PostgreSQL Tips: Installing the PostgreSQL Client

In the realm of cloud computing, the necessity of installing the entire PostgreSQL suite on local machines often raises questions, especially when leveraging managed services like the IBM Cloud® Database for PostgreSQL. Many installation guides assume that users require a full database setup, which may not be the case for those already utilizing cloud solutions.

This guide focuses on the streamlined process of installing only the psql client on various operating systems—Windows, Linux, and macOS—enabling users to connect effortlessly to their IBM Cloud Databases (ICD) for PostgreSQL service.

macOS with Homebrew

For macOS users, Homebrew serves as an excellent package manager. With Homebrew installed, users can easily access a plethora of applications, typically found in /usr/local/bin. The PostgreSQL client tools can be installed via the libpq package. The installation command is straightforward:

brew install libpq

However, there is a minor caveat: the libpq package does not automatically link to the /usr/local/bin directory. To establish this connection, execute the following command:

brew link --force libpq

With this step completed, users are ready to launch psql and begin connecting to their databases.

Ubuntu 16.04 and 18.04

Linux distributions, particularly Ubuntu and other Debian-based systems, come equipped with a built-in package manager, apt. To install the PostgreSQL client, simply run:

sudo apt-get install postgresql-client

This command installs the PostgreSQL 10 client, which is compatible with earlier versions, ensuring seamless connectivity.

Red Hat Enterprise Linux 7 (and others)

For users operating on Red Hat Enterprise Linux (RHEL), the installation process involves a few additional steps compared to Ubuntu. The package manager for RHEL is yum. First, direct yum to the PostgreSQL repository with the following command:

sudo yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm

Once configured, you can install the PostgreSQL client packages by executing:

sudo yum install postgresql10

For those seeking the repository URL, the Linux Downloads (Red Hat Family) page provides a user-friendly form to select the desired PostgreSQL version, platform, and architecture, along with tailored instructions for various Red Hat variants, including CentOS and Fedora.

Fedora 27 and 28

Fedora users benefit from readily available PostgreSQL client packages in the default repositories. To install the PostgreSQL client on Fedora 27, 28, or later, simply execute:

sudo dnf install postgresql.x86_64

This command completes the installation process with minimal effort.

Windows 10

Windows 10 users face a slightly more intricate setup. The recommended approach is to utilize the PostgreSQL installer from Enterprise DB. This comprehensive installation package allows users to opt for the command line tools, such as psql, without installing the full server. After downloading the executable, run it and select only the Command Line Tools option during installation.

Post-installation, it’s essential to configure the Windows environment variables to enable psql access from the command prompt. Navigate to Control Panel > System and Security > System, then select Advanced system settings. In the System Properties window, click on Environment Variables. In the top section labeled User variables for…, locate the PATH entry and click Edit. Add a new entry for the psql client path, typically:

C:Program FilesPostgreSQL10bin

After confirming the changes, open a new Command Prompt window to verify that psql is functioning correctly. A successful launch will confirm that the setup is complete, even in the absence of a local server.

With these steps, users can efficiently set up the psql client for PostgreSQL, facilitating connections to IBM Cloud Databases without the need for a full PostgreSQL installation on their local machines. Future PostgreSQL Tips will delve into the basic features and functions of the database using the newly installed psql client.

Tech Optimizer
PostgreSQL Tips: Installing the PostgreSQL Client