pgcli Smarter Postgres shell
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
pgcli -h <host> -U <user> -d <db>
pgcli
"postgresql://<user>@<host>/<db>"
\dt\d <table>
\x\e\ns <name> <query>
\qConcepts
- Connect flags, URI, DSN alias
- Prompt smart completion
- Result table format, pager
- Config ~/.config/pgcli/config
Connect
pgcli -h <host> -p <port> -U <user> -d
<db>
pgcli <db>
pgcli
"postgresql://<user>@<host>:<port>/<db>"
pgcli -Wpgcli -wpgcli -D <alias>
pgcli --list-dsn
pgcli -lpgcli --pingpgcli --ssh-tunnel <user@host>
pgcli --init-command "<sql>"
\c <db>\conninfoInspect
\l\dt\d <table>
\d+ <table>
\dn\dv\dm\di\ds\df\sf <function>
\du\dx\dp <table>
\dTRun SQL
pgcli -c "<sql>" <db>
pgcli -f <file.sql> <db>
\i <file>\e\e <file>\watch <sec>
\copy <table> from '<file>' csv
header
\copy (<query>) to '<file>' csv
header
\! <command>
\h <statement>
\?Output
\xpgcli --auto-vertical-output
\timing\T <format>
\o <file>\log-file <file>
\pager <command>
pgcli -t -c "<sql>" <db>
\pset null <text>
\v on\echo <text>
Completion & Keys
F2F3F4F5TabCtrl+SpaceAlt+EnterCtrl+p / Ctrl+n
Ctrl+rCtrl+a / Ctrl+e
\refresh\#Named Queries
\ns <name> <query>
\n\n <name> [args]
\np <pattern>
\nd <name>
\ne <name>
\ns <name> ... in ($*)
\ns <name> ... in ($@)
Config
~/.config/pgcli/config
pgcli --pgclirc <file>
smart_completion = True
multi_line = True
table_format = psql
expand = Trueauto_expand = True
destructive_warning = drop, delete
vi = Truekeyword_casing = upper
row_limit = 1000
generate_aliases = True
null_string = <null>
prompt = \u@\h:\d>
pgcli --less-chatty
~/.config/pgcli/log
Recipes
# config: [alias_dsn] prod = postgresql://app@db.example.com/apppgcli -D prod
\ns by_user select * from orders where user_id = $1\n by_user 42
\o out.txtselect * from <table>;\o
pgcli --ssh-tunnel me@bastion.example.com -h db.internal -U app app



