Use Power BI’s native PostgreSQL connector (or ODBC) to pull data, run SQL, and refresh reports.
The built-in connector ships with Power BI Desktop. It handles SSL, imports metadata, and supports DirectQuery or Import modes without extra drivers from v13 onward.
Enable TCP port 5432 on your firewall, install the latest Npgsql driver (if Desktop prompts for it), and create a read-only "powerbi_reader" role in your database.
Format: postgresql://user:password@host:port/database
.Example: postgresql://powerbi_reader:s3cret@db.company.com:5432/ecommerce
.
Home → Get Data → Database → PostgreSQL. Enter server (db.company.com:5432
) and database (ecommerce
). Select Import (for caching) or DirectQuery (for live queries). Click OK.
Yes. In the connector dialog, expand Advanced Options and paste your SQL, e.g., SELECT id, name, price FROM Products WHERE stock < 10
.Power BI will treat it as a single table.
Install an On-Premises Data Gateway on a machine that can reach PostgreSQL.In the Service, add a new data source, enter the same credentials, and enable scheduled refresh.
Create a limited role:
CREATE ROLE powerbi_reader LOGIN PASSWORD 's3cret';
GRANT CONNECT ON DATABASE ecommerce TO powerbi_reader;
GRANT USAGE ON SCHEMA public TO powerbi_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO powerbi_reader;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO powerbi_reader;
Use views to pre-aggregate, enable indices on join keys, and prefer Import mode for heavy dashboards.For DirectQuery, keep visuals under eight queries to avoid timeouts.
1) Verify SSL = require vs disable in postgresql.conf
. 2) Check pg_hba.conf
allows the gateway’s IP. 3) Ensure Npgsql driver ≥ 5.0 is installed if using older Desktop builds.
.
Power BI Desktop 2022 and later bundle Npgsql. Older versions prompt you to download it once. The Service requires only the data gateway.
Yes. Define Power Query parameters (Home → Manage Parameters) and reference them in your SQL using string concatenation before loading the data.
Microsoft recommends SSL. Set sslmode=require
in the connection string or enable “Encrypt connection” in the connector dialog.