PostgreSQL Cheat Sheet

From MK Wiki EN
Jump to navigation Jump to search

Open SQL Shell

As user "postgres"

sudo -u postgres psql

As arbitrary user using TCP/IP

psql -h host -d database -U username --password

Even on localhost it's necessary to specify "-h localhost", otherwise an error will appear unless the server isn't configured to allow this kind of connections:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "user"

Important Commands

Caption text
Command Description
\l List databases
\c Connect to database
\dt Display tables
\dv Display views
\df Display functions