-
Notifications
You must be signed in to change notification settings - Fork 0
/
.psqlrc
60 lines (47 loc) · 2.36 KB
/
.psqlrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
\set QUIET 1
-- http://www.postgresql.org/docs/9.3/static/app-psql.html#APP-PSQL-PROMPTING
-- http://stackoverflow.com/questions/19139330/colors-in-the-psql-prompt
\set PROMPT1 '(%n@%M:%>) %`date +%H:%M:%S` [%/] \n%x%# '
-- PROMPT2 is printed when the prompt expects more input
\set PROMPT2 '[more] %R > '
-- Show how long each query takes to execute
\timing
-- Better formatted tables
\pset format wrapped
\pset border 2
\pset linestyle unicode
-- Output layout
\pset pager on
\setenv PAGER 'pspg -bX --vertical-cursor'
-- By default, NULL displays as an empty space. Is it actually an empty
-- string, or is it null? This makes that distinction visible.
\pset null '[NULL]'
-- Use table format (with headers across the top) by default, but switch to
-- expanded table format when there's a lot of data, which makes it much
-- easier to read.
-- \x auto
-- Because of fancy pager pspg, never use \x
\x off
-- Wrap all commands issued interactively in SAVEPOINTs so we can try again
-- without having to restart the transaction
\set ON_ERROR_ROLLBACK interactive
-- Autocomplete keywords (like SELECT) in uppercase.
\set COMP_KEYWORD_CASE upper
-- Verbose error reports.
\set VERBOSITY verbose
\set HISTSIZE 100000
-- Use a separate history file per-database.
\set HISTFILE ~/.psql_history- :DBNAME
-- If a command is run more than once in a row, only store it once in the
-- history.
\set HISTCONTROL ignoredups
-- Helpful queries, use them with a colon, e.g. :uptime
\set uptime 'select now() - backend_start as uptime from pg_stat_activity where pid = pg_backend_pid();'
\set show_slow_queries 'SELECT (total_time / 1000 / 60) as total_minutes, (total_time/calls) as average_time, query FROM pg_stat_statements ORDER BY 1 DESC LIMIT 100;'
\set settings 'select name, setting,unit,context from pg_settings;'
\set conninfo 'select usename, count(*) from pg_stat_activity group by usename;'
\set dbsize 'SELECT datname, pg_size_pretty(pg_database_size(datname)) db_size FROM pg_database ORDER BY db_size;'
\set tablesize 'SELECT nspname || \'.\' || relname AS \"relation\", pg_size_pretty(pg_relation_size(C.oid)) AS "size" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE nspname NOT IN (\'pg_catalog\', \'information_schema\') ORDER BY pg_relation_size(C.oid) DESC LIMIT 40;'
\set clear '\\! clear;'
set search_path to public, app_public, app_hidden, app_private;
\unset QUIET