-
Notifications
You must be signed in to change notification settings - Fork 0
/
.psqlrc
29 lines (26 loc) · 2.92 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
\set AUTOCOMMIT OFF
\set PROMPT1 '%[%033[0;33m%]%M AC=%:AUTOCOMMIT: %[%033[0;34m%]%n%[%033[0m%]@%[%033[1;32m%]%~%[%033[0;37m%]%R%[%033[1;36m%]%x%[%033[0m%]%#%[%033[0m%]% '
\set PROMPT2 '%[%033[1m%][%[%033[0m%]more%[%033[1m%]]%[%033[0m%] %R > '
-- Use a separate history file per-database.
\set HISTFILE ~/.psql_history/:DBNAME
\set HISTCONTROL ignoredups
\set COMP_KEYWORD_CASE upper
\timing
-- --------------------------------------------------------------------------
-- run the following queries simply with for example:
-- :tablesize
-- --------------------------------------------------------------------------
\set connlimits 'SELECT rolname, rolconnlimit FROM pg_roles WHERE rolconnlimit <> -1;'
\set conninfo 'select usename, count(*) from pg_stat_activity group by usename;'
\set settings 'select name, setting,unit,context from pg_settings;'
-- \set locks 'SELECT bl.pid AS blocked_pid, a.usename AS blocked_user, kl.pid AS blocking_pid, ka.usename AS blocking_user, a.query AS blocked_statement FROM pg_catalog.pg_locks bl JOIN pg_catalog.pg_stat_activity a ON bl.pid = a.pid JOIN pg_catalog.pg_locks kl JOIN pg_catalog.pg_stat_activity ka ON kl.pid = ka.pid ON bl.transactionid = kl.transactionid AND bl.pid != kl.pid WHERE NOT bl.granted;'
\set activity 'select datname, procpid, usename, application_name,client_addr, client_hostname, client_port, current_query as query, waiting from pg_stat_activity;'
\set waits 'SELECT pg_stat_activity.pid, pg_stat_activity.query, pg_stat_activity.waiting, now() - pg_stat_activity.query_start AS \"totaltime\", pg_stat_activity.backend_start FROM pg_stat_activity WHERE pg_stat_activity.query !~ \'%IDLE%\'::text AND pg_stat_activity.waiting = true;'
\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 uselesscol 'SELECT nspname, relname, attname, typname, (stanullfrac*100)::int AS null_percent, case when stadistinct >= 0 then stadistinct else abs(stadistinct)*reltuples end AS \"distinct\", case 1 when stakind1 then stavalues1 when stakind2 then stavalues2 end AS \"values\" FROM pg_class c JOIN pg_namespace ns ON (ns.oid=relnamespace) JOIN pg_attribute ON (c.oid=attrelid) JOIN pg_type t ON (t.oid=atttypid) JOIN pg_statistic ON (c.oid=starelid AND staattnum=attnum) WHERE nspname NOT LIKE E\'pg\\\\_%\' AND nspname != \'information_schema\' AND relkind=\'r\' AND NOT attisdropped AND attstattarget != 0 AND reltuples >= 100 AND stadistinct BETWEEN 0 AND 1 ORDER BY nspname, relname, attname;'
\set uptime 'select now() - pg_postmaster_start_time() AS uptime;'
-- Display NULL values as <null>
\pset null '<null>'
\pset linestyle unicode
\pset border 2