Skip to content

Commit e42bed4

Browse files
authored
Merge pull request #9 from NikolayS/activity
new report: Current Activity
2 parents 73439d6 + 1efacb4 commit e42bed4

File tree

7 files changed

+28
-4
lines changed

7 files changed

+28
-4
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ jobs:
3535
#echo "\set postgres_dba_wide false" > ~/.psqlrc
3636
#for f in ~/postgres_dba/sql/*; do psql test -f "$f">/dev/null; done
3737
diff -b test/regression/1_basic.out <(psql test -f warmup.psql -f ~/postgres_dba/sql/1_basic.sql | grep Role)
38-
diff -b test/regression/a1_alignment_padding.out <(psql test -f warmup.psql -f ~/postgres_dba/sql/a1_alignment_padding.sql | grep align)
38+
diff -b test/regression/p1_alignment_padding.out <(psql test -f warmup.psql -f ~/postgres_dba/sql/p1_alignment_padding.sql | grep align)
39+
diff -b test/regression/a1_activity.out <(psql test -f warmup.psql -f ~/postgres_dba/sql/a1_activity.sql | grep User)

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[![CircleCI](https://circleci.com/gh/NikolayS/postgres_dba.svg?style=svg)](https://circleci.com/gh/NikolayS/postgres_dba)
2-
32
# postgres_dba (PostgresDBA)
43

54
The missing set of useful tools for Postgres DBA and mere mortals.

sql/a1_activity.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--Current Activity: count of current connections grouped by database, user name, state
2+
select
3+
coalesce(usename, '** ALL users **') as "User",
4+
coalesce(datname, '** ALL databases **') as "DB",
5+
coalesce(state, '** ALL states **') as "Current State",
6+
count(*) as "Count",
7+
count(*) filter (where state_change < now() - interval '1 minute') as "State changed >1m ago",
8+
count(*) filter (where state_change < now() - interval '1 hour') as "State changed >1h ago"
9+
from pg_stat_activity
10+
group by grouping sets ((datname, usename, state), (usename, state), ())
11+
order by
12+
usename is null desc,
13+
datname is null desc,
14+
2 asc,
15+
3 asc,
16+
count(*) desc
17+
;
File renamed without changes.

start.psql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\echo ' 1 – Node Information: master/replica, lag, DB size, tmp files, etc'
55
\echo ' 2 – Table Size'
66
\echo ' 3 – Load Profile'
7-
\echo ' a1 – [EXPERIMENTAL] Alignment Padding. How many bytes can be saved if columns are ordered better?'
7+
\echo ' a1 – Current Activity: count of current connections grouped by database, user name, state'
88
\echo ' b1 – Tables Bloat, rough estimation'
99
\echo ' b2 – B-tree Indexes Bloat, rough estimation'
1010
\echo ' b3 – Tables Bloat, more precise (requires pgstattuple extension; expensive)'
@@ -13,6 +13,7 @@
1313
\echo ' i1 – Unused/Rarely Used Indexes'
1414
\echo ' i2 – Unused/Redundant Indexes Do & Undo Migration DDL'
1515
\echo ' i3 – FKs with Missing/Bad Indexes'
16+
\echo ' p1 – [EXPERIMENTAL] Alignment Padding. How many bytes can be saved if columns are ordered better?'
1617
\echo ' s1 – Slowest Queries, by Total Time (requires pg_stat_statements extension)'
1718
\echo ' s2 – Slowest Queries Report (requires pg_stat_statements)'
1819
\if :postgres_dba_wide
@@ -38,6 +39,7 @@ select
3839
:d_stp::text = 'i1' as d_step_is_i1,
3940
:d_stp::text = 'i2' as d_step_is_i2,
4041
:d_stp::text = 'i3' as d_step_is_i3,
42+
:d_stp::text = 'p1' as d_step_is_p1,
4143
:d_stp::text = 's1' as d_step_is_s1,
4244
:d_stp::text = 's2' as d_step_is_s2,
4345
:d_stp::text = 'x' as d_step_is_x,
@@ -69,7 +71,7 @@ set postgres_dba.wide = 'on';
6971
\prompt 'Press <Enter> to continue…' d_dummy
7072
\ir ./start.psql
7173
\elif :d_step_is_a1
72-
\ir ./sql/a1_alignment_padding.sql
74+
\ir ./sql/a1_activity.sql
7375
\prompt 'Press <Enter> to continue…' d_dummy
7476
\ir ./start.psql
7577
\elif :d_step_is_b1
@@ -104,6 +106,10 @@ set postgres_dba.wide = 'on';
104106
\ir ./sql/i3_non_indexed_fks.sql
105107
\prompt 'Press <Enter> to continue…' d_dummy
106108
\ir ./start.psql
109+
\elif :d_step_is_p1
110+
\ir ./sql/p1_alignment_padding.sql
111+
\prompt 'Press <Enter> to continue…' d_dummy
112+
\ir ./start.psql
107113
\elif :d_step_is_s1
108114
\ir ./sql/s1_pg_stat_statements_top_total.sql
109115
\prompt 'Press <Enter> to continue…' d_dummy

test/regression/a1_activity.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
User | DB | Current State | Count | State changed >1m ago | State changed >1h ago

0 commit comments

Comments
 (0)