-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.psqlrc
20 lines (14 loc) · 2.35 KB
/
.psqlrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
\set QUIET 1
\set PROMPT1 '%n@%m:%/%# '
\pset pager off
\pset null '␀'
\set check_index_creation 'SELECT now() :: TIME(0), a.query, p.phase, p.blocks_done, p.blocks_total, round(100.0 * p.blocks_done / (p.blocks_total + 0.00000001), 2) as blocks_pct, p.tuples_done, p.tuples_total, case when p.tuples_total != 0 then round(100.0 * p.tuples_done / p.tuples_total, 2) else 0 end as tuples_pct FROM pg_stat_progress_create_index p JOIN pg_stat_activity a ON p.pid = a.pid;'
\set list_blocked 'SELECT a.blocked_pid, left(regexp_replace(a.blocked_query, \'/\*.*\*/\', \'\'), 100) as blocked_query, left(a.blocked_app, 30) as blocked_app, b.pid as blocking_pid, b.wait_event as blocking_wait, left(regexp_replace(b.query, \'/\*.*\*/\', \'\'), 100) as blocking_query, b.application_name as blocking_app FROM (SELECT pid as blocked_pid, UNNEST(pg_blocking_pids(pid)) as blocking, query as blocked_query, application_name as blocked_app FROM pg_stat_activity WHERE pg_blocking_pids(pid) :: text != \'{}\') a JOIN pg_stat_activity b on a.blocking = b.pid;'
\set list_blocked_no_limit 'SELECT a.blocked_pid, regexp_replace(a.blocked_query, \'/\*.*\*/\', \'\') as blocked_query, left(a.blocked_app, 30) as blocked_app, b.pid as blocking_pid, b.wait_event as blocking_wait, regexp_replace(b.query, \'/\*.*\*/\', \'\') as blocking_query, b.application_name as blocking_app FROM (SELECT pid as blocked_pid, UNNEST(pg_blocking_pids(pid)) as blocking, query as blocked_query, application_name as blocked_app FROM pg_stat_activity WHERE pg_blocking_pids(pid) :: text != \'{}\') a JOIN pg_stat_activity b on a.blocking = b.pid;'
\set list_long_running 'SELECT datname, state, pid, leader_pid, usename, now() - query_start as duration, left(query, 200) as trunc_query FROM pg_stat_activity where (now() - query_start) > \'30 seconds\' and query not ilike \'%pg_stat_activity%\' and query not ilike \'%commit\' and query not ilike \'%rollback\' order by duration desc;'
\set list_long_running_no_limit 'SELECT datname, state, pid, leader_pid, usename, now() - query_start as duration, query FROM pg_stat_activity where (now() - query_start) > \'30 seconds\' and query not ilike \'%pg_stat_activity%\' and query not ilike \'%commit\' and query not ilike \'%rollback\' order by duration desc;'
\timing
\set HISTFILE ~/.psql_history- :HOST - :DBNAME
\set HISTCONTROL ignoredups
\set COMP_KEYWORD_CASE upper
\unset QUIET