PostgreSQL Cheat Sheet: Difference between revisions

From MK Wiki EN
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

psql manual page

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