Skip to content

Instantly share code, notes, and snippets.

@paxinla
Created June 18, 2021 02:41
Show Gist options
  • Save paxinla/24e4e13e0e8dee19ec22cc2a561ed97b to your computer and use it in GitHub Desktop.
Save paxinla/24e4e13e0e8dee19ec22cc2a561ed97b to your computer and use it in GitHub Desktop.
example_psqlrc
\set QUIET 1
\set ON_ERROR_ROLLBACK interactive
\set VERBOSITY verbose
/* psql escape codes:
%M - full host + domain for db server, or [local] (if over Unix socket), or [local:/dir/name]
%m - host name of the db server, truncated at the first dot, or [local] (if over Unix socket)
%> - port where db server is listening
%n - database session user name (changes based on SET SESSION AUTHORIZATION)
%/ - current database name
%~ - like %/ but the output is ~ if the database is the default
%# - # if user is superuser, else > (changes based on SET SESSION AUTHORIZATION)
%R - in prompt 1: = (normal), ^ (single-line mode), ! (disconnected)
%R - in prompt 2: - (more input expected), * (in a comment), ' or " or $ (inside a string)
%x - Transaction status: an empty string when not in a transaction block, or * when in a transaction block, or ! when in a failed transaction block, or ? when the transaction state is indeterminate (for example, because there is no connection).
*/
/* ANSI control sequences http://www.termsys.demon.co.uk/vtansi.htm
Display Attribute FG / BG Color
0 Reset ALL 30 / 40 Black
1 Bright 31 / 41 Red
2 Dim 32 / 42 Green
4 Underscore 33 / 43 Yellow
5 Blink 34 / 44 Blue
7 Reverse 35 / 45 Magenta
8 Hidden 36 / 46 Cyan
37 / 47 White
39 / 49 Default
*/
\set PROMPT1 '%`hostname -s`=>(%[%033[1;31;49m%]%M%[%033[0m%]):%>-> %p [%[%033[2;35;49m%]%n%[%033[0m%]@%[%033[0;33;49m%]%/%[%033[0m%]] %# '
\set PROMPT2 '... %# '
\timing
\pset null '¤ '
\pset pager always
\setenv PAGER more
\x auto
\set VERBOSITY verbose
\set HISTFILE ~/.psql_history/db_history- :DBNAME
\set HISTCONTROL ignoredups
\set COMP_KEYWORD_CASE upper
\unset QUIET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment