17 Practical psql Commands You Don’t Want to Miss
Summary: In this tutorial, you will learn how to use practical psql commands to interact with the PostgreSQL database server effectively.
1) Connect to PostgreSQL database
The following command connects to a database under a specific user. After pressing Enter
PostgreSQL will ask for the password of the user.
psql -d database -U user -W
For example, to connect to dvdrental
database under postgres
user, you use the following command:
psql -d dvdrental -U postgres -W
Password for user postgres:
dvdrental=#
If you want to connect to a database that resides on another host, you add the -h option as follows:
psql -h host -d database -U user -W
In case you want to use SSL mode for the connection, just specify it as shown in the following command:
psql -U user -h host "dbname=db sslmode=require"