Skip to content

Instantly share code, notes, and snippets.

@garudareiga
Last active December 21, 2015 02:59
Show Gist options
  • Save garudareiga/6238705 to your computer and use it in GitHub Desktop.
Save garudareiga/6238705 to your computer and use it in GitHub Desktop.
Some stuff about PostgreSQL

PostgreSQL .psqlrc Tips

List of tips:

  • Show date on startup
  • Be verbose about feeback
  • Set all null fields to NULL
  • Turn off the pager so that results keep scrolling by, rather than stopping
  • Set the command history files for each host and database
  • Set the number of commands to store in the command history
  • Set timing on and show how long it takes to run each query

Configure .psqlrc as follows:

\echo `date  +"%Y-%m-%d %H:%M:%S"`
\set VERBOSITY verbose
\pset null 'NULL'
\pset pager off
\set HISTFILE ~/.psql_history- :HOST - :DBNAME
\set HISTSIZE 2000
\timing

One additional tip is to add less to PAGER environment variable if you want to use less rather than more. Add the following to profile ~/.profile or /etc/profile

export PAGER=less

Useful Links

PostgreSQL Stuff

PostgreSQL .psqlrc tips and tricks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment