[PostgreSQL] PSQL basic command

1. Login to PostgreSQL

psql -h abc.com -U userA -d databaseA 

2. List databases

Most Postgres servers have three databases defined by default: template0, template1 and postgres. template0 and template1 are skeleton databases that are or can be used by the CREATE DATABASE command. postgres is the default database you will connect to before you have created any other databases.

\l
\list
\c databaseName ##switch database

3. List tables

\dt

4. Check DB/Table size

SELECT pg_size_pretty( pg_database_size('dbname') );
SELECT pg_size_pretty( pg_total_relation_size('tablename') );