How to show tables in PostgreSQL? How to exit Postgres psql command line utility? How to describe a table in PostreSQL? Find all the answers in our PostreSQL cheat sheet
We gathered a list of handy PostgreSQL commands and queries when working with PostgreSQL databases. Please ping us @ForestAdmin if you’d like to add something to the cheat sheet!
Getting started with PostgreSQL
Login and enter PostgreSQL command line utility psql
$ sudo su - postgres psql
$ sudo su - postgres psql
$ sudo su - postgres psql
List postgres databases
\l
\l
\l
Connect to postgres database
\c databaseName
\c databaseName
\c databaseName
Exit postgreSQL command line utility psql
\q
\q
\q
Managing PostgreSQL
Check PostgreSQL version
SELECT version();
SELECT version();
SELECT version();
Check if PostgreSQL is installed
$ which psql
$ which psql
$ which psql
Check if PostgreSQL is running
$ pgrep -fa -- -D | grep postgres
$ pgrep -fa -- -D | grep postgres
$ pgrep -fa -- -D | grep postgres
Restart PostgreSQL on Linux
# systemctl restart postgresql// or # service postgresql restart // or # /etc/init.d/postgresql restart // or # /sbin/service postgresql restart
# systemctl restart postgresql// or # service postgresql restart // or # /etc/init.d/postgresql restart // or # /sbin/service postgresql restart
# systemctl restart postgresql// or # service postgresql restart // or # /etc/init.d/postgresql restart // or # /sbin/service postgresql restart