-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgres_queries2_
executable file
·67 lines (61 loc) · 1.69 KB
/
postgres_queries2_
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
61
62
63
64
65
66
#!/bin/bash
db="${0/*_/}"
if [ "$db" == "" ];then
echo "error/no db" >&2
exit 1
fi
#echo $db
if [ "$1" == "config" ];then
cat << EOF
graph_title Postgres queries2 on $db
graph_args --base 1000
graph_vlabel Queries per \${graph_period}
graph_category PostgreSQL
graph_info Shows number of select, insert, update and delete queries
sel_seq.label s_selects
sel_seq.info Sequential selects on all tables
sel_seq.type DERIVE
sel_seq.min 0
sel_seq_rows.label s_select rows
sel_seq_rows.info Rows returned from sequential selects
sel_seq_rows.type DERIVE
sel_seq.min 0
sel_idx.label i_selects
sel_idx.info Sequential selects on all indexes
sel_idx.type DERIVE
sel_seq.min 0
sel_idx_rows.label i_select rows
sel_idx_rows.info Rows returned form index selects
sel_idx_rows.type DERIVE
sel_seq_rows.min 0
inserts.label inserts
inserts.info Rows inserted on all tables
inserts.type DERIVE
inserts.min 0
updates.label updates
updates.info Rows updated on all tables
updates.type DERIVE
updates.min 0
deletes.label deletes
deletes.info Rows deleted from all tables
deletes.type DERIVE
deletes.min 0
EOF
else
psql -At $db << EOF
select
'sel_seq.value ' || SUM(seq_scan) || E'\n' ||
'sel_seq_rows.value ' || SUM(seq_tup_read) || E'\n' ||
'sel_idx.value ' || SUM(idx_scan) || E'\n' ||
'sel_idx_rows.value ' || SUM(idx_tup_fetch) || E'\n' ||
'inserts.value ' || SUM(n_tup_ins) || E'\n' ||
'updates.value ' || SUM(n_tup_upd) || E'\n' ||
'deletes.value ' || SUM(n_tup_del)
from pg_stat_all_tables;
EOF
# my $sql = "SELECT SUM(seq_scan),SUM(seq_tup_read), ";
# $sql .= "SUM(idx_scan),SUM(idx_tup_fetch), ";
# $sql .= "SUM(n_tup_ins),SUM(n_tup_upd),SUM(n_tup_del) ";
# $sql .= "from pg_stat_all_tables";
# echo 1
fi