Connecting Excel to PostgreSQL With ODBC Step by Step
Install the psqlODBC driver, create a data source, connect Excel to PostgreSQL with a read only role, run a query and fix the usual bitness and SSL problems.

Excel can read a PostgreSQL database directly, which turns a monthly export into a refresh. The route that works on every Windows machine is ODBC: a standard driver interface that Excel's Power Query uses to talk to databases. Setting it up takes ten minutes when you know the order, and an afternoon when you do not, because the failures are not helpful. This post goes through the order: driver, data source, connection, query and checks. It is a spoke of connecting Excel directly to a database.
What you need before starting
Four facts about the server and one about your computer.
Host name or address of the PostgreSQL server, and the port (5432 by default).
Database name.
A login role and its password, ideally a read-only role created for reports (giving Excel users a read only database account).
Network access. The server must accept connections from your address. A firewall, a VPN or
pg_hba.confon the server may block you, and no setting in Excel can fix that.Excel's bitness. In Excel choose File, Account, About Excel. It says 32-bit or 64-bit. The ODBC driver you install must match.
Step 1: install the driver
PostgreSQL's ODBC driver is called psqlODBC and is distributed by the PostgreSQL project. Download the Windows installer from the project's download area, choosing the 64-bit build for 64-bit Excel (the installer's file name carries x64). Install it with the defaults. Some organizations distribute it through software management, in which case check that the version matches the server's major version support and ask IT for the right package.
If you use 32-bit Excel, install the 32-bit driver. Installing both is allowed; they live side by side.
Step 2: create a data source
Open the ODBC Data Source Administrator. Windows includes two: one for 64-bit drivers and one for 32-bit. Search for "ODBC Data Sources (64-bit)" for 64-bit Excel. For 32-bit Excel run C:\Windows\SysWOW64\odbcad32.exe. Using the wrong one is the most common reason a data source "does not appear" in Excel.
Choose a tab:
User DSN is visible only to your Windows account.
System DSN is visible to all users of the machine, and is the usual choice for shared computers and scheduled tasks.
Click Add and pick PostgreSQL Unicode(x64) (the Unicode driver, not ANSI, for text with accents). Fill in:
| Field | Value |
|---|---|
| Data Source | A short name, such as shop_reporting |
| Database | The database name |
| SSL Mode | require for a server across a network, verify-full if you have the certificate |
| Server | Host name or address |
| Port | 5432 |
| User Name | The read-only role |
| Password | Leave empty if you will type it in Excel |
Click Test. A success message means the driver, network and login work. Saving the password in the data source writes it to the registry for that profile, in a form that is readable by anyone with access to your account. Prefer to be asked each time, or use a secrets approach described in keeping database credentials out of shared workbooks.
The same configuration can be written as a connection string without a DSN:
Driver={PostgreSQL Unicode(x64)};Server=db.example.test;Port=5432;Database=shop;Uid=report_reader;SslMode=require;A DSN keeps the details in one place on the machine. A connection string travels with the workbook and works on any machine with the same driver, and it must not hold a password.
Step 3: connect from Excel
In Excel choose Data, Get Data, From Other Sources, From ODBC. A dialog asks for a data source name. Choose shop_reporting from the list. If the list is empty, the data source was created in the wrong administrator (bitness), as above.
Open Advanced options to paste a SQL statement, as in building a pivot table from a database query. Without it, Excel lists the tables, and loading one loads all its rows. A statement such as:
SELECT o.order_date, c.region, p.category,
l.quantity * l.unit_price AS revenue
FROM orders o
JOIN customers c ON c.id = o.customer_id
JOIN order_lines l ON l.order_id = o.id
JOIN products p ON p.id = l.product_id
WHERE o.order_date >= DATE '2025-01-01';returns the shape a pivot needs. Click OK. When Excel asks for credentials, choose the Database tab and enter the role name and password. Excel stores the credential for the data source in your profile, not in the workbook. Click Connect, review the preview, and either Load or Transform Data to continue in the Power Query editor.
You can also use the PostgreSQL connector (Get Data, From Database, From PostgreSQL Database), which in some versions needs a separate .NET provider, Npgsql, installed on the machine. Where it works it is quicker to set up and shows tables with their schemas. ODBC is the fallback that needs no extra provider and is the route that works in most locked-down environments.
Step 4: choose how to load
After the preview, Load To offers a table, only a connection, or the Data Model. Large results go to the Data Model or stay as connections feeding a pivot. A table of a hundred thousand rows in a sheet makes the workbook slow and large. Set the properties of the query: refresh on open, no background refresh for scripted use, and a name that says what it holds (refreshing database data in Excel on open).
Step 5: check what came back
Compare the loaded result with the database. Count rows and total a column in both places:
SELECT COUNT(*) AS rows, SUM(l.quantity * l.unit_price) AS revenue
FROM orders o JOIN order_lines l ON l.order_id = o.id
WHERE o.order_date >= DATE '2025-01-01';In Excel, compare with the row count of the table and the sum of the revenue column. Check types: dates should be dates, numbers numbers, and text columns not truncated. If a date arrives as text, the ODBC driver may be returning it as a string; cast it in SQL (o.order_date::date) or set the type in Power Query with a locale.
Common problems
"Data source name not found and no default driver specified." The data source is not visible to this Excel. Check the bitness of the administrator, the DSN type (user or system) and the spelling of the name.
"Driver not found" or no PostgreSQL entry in the driver list. The driver is not installed, or only the other bitness is. Install the matching one (fixing ODBC driver not found errors in Excel).
"Connection refused" or a timeout. The server is not reachable: a firewall, a wrong port, a VPN not connected, or listen_addresses on the server set to localhost only.
"No pg_hba.conf entry for host". The server rejects your address, user, database or SSL setting. The server administrator must add a rule. The message names the address and role it saw.
"password authentication failed". A wrong password, a role without LOGIN, or a server that expects a different method (SCRAM versus MD5). Update to a recent psqlODBC if the server uses SCRAM and the driver is old.
SSL errors. SslMode=require demands encryption; verify-full also checks the certificate against a root certificate that must be present. A server that does not support SSL rejects require.
Garbled accents. Use the Unicode driver, and make sure the database encoding is UTF-8.
Slow refresh. See slow Excel refresh from a database.
Keep it secure
The workbook now has a live path to production data. Use a role with SELECT on the specific views, not on all tables. Set a statement timeout on the role so a runaway query cannot hold the server (ALTER ROLE report_reader SET statement_timeout = '60s';) and limit its connections. Require SSL across networks. Do not email the workbook outside the organization: the data it cached travels with it, and so does the connection information.
When ODBC is not the right way to reach PostgreSQL
The built-in connector works. If Get Data, From PostgreSQL Database works in your version, it saves the driver setup.
The audience is large or external. Give them a published report, not a database login each.
The data is big. A refresh that pulls millions of rows should be a summary view or a scheduled export (making a pivot table from data larger than Excel allows).
The job is unattended. A scripted job on a server should use a database client library, not Excel.
See the psqlODBC project page and Microsoft's page on connecting to an ODBC data source with Power Query. To convert a small result to JSON, use the CSV to JSON converter.


