Mar 18, 2024
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 Timescale dashboard, this is how they look in the Timescale 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 Timescale in AWS, create a free account on our platform today. It only takes a couple of seconds, no credit card required!
Hi, we’re Timescale! We build a faster PostgreSQL for demanding workloads like time series, vector, events, and analytics data. Check us out.