How to Install the Client Tools for PostgreSQL on Windows

David Mbochi Njonge Feb 02, 2024
  1. Download the Complete PostgreSQL Binaries to Install the PostgreSQL Client Tools
  2. Use PostgreSQL Installer to Install the PostgreSQL Client Tools
How to Install the Client Tools for PostgreSQL on Windows

When we develop applications, we end up hosting them to the desired cloud provider based on a specific monthly or yearly subscription. Depending on your plan, these subscriptions give us different services such as data stored on a database, bandwidth, email services, and others.

There are different ways to access the remote database from your local computer, and one of them is through the graphical user interface client or the command line interface over TCP.

This tutorial will teach us how to install only the PostgreSQL client tools that we need to access the remote database on a Windows machine.

Download the Complete PostgreSQL Binaries to Install the PostgreSQL Client Tools

This is the first approach that we can use to install the PostgreSQL client tools.

We must first install Microsoft Visual C++ Redistributable for this approach to work.

microsoft Visual C++ Redistributable installation

Download the zip archive of the complete PostgreSQL binaries for the Windows operating system.

download PostgreSQL binaries

Note that these binary files are provided for convenience to expert users, and a user should use an installer unless they need these files.

Go to your Downloads folder where the PostgreSQL binary is saved and unzip the archive.

A folder named pgsql is extracted from the archive, and it has the folders shown in the following image.

PostgreSQL pgsql folders

Delete the selected folders as indicated in the above image as they are not required to access your remote database.

The remaining folder is the bin folder required in this approach. Go into the bin folder and copy the path of its location, as shown below.

PostgreSQL bin location

The next step is to add this path to the System Environment Variables so that we can execute the PostgreSQL commands.

Click the Windows logo key, search for Environment, and click the Enter key when the Edit the system environment variables option is returned.

This will return the System properties window, as shown below.

system properties window

Click on the Environment variables window, which opens another window for User variables and System variables. Select the Path option and click the Edit button.

environment variables window

On the new window that opens, press the new button and paste the location of the PostgreSQL bin folder that we copied in the empty field, as shown below.

PostgreSQL system variable

The final step is to verify whether we can execute PostgreSQL commands from our terminal. In this example, we will not connect to any remote database, but if you have one, use the following command to access your database.

>psql -h <host> -d <database> -U <username> -p <port> -W

Open the Windows command prompt to verify that our configuration is working, type psql, and press Enter on your keyboard. As shown below, the command attempts to connect to a local PostgreSQL server, but it does not work since we have not installed any PostgreSQL server.

PostgreSQL connection test

Use PostgreSQL Installer to Install the PostgreSQL Client Tools

Download the PostgreSQL installer for Windows and run the software.

The software has several products that can be installed, as shown below, but since we are only interested in the command line tools, deselect all the others and click Next.

PostgreSQL installer

Once the installation is complete, copy the bin folder location installed under Program Files > PostgreSQL > 14, as shown below.

bin installer location

The next step is installing and adding the location to the System variables. The steps we covered above are similar to this approach; hence there is no need to repeat them.

Ensure you delete the previous PostgreSQL environment variable that we added. After adding the new environment variable under the location Program Files > PostgreSQL > 14 > bin, open the Windows command prompt and test the configuration again using the psql command.

The command attempts to connect to a local PostgreSQL server but is unsuccessful because we have not installed any database server as we saw in the previous approach.

connection test two

David Mbochi Njonge avatar David Mbochi Njonge avatar

David is a back end developer with a major in computer science. He loves to solve problems using technology, learning new things, and making new friends. David is currently a technical writer who enjoys making hard concepts easier for other developers to understand and his work has been published on multiple sites.

LinkedIn GitHub

Related Article - PostgreSQL Windows