How to Install psql on Mac, Ubuntu, Debian, Windows


Before You Start

Before you start, you should confirm that you don’t already have psql installed. In fact, if you’ve ever installed Postgres or TimescaleDB before, you likely already have psql installed.

psql --version

Install on MacOS Using Homebrew

First, install the Brew Package Manager.

Second, update brew. From your command line, run the following commands:

brew doctor
brew update
brew install libpq

Finally, symlink psql (and other libpq tools) into /usr/local/bin:

brew link --force libpq
Editor's Note: For information about how to connect psql to your Timescale database, please refer to Timescale documentation on connecting to your database with psql.

Install on Ubuntu 16.04,18.04 and Debian 9,10

Install on Ubuntu and Debian using the apt package manager:

sudo apt-get update
sudo apt-get install postgresql-client

Note: This only installs the psql client and not the PostgreSQL database.

Install Windows 10

We recommend using the installer from PostgreSQL.org.

Last Step: Connect to Your PostgreSQL Server

Let’s confirm that psql is installed:

psql --version

Now, in order to connect to your PostgreSQL server, we’ll need the following connection params:

  • Hostname
  • Port
  • Username
  • Password
  • Database name

There are two ways to use these params.

Option 1:

psql -h [HOSTNAME] -p [PORT] -U [USERNAME] -W -d [DATABASENAME]

Once you run that command, the prompt will ask you for your password. (Which we specified with the -W flag.)

Option 2:

psql postgres://[USERNAME]:[PASSWORD]@[HOSTNAME]:[PORT]/[DATABASENAME]?sslmode=require

And this is how they look in the Timescale UI:

Congrats! Now you have connected via psql.

If you haven’t yet, you can head over to our documentation page and find out more about TimescaleDB, our open-source extension that makes PostgreSQL scalable.

Ingest and query in milliseconds, even at terabyte scale.
This post was written by
1 min read
Tutorials & How-tos
Contributors

Related posts