How to Install and Troubleshoot the ODBC Driver for PostgreSQL

Bilal Shahid Feb 02, 2024
  1. What Is an ODBC Driver
  2. How to Install an ODBC Driver
  3. Set Up the ODBC Driver for PostgreSQL
  4. Common Problems When Using ODBC Driver
How to Install and Troubleshoot the ODBC Driver for PostgreSQL

ODBC drivers can be quite helpful if you’re looking for something that could help you gain an additional connection that will provide incredibly high performance for your DBMS. However, if you’re having a little trouble with it, you’re in the right place to find all your answers.

What Is an ODBC Driver

A Microsoft Open Database Connectivity, or ODBC driver, is a system that will allow external applications to access data from database management systems such as PostgreSQL. With its help, you can import, export, or edit your data using third-party software, even if they aren’t designed to be linked with PostgreSQL.

You can move your data as you please, and the application won’t have to be bound to the database they’re running on.

An additional benefit of an ODBC driver is that you can easily create a database application that has access to any database as long as the end-user has an ODBC driver. Overall, an ODBC driver will provide a consistent interface for any database server with multiple concurrent connections.

How to Install an ODBC Driver

We’ve got you covered if you’re ready to install an ODBC driver. Ideally, you should opt for psqlODBC, the official ODBC driver for PostgreSQL.

You can use any one of the three methods to install psqlODBC on your Windows system.

Install psqlODBC in PowerShell Using MSBuild Files

This method is often the most recommended since it is often the most reliable and simple to get done.

  1. Open command prompt or PowerShell console on your system and install the driver using C:\psqlodbc\winbuild\> (Powershell) ./BuildAll.ps1 <options> or C:\psqlodbc\> (Command Prompt) .\BuildAll.bat <options>.

  2. Now, you will have to set the execution policy of PowerShell to RemoteSigned or Unrestricted, depending on your need. Type in Get-ExecutionPolicy.

    If it is currently set as "Restricted" or "AllSigned", change it using Set-ExecutionPolicy RemoteSigned where you can swap "RemoteSigned" with "Unrestricted", depending on your need.

  3. Next, install Visual Studio 2015 Non-Express Edition or Express 2015. You can always opt for the 2013 or 2012 versions.

    An alternative is Full Microsoft Visual C++ 2010 or Windows SDK 7.1. If you like, you can always install multiple and use whatever works best for you.

    Ensure to include x64 and x84 development tools while installing.

  4. Type in .\editConfiguration(.ps1) to set up the build environment. You can edit this as you like or leave them at their defaults.

  5. Next, invoke build operations using .\BuildAll(.ps1) or .\BuildAll(.ps1) -V(CVersion) 10.0 if you compiled under the VC10 environment.

  6. If you like, you can also put in a regression test using .\regress(.ps1) or .\regress(.ps1) -(platform) x64.

  7. Finally, install the .msi installer file using C:\psqlodbc\> (Command Prompt) .\buildInstallers.bat <options> or C:\psqlodbc\installer\> (Powershell) ./buildInstallers.ps1 <options>.

You may also build it with the command line using nmake makefiles or Visual Studio IDE. For nmake makefiles, use NMAKE.exe to build the driver, then install the .msi installer file.

Set Up the ODBC Driver for PostgreSQL

Setting up your ODBC driver for PostgreSQL is often easier than the installation process, but it’s best to walk through it once to simplify it.

First, configure ODBC using the ODBC Data Source Administrator (DNS is ideal). Then, connect an object to your database and create a new channel or use an existing one.

Ensure the source is from the translator and the destination is the channel.

If you want to set up a new ODBC data source for PostgreSQL, you can do so easily once all of the latest PostgreSQL ODBC drivers have been installed. After installation, open the ODBC Administrator and select "Run as Administrator".

In the System DSN tab, click on "Add", select the ODBC driver that you installed and click "Finish". Lastly, enter the credentials for ODBC.

The data source and description can be anything you prefer, but it is best to leave the port at default, 5432. As for the server field, it should be the same as the network name of your PostgreSQL server.

Once you’ve entered the username and password, click on "Test" to make sure everything is working fine, then save.

Common Problems When Using ODBC Driver

Sometimes, you might have made an error because your ODBC driver isn’t working the way it should. Here are some issues you might encounter and possible methods to solve them.

PostgreSQL Isn’t Listed as a Server

If you don’t see the option of PostgreSQL when you’re adding a user DSN, you’re likely missing the 64-bit version of the ODBC driver. This doesn’t come with the PostgreSQL installer, so installing it can solve the problem.

Configuring DSNs

People attempt to configure it on the ordinary control panel or ODBC data source administrator. However, this won’t always work.

You might have to configure the ODBC DSN by going to Run and then entering "%SystemRoot%\syswow64\odbcad32.exe" for a 32-bit system. After this, go to ODBC and select PostgreSQL Unicode under the System DSN tab.

the 32-bit Version Isn’t Working

The ODBC driver is installed based on the version of your software client, not your OS. This means that if your OS is 64-bit, but your software is 32-bit, the 64-bit version of the ODBC driver won’t work and vice versa.

the Data Source Connection Fails

This might occur because of an error in the server name or port number. The server should always be the network name of your PostgreSQL server.

As for the port number, it is best to leave it as the default if you’re not sure you should opt for an alternative. The default port number is 5432.

ODBC drivers for PostgreSQL can be great if you know how to use them. We hope this article has walked you through everything you need to start.

Author: Bilal Shahid
Bilal Shahid avatar Bilal Shahid avatar

Hello, I am Bilal, a research enthusiast who tends to break and make code from scratch. I dwell deep into the latest issues faced by the developer community and provide answers and different solutions. Apart from that, I am just another normal developer with a laptop, a mug of coffee, some biscuits and a thick spectacle!

GitHub