Edit

Share via


PostgreSQL

Summary

Item Description
Release State General Availability
Products Excel
Power BI (Semantic models)
Power BI (Dataflows)
Fabric (Dataflow Gen2)
Power Apps (Dataflows)
Dynamics 365 Customer Insights
Analysis Services
Authentication Types Supported Database (Username/Password)
Function Reference Documentation PostgreSQL.Database

Note

Some capabilities may be present in one product but not others due to deployment schedules and host-specific capabilities.

Prerequisites

Power BI Desktop has included the Npgsql provider for PostgreSQL connector since December 2019, eliminating the need for additional installation. Starting with the October 2024 version, it incorporates Npgsql version 4.0.17. Separate Npgsql GAC installation will override this default version.

The PostgreSQL connector is supported for cloud connection and via VNet data gateway or on-premises data gateway. Since the June 2025 release, the on-premises data gateway includes the Npgsql provider, so no extra installation is needed. Separate Npgsql GAC installation will override this default version.

For Power BI Desktop versions released before December 2019 and on-premises data gateway released before June 2025, you must install the Npgsql provider on your local machine to use the PostgreSQL connector. To install the Npgsql provider, go to the releases page for version 4.0.17, download and run the .msi file. The provider architecture (32-bit or 64-bit) needs to match the architecture of the product where you intend to use the connector. When installing, make sure that you select Npgsql GAC Installation to ensure Npgsql itself is added to your machine. Npgsql 4.1 and up are not supported due to .NET version incompatibilities.

Screenshot of the Npgsql installer with GAC Installation selected.

Capabilities Supported

  • Import
  • DirectQuery (Power BI semantic models)
  • Advanced options
    • Command timeout in minutes
    • Native SQL statement
    • Relationship columns
    • Navigate using full hierarchy

Connect to a PostgreSQL database from Power Query Desktop

Once the matching Npgsql provider is installed, you can connect to a PostgreSQL database. To make the connection, take the following steps:

  1. Select the PostgreSQL database option in the connector selection. For more information, go to Where to get data.

  2. In the PostgreSQL database dialog that appears, provide the name of the server and database.

    Screenshot of the PostgreSQL connection builder in Power BI.

  3. Select either the Import or DirectQuery data connectivity mode.

  4. If you're connecting to this database for the first time, input your PostgreSQL credentials in the User name and Password boxes of the Database authentication type. Select the level to apply the authentication settings to. Then select Connect.

    Screenshot of the authentication dialog where you enter your PostgreSQL user name and password.

    For more information about using authentication methods, go to Authentication with a data source.

  5. If the connection isn't encrypted, you're prompted with the following message.

    Screenshot of the Azure SQL database encryption support dialog.

    Select OK to connect to the database by using an unencrypted connection, or follow the instructions in Enable encrypted connections to the Database Engine to set up encrypted connections to PostgreSQL database.

  6. In Navigator, select the database information you want, then either select Load to load the data or Transform Data to continue transforming the data in Power Query editor.

    Screenshot of the Power Query Desktop Navigator showing the Human Resources employee data in PostgreSQL database.

Connect to a PostgreSQL database from Power Query Online

To make the connection, take the following steps:

  1. Select the PostgreSQL database option in the connector selection. For more information, go to Where to get data.

  2. In the PostgreSQL database dialog that appears, provide the name of the server and database.

    PostgreSQL connection builder in Power Query Online.

  3. Select the name of the on-premises data gateway you want to use.

  4. Select the Basic authentication kind and input your PostgreSQL credentials in the Username and Password boxes.

  5. If your connection isn't encrypted, clear Use Encrypted Connection.

  6. Select Next to connect to the database.

  7. In Navigator, select the data you require, then select Transform data to transform the data in Power Query editor.

Connect using advanced options

Power Query Desktop provides a set of advanced options that you can add to your query if needed.

Screenshot of the advanced options included in the PostgreSQL connection dialog box.

The following table lists all of the advanced options you can set in Power Query Desktop.

Advanced option Description
Command timeout in minutes If your connection lasts longer than 10 minutes (the default time-out), you can enter another value in minutes to keep the connection open longer. This option is only available in Power Query Desktop.
SQL statement For information, go to Import data from a database using native database query.
Include relationship columns If checked, includes columns that might have relationships to other tables. If this box is cleared, those columns aren't displayed.
Navigate using full hierarchy If checked, the navigator displays the complete hierarchy of tables in the database you're connecting to. If cleared, the navigator displays only the tables whose columns and rows contain data.

Once you select the advanced options you require, select OK in Power Query Desktop to connect to your PostgreSQL database.

Native query folding

By default, native query folding is enabled. Operations that are capable of folding are applied on top of your native query according to normal Import or Direct Query logic. Native Query folding isn't applicable with optional parameters present in Value.NativeQuery.

In the rare case that folding doesn't work with native query folding enabled, you can disable it. To disable native query folding, set the EnableFolding flag to false for Value.NativeQuery in the advanced editor.

Sample: Value.NativeQuery(target as any, query, null, [EnableFolding=false])

Troubleshooting

Your native query might throw the following error:

We cannot fold on top of this native query. Please modify the native query or remove the 'EnableFolding' option.

A basic troubleshooting step is to check if the query in Value.NativeQuery throws the same error with a limit 1 clause around it:

select * from (query) _ limit 1