Connect to a PostgreSQL database (Power Query)

  This article applies to Power Query, a data analysis feature available for Excel that lets you discover, combine and refine data. You may need to enable Power Query in Excel. You can also download and install the most recent version of Power Query for Excel, which automatically enables it. Power Query technology is also built into the Power BI Designer, which is a stand-alone report authoring and data transformation tool for Power BI.

Before you can connect to a PostgreSQL database in Power Query, you need the Ngpsql data provider for PostgreSQL installed on your computer. Select the driver that matches your Power Query installation (32-bit or 64-bit). Also make sure you have the provider registered in the machine configuration that matches the most recent .NET version on your device.

Connect to a PostgreSQL database

Note   Before you can connect to a PostgreSQL database in Power Query, you need the Ngpsql data provider for PostgreSQL installed on your computer. Select the driver that matches your Power Query installation (32-bit or 64-bit). Also make sure you have the provider registered in the machine configuration that matches the most recent .NET version on your device.

  1. In the POWER QUERY ribbon tab, select From Database > From PostgreSQL Database.

    Get External Data from a Database
  2. In the PostgreSQL Database dialog box, in Server Name specify the PostgreSQL Database Server to which you want to connect.

  3. If you want to import data using native database query, specify your query in the SQL Statement box. For more information, see Import Data from Database using Native Database Query.

  4. Select OK.

  5. If the PostgreSQL server requires database user credentials:

    1. In the Access a Database dialog box, enter your username and password.

    2. Select Save.

Top of Page

Install the PostgreSQL .Net Data Provider

  1. Download and unzip the most recent Ngpsql data provider for PostgreSQL.

  2. Use GACUtil.exe to add Npgsql.dll and Mono.Security.dll to the global cache.

Syntax

"{GACUtil Path}\GACUtil" /i "{Provider DLL Path}\Npgsql.dll""{GACUtil Path}\GACUtil" /i "{Provider DLL Path}\Mono.Security.dll"

Where
GACUtil Path

  • For x86

    • C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\

  • For x64

    • C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64

Provider DLL Path

  • Path to Npgsql.dll and Mono.Security.dll

  • Add a new entry to the machine.config file:

    1. Navigate to C:\Windows\Microsoft.NET\Framework\v4.0.30319\CONFIG (or C:\Windows\Microsoft.NET\Framework64\v4.0.30319\CONFIG if running 64 bit). The bold portions in the sample paths reflect the version of .NET installed on the device; make sure your path appropriately matches your .NET installation. For .NET 3.5, use the v2.0.50727 directory; for .NET 4.0 and later use the v4.0.30319 directory.

    2. Open the machine.config file with administrator privileges.

    3. Look for a node called DbProviderFactories.

    4. Add a new entry, ensuring the new entry is between the <DbProviderFactories> and </DbProviderFactories> tags:

        The Ngpsql data provider version in the following code must match the version that is installed on the device. For example, the code sample below reflects Ngpsql data provider version 2.0.12.0; if your version is more recent, change the following line accordingly before adding it to the machine.config file. You can view the Ngpsql data provider's file properties in Windows Explorer to determine its version.

      <add description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" name="Npgsql Data Provider" invariant="Npgsql" support="FF"/>
  • Save the Machine.config file.

Top of Page

Related Topics

Import data from external data sources

Applies To: Excel 2010, Excel 2013



Was this information helpful?

Yes No

How can we improve it?

255 characters remaining

To protect your privacy, please do not include contact information in your feedback. Review our privacy policy.

Thank you for your feedback!

Support resources

Change language