PostgreSQL connect to database using psql

Written by Yujin Boby

Edit in WordPress

To connect to the PostgreSQL database server using psql command line, run

su - postgres
psql

If you have a PostgreSQL user and password, you can use

psql -h SERVER_IP_HERE -p 5432 -U USER_NAME_HERE -W

Example

psql -h students.arrhwfpckmeo.ap-southeast-2.rds.amazonaws.com -p 5432 -U aite_students -W

-W option is to force asking password.

See PostgreSQL