PostgreSQL Cheat Sheet: Difference between revisions
Jump to navigation
Jump to search
m (Added category) |
(Added man page of psql) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[https://linux.die.net/man/1/psql psql manual page] | |||
== Open SQL Shell == | == Open SQL Shell == | ||
=== As user "postgres" === | |||
sudo -u postgres psql | 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 == | == Important Commands == |
Latest revision as of 10:12, 30 May 2025
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
Command | Description |
---|---|
\l | List databases |
\c | Connect to database |
\dt | Display tables |
\dv | Display views |
\df | Display functions |