Category: All posts
Jun 11, 2025
Posted by
Ajay Kulkarni
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, 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:
psql --version
If you haven’t installed psql, here is how to install it on a variety of operating systems.
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.
brew doctor
brew update
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.
/usr/local/bin
:brew link --force libpq
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.
We recommend using the installer from PostgreSQL.org.
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:
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
If you are using the TigerData dashboard, this is how they look in the TigerData UI:
Congrats! Now you have connected via psql.
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 TimescaleDB in AWS, create a free account on our platform today. It only takes a couple of seconds, no credit card required!
Q: How do I check if psql is already installed on my system? A: You can verify if psql
is already installed by opening your command line program and typing psql --version
. If you've previously installed PostgreSQL or TimescaleDB, you likely already have psql
installed, as it comes bundled with these installations.
Q: How do I install psql on macOS? A: To install psql on macOS, first install the Brew Package Manager, then run brew doctor
, brew update
, and brew install libpq
commands in sequence. Finally, symlink psql into /usr/local/bin
by running brew link --force libpq
to make the psql
command available system-wide.
Q: How do I install psql on Ubuntu or Debian? A: Installing psql on Ubuntu or Debian is straightforward using the apt package manager. Simply run sudo apt update
followed by sudo apt install postgresql-client
in your terminal. This installs only the psql client without the full PostgreSQL database server.
Q: What's the recommended way to install psql on Windows 10? A: For Windows 10, the recommended approach is to use the official installer from PostgreSQL.org. This installer provides a wizard-based setup that guides you through the installation process and includes psql along with other PostgreSQL tools.
Q: How do I connect to a PostgreSQL server using psql? A: To connect to a PostgreSQL server, you can use either the command format psql -h [HOSTNAME] -p [PORT] -U [USERNAME] -W -d [DATABASENAME]
a (which will prompt for password) or the connection string format psql postgres://[USERNAME]:[PASSWORD]@[HOSTNAME]:[PORT]/[DATABASENAME]?sslmode=require
. Both methods require your server's hostname, port, username, password, and database name.
Hi, we’re Timescale! We build a faster PostgreSQL for demanding workloads like time series, vector, events, and analytics data. Check us out.