forked from damonmorgan/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsqlrc
18 lines (18 loc) · 1.87 KB
/
psqlrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\set QUIET 1
\x auto
\set PROMPT1 '%[%033[33;1m%]%x%[%033[0m%]%[%033[1m%]%/%[%033[0m%]%R%# '
\pset pager off
\timing
\pset linestyle unicode
\pset border 2
\pset null ¤
\set HISTCONTROL ignoredups
\set COMP_KEYWORD_CASE upper
\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 ps 'SELECT pid, backend_start, application_name, left(query, 80), state FROM pg_stat_activity order by backend_start;'
\set psa 'SELECT pid, backend_start, application_name, left(query, 80), state FROM pg_stat_activity WHERE state = \'active\' order by backend_start;'
\set blocking 'SELECT kl.pid as blocking_pid, ka.usename as blocking_user, ka.query as blocking_query, bl.pid as blocked_pid, a.usename as blocked_user, a.query as blocked_query, to_char(age(now(), a.query_start),\'HH24h:MIm:SSs\') as age FROM pg_catalog.pg_locks bl JOIN pg_catalog.pg_stat_activity a ON bl.pid = a.pid JOIN pg_catalog.pg_locks kl ON bl.locktype = kl.locktype and bl.database is not distinct from kl.database and bl.relation is not distinct from kl.relation and bl.page is not distinct from kl.page and bl.tuple is not distinct from kl.tuple and bl.virtualxid is not distinct from kl.virtualxid and bl.transactionid is not distinct from kl.transactionid and bl.classid is not distinct from kl.classid and bl.objid is not distinct from kl.objid and bl.objsubid is not distinct from kl.objsubid and bl.pid <> kl.pid JOIN pg_catalog.pg_stat_activity ka ON kl.pid = ka.pid WHERE kl.granted and not bl.granted ORDER BY a.query_start;'
\set delayed_job 'select attempts, left(handler,140), created_at, failed_at, locked_by from delayed_jobs order by created_at;'
\set version 'SELECT version();'
\echo 'Type :version to see the PostgreSQL version, :ps to see running processes, :blocking to see blocked processes \n'
\unset QUIET