How to Install psql on Mac, Ubuntu, Debian, Windows
psql is a terminal-based front-end to PostgreSQL. It provides an interactive command-line interface to the PostgreSQL (or TimescaleDB) database. With psql, you can type in queries interactively, issue them to PostgreSQL, and see the query results. It also provides several meta-commands and various shell-like features to facilitate writing scripts and automating a wide variety of tasks.
For instance, users can create, modify, and delete database objects such as tables, views, or users using psql. They can also execute SQL commands, manage data within the database, and even customize the psql environment.
Since psql is the standard command line interface for interacting with a PostgreSQL or TimescaleDB instance, this article will show you how to install it on a variety of operating systems.
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.
To verify it, open the command line program and type the following:
If you haven’t installed psql, here is how to install it on a variety of operating systems.
Install on MacOS Using Homebrew
- First, install the Brew Package Manager. Homebrew, often called "brew," is a free and open-source software package management system that simplifies software installation on Apple's macOS operating system and Linux.
Homebrew downloads, unpacks, and installs the software and its dependencies in your system. It also keeps track of what it has installed, allowing you to easily uninstall software or upgrade to newer versions when they become available.
- Second, update brew. From your command line, run the following commands:
brew install libpq
Next, you will have to symlink psql. Symlinking, or creating a symbolic link, is a process in Unix or Unix-like operating systems (like MacOS) that creates a link to a file or a directory that resides elsewhere in the system. Symbolic links are similar to shortcuts in Windows.
- The final step is to symlink psql (and other libpq tools) into
brew link --force libpq
Install on Ubuntu 23.10,22.04 and Debian 12
Install on Ubuntu and Debian using the
apt package manager:
sudo apt update
sudo apt 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:
Now, in order to connect to your PostgreSQL server, we’ll need the following connection params:
- Database name
There are two ways to use these params.
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
If you are using the Timescale dashboard, this is how they look in the Timescale UI:
Congrats! Now you have connected via psql.
Speed Up Your PostgreSQL Queries With TimescaleDB
Now that you've installed psql, you are ready to start easily interacting with your PostgreSQL—or TimescaleDB—database.
TimescaleDB is built on PostgreSQL and expands its capabilities for time series, analytics, and events. It will make your queries faster via automatic partitioning, query planner enhancements, improved materialized views, columnar compression, and much more. Plus, you can scale PostgreSQL for cheap with our multi-tiered storage backend.
If you're running your PostgreSQL database on your own hardware, you can simply add the TimescaleDB extension. If you prefer to try Timescale in AWS, create a free account on our platform today. It only takes a couple of seconds, no credit card required!