forked from NikolayS/postgres_dba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.psql
144 lines (143 loc) · 4.74 KB
/
start.psql
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
\ir warmup.psql
\echo '\033[1;35mMenu:\033[0m'
\echo ' 0 – Node & Current DB Information: master/replica, lag, DB size, tmp files, etc'
\echo ' 1 – Databases: Size, Statistics'
\echo ' 2 – Table Sizes'
\echo ' 3 – Load Profile'
\echo ' a1 – Current Activity: count of current connections grouped by database, user name, state'
\echo ' b1 – Tables Bloat, rough estimation'
\echo ' b2 – B-tree Indexes Bloat, rough estimation'
\echo ' b3 – Tables Bloat, more precise (requires pgstattuple extension; expensive)'
\echo ' b4 – B-tree Indexes Bloat, more precise (requires pgstattuple extension; expensive)'
\echo ' b5 – Tables and Columns Without Stats (so bloat cannot be estimated)'
\echo ' i1 – Unused/Rarely Used Indexes'
\echo ' i2 – Unused/Redundant Indexes Do & Undo Migration DDL'
\echo ' i3 – FKs with Missing/Bad Indexes'
\echo ' p1 – [EXPERIMENTAL] Alignment Padding. How many bytes can be saved if columns are ordered better?'
\echo ' s1 – Slowest Queries, by Total Time (requires pg_stat_statements extension)'
\echo ' s2 – Slowest Queries Report (requires pg_stat_statements)'
\echo ' t1 – Postgres parameters tuning'
\echo ' v1 – Vacuum: Current Activity'
\if :postgres_dba_wide
\echo ' x – Turn Wide Mode OFF (currently ON): show less details, less columns'
\else
\echo ' x – Turn Wide Mode ON (currently OFF): show more details, more columns'
\endif
\echo ' q – Quit'
\echo
\echo Type your choice and press <Enter>:
\prompt d_step_unq
\set d_stp '\'' :d_step_unq '\''
select
:d_stp::text = '0' as d_step_is_0,
:d_stp::text = '1' as d_step_is_1,
:d_stp::text = '2' as d_step_is_2,
:d_stp::text = '3' as d_step_is_3,
:d_stp::text = 'a1' as d_step_is_a1,
:d_stp::text = 'b1' as d_step_is_b1,
:d_stp::text = 'b2' as d_step_is_b2,
:d_stp::text = 'b3' as d_step_is_b3,
:d_stp::text = 'b4' as d_step_is_b4,
:d_stp::text = 'b5' as d_step_is_b5,
:d_stp::text = 'i1' as d_step_is_i1,
:d_stp::text = 'i2' as d_step_is_i2,
:d_stp::text = 'i3' as d_step_is_i3,
:d_stp::text = 'p1' as d_step_is_p1,
:d_stp::text = 's1' as d_step_is_s1,
:d_stp::text = 's2' as d_step_is_s2,
:d_stp::text = 't1' as d_step_is_t1,
:d_stp::text = 'v1' as d_step_is_v1,
:d_stp::text = 'x' as d_step_is_x,
:d_stp::text = 'q' as d_step_is_q \gset
\if :d_step_is_q
\echo 'Bye!'
\echo
\elif :d_step_is_x
\if :postgres_dba_wide
set postgres_dba.wide = 'off';
\echo 'Wide mode turned OFF!'
\echo
\else
set postgres_dba.wide = 'on';
\echo 'Wide mode turned ON!'
\echo
\endif
\ir ./start.psql
\elif :d_step_is_0
\ir ./sql/0_node.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_1
\ir ./sql/1_databases.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_2
\ir ./sql/2_table_sizes.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_3
\ir ./sql/3_load_profiles.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_a1
\ir ./sql/a1_activity.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_b1
\ir ./sql/b1_table_estimation.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_b2
\ir ./sql/b2_btree_estimation.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_b3
\ir ./sql/b3_table_pgstattuple.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_b4
\ir ./sql/b4_btree_pgstattuple.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_b5
\ir ./sql/b5_tables_no_stats.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_i1
\ir ./sql/i1_rare_indexes.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_i2
\ir ./sql/i2_redundant_indexes.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_i3
\ir ./sql/i3_non_indexed_fks.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_p1
\ir ./sql/p1_alignment_padding.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_s1
\ir ./sql/s1_pg_stat_statements_top_total.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_s2
\ir ./sql/s2_pg_stat_statements_report.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_t1
\ir ./sql/t1_tuning.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_v1
\ir ./sql/v1_vacuum_activity.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\else
\echo
\echo '\033[1;31mError:\033[0m Unknown option! Try again.'
\echo
\ir ./start.psql
\endif