Skip to content



Psql is postgreSQL’s interactive terminal

Connecting to a database#

psql testdb


Anything you enter in psql that begins with an unquoted backslash (\) is a psql meta-command that is processed by psql itself

  • \d - Describe. List objects in the database.
  • \d <table> - describe a given (shows columns)
  • \c <db_name> - change to a different db
  • \l - list dbs
  • \q - quit

Find the Data Directory#

SHOW data_directory;

Find the Config File#

show config_file;

Manually installed postgres mac restart#

sudo -u postgres pg_ctl -D /Library/PostgreSQL/14/data stop
sudo -u postgres pg_ctl -D /Library/PostgreSQL/14/data start


Postgres’s startup file / startup config:


Sensible options:

-- Automatically format output based on result length and screen
\x auto

-- Prettier nulls
\pset null '#'

-- Save history based on database name
\set HISTFILE ~/.psql_history- :DBNAME

-- Turn on automatic query timing