Skip to content

Instantly share code, notes, and snippets.

@wwgist
Created July 2, 2014 15:51
Show Gist options
  • Save wwgist/0c38675bc1a2aae7b131 to your computer and use it in GitHub Desktop.
Save wwgist/0c38675bc1a2aae7b131 to your computer and use it in GitHub Desktop.
PSQL: usage hints
# PostgreSQL hints
psql [option...] [dbname [username]]
-U > username (default=unix_user) VEVAR=PGUSER
-W > password
-w > no-password
-d > dbname VEVAR=PGDATABASE
-h > hostname (default=unix_socket/localhost) VEVAR=PGHOST
-p > port (default=default)
-c > command
-html > html output
-o > file-to-output
# from command line:
connectdb: psql dbname
clquery: psql -U username -d mydatabase -c 'SELECT * FROM mytable'
clcreatedb: createdb 'database name'
cldropdb: dropdb 'database name'
cldblist: psql --list
# from psql console (meta-commands):
\c [dbname][username][hostname][port]
\list db list
\dt tables list (current db)
\i [full path and file name with extension] import file.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment