Postgres Cheat Sheet
Sat, Oct 22, 2022
One-minute read
Commands
Query a Database
psql -U postgres -h <hostname> -p <port> -c '<query>' <database>
Get the Table Structure
psql -U postgres -h <hostname> -p <port> -c '\d <table>' <database>
Get the Database Schema
psql -U postgres -h <hostname> -p <port> -c '\dn' <database>
Troubleshooting
Verify if a Database is running
ps -ef | grep postgres
Verify if Postgres Service is running
sudo fun /tmp -name .s.PGSQL.5432
psql -h /tmp <database>