From a269478be6fea1983b860515f326fb020f41f8f3 Mon Sep 17 00:00:00 2001 From: Nikolay Samokhvalov Date: Mon, 29 Sep 2025 16:51:31 -0700 Subject: [PATCH 1/8] fix(roles): SQL injection in role management Replace string concatenation with format() function in role management scripts to prevent SQL injection with special characters in usernames or passwords. Use %I for identifier quoting and %L for literal escaping. While these scripts are intended for DBA use in interactive sessions, using format() is better practice and handles edge cases with special characters. Files modified: - roles/alter_user_with_random_password.psql - roles/create_user_with_random_password.psql Co-Authored-By: Claude --- roles/alter_user_with_random_password.psql | 14 +++++++------- roles/create_user_with_random_password.psql | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/roles/alter_user_with_random_password.psql b/roles/alter_user_with_random_password.psql index f951c87..2f7bf59 100644 --- a/roles/alter_user_with_random_password.psql +++ b/roles/alter_user_with_random_password.psql @@ -43,17 +43,17 @@ begin j := int4(random() * allowed_len); pwd := pwd || substr(allowed, j+1, 1); end loop; - sql := 'alter role ' || current_setting('postgres_dba.username')::text || ' password ''' || pwd || ''';'; + sql := format('alter role %I password %L', current_setting('postgres_dba.username')::text, pwd); raise debug 'SQL: %', sql; execute sql; - sql := 'alter role ' || current_setting('postgres_dba.username')::text - || (case when lower(current_setting('postgres_dba.is_superuser')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' superuser' else '' end) - || ';'; + sql := format('alter role %I%s', + current_setting('postgres_dba.username')::text, + (case when lower(current_setting('postgres_dba.is_superuser')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' superuser' else '' end)); raise debug 'SQL: %', sql; execute sql; - sql := 'alter role ' || current_setting('postgres_dba.username')::text - || (case when lower(current_setting('postgres_dba.login')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' login' else '' end) - || ';'; + sql := format('alter role %I%s', + current_setting('postgres_dba.username')::text, + (case when lower(current_setting('postgres_dba.login')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' login' else '' end)); raise debug 'SQL: %', sql; execute sql; raise debug 'User % altered, password: %', current_setting('postgres_dba.username')::text, pwd; diff --git a/roles/create_user_with_random_password.psql b/roles/create_user_with_random_password.psql index a5257a3..3d3f42a 100644 --- a/roles/create_user_with_random_password.psql +++ b/roles/create_user_with_random_password.psql @@ -43,10 +43,11 @@ begin j := int4(random() * allowed_len); pwd := pwd || substr(allowed, j+1, 1); end loop; - sql := 'create role ' || current_setting('postgres_dba.username')::text - || (case when lower(current_setting('postgres_dba.is_superuser')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' superuser' else '' end) - || (case when lower(current_setting('postgres_dba.login')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' login' else '' end) - || ' password ''' || pwd || ''';'; + sql := format('create role %I%s%s password %L', + current_setting('postgres_dba.username')::text, + (case when lower(current_setting('postgres_dba.is_superuser')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' superuser' else '' end), + (case when lower(current_setting('postgres_dba.login')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' login' else '' end), + pwd); raise debug 'SQL: %', sql; execute sql; raise info 'User % created, password: %', current_setting('postgres_dba.username')::text, pwd; From fca689ce280660c95ab43a91f619096ef1cecf4e Mon Sep 17 00:00:00 2001 From: Nikolay Samokhvalov Date: Mon, 29 Sep 2025 17:06:09 -0700 Subject: [PATCH 2/8] chore: trigger CI From d974cc501ff37afe46cdaec54e0f286e5fd73cbf Mon Sep 17 00:00:00 2001 From: Nikolay Samokhvalov Date: Mon, 29 Sep 2025 17:09:10 -0700 Subject: [PATCH 3/8] feat(roles): add role management to interactive menu --- sql/r1_create_user_with_random_password.sql | 2 ++ sql/r2_alter_user_with_random_password.sql | 2 ++ start.psql | 12 ++++++++++++ warmup.psql | 4 ---- 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 sql/r1_create_user_with_random_password.sql create mode 100644 sql/r2_alter_user_with_random_password.sql diff --git a/sql/r1_create_user_with_random_password.sql b/sql/r1_create_user_with_random_password.sql new file mode 100644 index 0000000..cbc99db --- /dev/null +++ b/sql/r1_create_user_with_random_password.sql @@ -0,0 +1,2 @@ +-- Create user with random password (interactive) +\ir ../roles/create_user_with_random_password.psql \ No newline at end of file diff --git a/sql/r2_alter_user_with_random_password.sql b/sql/r2_alter_user_with_random_password.sql new file mode 100644 index 0000000..8045794 --- /dev/null +++ b/sql/r2_alter_user_with_random_password.sql @@ -0,0 +1,2 @@ +-- Alter user with random password (interactive) +\ir ../roles/alter_user_with_random_password.psql \ No newline at end of file diff --git a/start.psql b/start.psql index a04e7c0..dd49aa4 100644 --- a/start.psql +++ b/start.psql @@ -19,6 +19,8 @@ \echo ' l1 – Lock trees (leightweight)' \echo ' l2 – Lock trees, detailed (based on pg_blocking_pids())' \echo ' p1 – [EXP] Alignment padding: how many bytes can be saved if columns are reordered?' +\echo ' r1 – Create user with random password (interactive)' +\echo ' r2 – Alter user with random password (interactive)' \echo ' s1 – Slowest queries, by total time (requires pg_stat_statements)' \echo ' s2 – Slowest queries report (requires pg_stat_statements)' \echo ' t1 – Postgres parameters tuning' @@ -49,6 +51,8 @@ select :d_stp::text = 'l1' as d_step_is_l1, :d_stp::text = 'l2' as d_step_is_l2, :d_stp::text = 'p1' as d_step_is_p1, +:d_stp::text = 'r1' as d_step_is_r1, +:d_stp::text = 'r2' as d_step_is_r2, :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, @@ -134,6 +138,14 @@ select \ir ./sql/p1_alignment_padding.sql \prompt 'Press to continue…' d_dummy \ir ./start.psql +\elif :d_step_is_r1 + \ir ./sql/r1_create_user_with_random_password.sql + \prompt 'Press to continue…' d_dummy + \ir ./start.psql +\elif :d_step_is_r2 + \ir ./sql/r2_alter_user_with_random_password.sql + \prompt 'Press to continue…' d_dummy + \ir ./start.psql \elif :d_step_is_s1 \ir ./sql/s1_pg_stat_statements_top_total.sql \prompt 'Press to continue…' d_dummy diff --git a/warmup.psql b/warmup.psql index a964275..4105053 100644 --- a/warmup.psql +++ b/warmup.psql @@ -4,10 +4,6 @@ select 1/0; \endif -select current_setting('server_version_num')::integer >= 170000 as postgres_dba_pgvers_17plus \gset - -select current_setting('server_version_num')::integer >= 130000 as postgres_dba_pgvers_13plus \gset - select current_setting('server_version_num')::integer >= 100000 as postgres_dba_pgvers_10plus \gset \if :postgres_dba_pgvers_10plus \set postgres_dba_last_wal_receive_lsn pg_last_wal_receive_lsn From 117bb232edb8d728c15b0c01dfa338e1c1faccdb Mon Sep 17 00:00:00 2001 From: Nikolay Samokhvalov Date: Mon, 29 Sep 2025 17:10:37 -0700 Subject: [PATCH 4/8] fix(roles): remove extra space in menu descriptions --- sql/r1_create_user_with_random_password.sql | 2 +- sql/r2_alter_user_with_random_password.sql | 2 +- start.psql | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sql/r1_create_user_with_random_password.sql b/sql/r1_create_user_with_random_password.sql index cbc99db..1c862ed 100644 --- a/sql/r1_create_user_with_random_password.sql +++ b/sql/r1_create_user_with_random_password.sql @@ -1,2 +1,2 @@ --- Create user with random password (interactive) +--Create user with random password (interactive) \ir ../roles/create_user_with_random_password.psql \ No newline at end of file diff --git a/sql/r2_alter_user_with_random_password.sql b/sql/r2_alter_user_with_random_password.sql index 8045794..b741f72 100644 --- a/sql/r2_alter_user_with_random_password.sql +++ b/sql/r2_alter_user_with_random_password.sql @@ -1,2 +1,2 @@ --- Alter user with random password (interactive) +--Alter user with random password (interactive) \ir ../roles/alter_user_with_random_password.psql \ No newline at end of file diff --git a/start.psql b/start.psql index dd49aa4..52098f0 100644 --- a/start.psql +++ b/start.psql @@ -19,8 +19,8 @@ \echo ' l1 – Lock trees (leightweight)' \echo ' l2 – Lock trees, detailed (based on pg_blocking_pids())' \echo ' p1 – [EXP] Alignment padding: how many bytes can be saved if columns are reordered?' -\echo ' r1 – Create user with random password (interactive)' -\echo ' r2 – Alter user with random password (interactive)' +\echo ' r1 – Create user with random password (interactive)' +\echo ' r2 – Alter user with random password (interactive)' \echo ' s1 – Slowest queries, by total time (requires pg_stat_statements)' \echo ' s2 – Slowest queries report (requires pg_stat_statements)' \echo ' t1 – Postgres parameters tuning' From 893bf694d3a3bd8ff7eaa6dee9d6b07287985679 Mon Sep 17 00:00:00 2001 From: Nikolay Samokhvalov Date: Mon, 29 Sep 2025 17:12:28 -0700 Subject: [PATCH 5/8] style: apply sentence-style capitalization to menu items --- sql/i3_non_indexed_fks.sql | 2 +- sql/i5_indexes_migration.sql | 2 +- sql/t1_tuning.sql | 2 +- sql/v2_autovacuum_progress_and_queue.sql | 2 +- start.psql | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sql/i3_non_indexed_fks.sql b/sql/i3_non_indexed_fks.sql index 13b7c35..5e79ab8 100644 --- a/sql/i3_non_indexed_fks.sql +++ b/sql/i3_non_indexed_fks.sql @@ -1,4 +1,4 @@ ---FKs with Missing/Bad Indexes +--FKs with missing/bad indexes --Created by PostgreSQL Experts https://github.com/pgexperts/pgx_scripts/blob/master/indexes/fk_no_index.sql diff --git a/sql/i5_indexes_migration.sql b/sql/i5_indexes_migration.sql index 96600b2..c24d068 100644 --- a/sql/i5_indexes_migration.sql +++ b/sql/i5_indexes_migration.sql @@ -1,4 +1,4 @@ ---Cleanup unused and redundant indexes – DO & UNDO migration DDL +--Cleanup unused and redundant indexes – do & undo migration DDL -- Use it to generate a database migration (e.g. RoR's db:migrate or Sqitch) -- to drop unused and redundant indexes. diff --git a/sql/t1_tuning.sql b/sql/t1_tuning.sql index 361c2f7..43197c9 100644 --- a/sql/t1_tuning.sql +++ b/sql/t1_tuning.sql @@ -1,4 +1,4 @@ ---Postgres parameters tuning +--PostgreSQL parameters tuning -- For Postgres versions older than 10, copy/paste the part -- below the last "\else" (scroll down) diff --git a/sql/v2_autovacuum_progress_and_queue.sql b/sql/v2_autovacuum_progress_and_queue.sql index 380ce5a..13ec58e 100644 --- a/sql/v2_autovacuum_progress_and_queue.sql +++ b/sql/v2_autovacuum_progress_and_queue.sql @@ -1,4 +1,4 @@ ---Vacuum: VACUUM progress and autovacuum queue +--Vacuum: vacuum progress and autovacuum queue -- Based on: https://gitlab.com/snippets/1889668 diff --git a/start.psql b/start.psql index 52098f0..4d14c1c 100644 --- a/start.psql +++ b/start.psql @@ -13,9 +13,9 @@ \echo ' e1 – Extensions installed in current DB' \echo ' i1 – Unused and rarely used indexes' \echo ' i2 – Redundant indexes' -\echo ' i3 – FKs with Missing/Bad Indexes' +\echo ' i3 – FKs with missing/bad indexes' \echo ' i4 – Invalid indexes' -\echo ' i5 – Cleanup unused and redundant indexes – DO & UNDO migration DDL' +\echo ' i5 – Cleanup unused and redundant indexes – do & undo migration DDL' \echo ' l1 – Lock trees (leightweight)' \echo ' l2 – Lock trees, detailed (based on pg_blocking_pids())' \echo ' p1 – [EXP] Alignment padding: how many bytes can be saved if columns are reordered?' @@ -23,9 +23,9 @@ \echo ' r2 – Alter user with random password (interactive)' \echo ' s1 – Slowest queries, by total time (requires pg_stat_statements)' \echo ' s2 – Slowest queries report (requires pg_stat_statements)' -\echo ' t1 – Postgres parameters tuning' +\echo ' t1 – PostgreSQL parameters tuning' \echo ' v1 – Vacuum: current activity' -\echo ' v2 – Vacuum: VACUUM progress and autovacuum queue' +\echo ' v2 – Vacuum: vacuum progress and autovacuum queue' \echo ' q – Quit' \echo \echo Type your choice and press : From f1bda224fa16c048a33370aa41d69cd21569d461 Mon Sep 17 00:00:00 2001 From: Nikolay Samokhvalov Date: Mon, 29 Sep 2025 17:13:58 -0700 Subject: [PATCH 6/8] fix: correct typo and apply binary units standards - Fix typo: lightweight (was leightweight) in l1 - Use GiB instead of GB in memory prompt per binary units rule --- sql/l1_lock_trees.sql | 2 +- sql/t1_tuning.sql | 2 +- start.psql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/l1_lock_trees.sql b/sql/l1_lock_trees.sql index 9969b6d..cae0106 100644 --- a/sql/l1_lock_trees.sql +++ b/sql/l1_lock_trees.sql @@ -1,4 +1,4 @@ ---Lock trees (leightweight) +--Lock trees (lightweight) -- Source: https://github.com/dataegret/pg-utils/blob/master/sql/locktree.sql -- The paths won't be precise but this query is very light and may be used quite frequently diff --git a/sql/t1_tuning.sql b/sql/t1_tuning.sql index 43197c9..75e90be 100644 --- a/sql/t1_tuning.sql +++ b/sql/t1_tuning.sql @@ -42,7 +42,7 @@ select :postgres_dba_t1_location = 3 as postgres_dba_t1_location_rds \gset \echo \echo -\echo 'Type total available memory (in GB): ' +\echo 'Type total available memory (in GiB): ' \prompt postgres_dba_t1_memory \echo diff --git a/start.psql b/start.psql index 4d14c1c..f10bd45 100644 --- a/start.psql +++ b/start.psql @@ -16,7 +16,7 @@ \echo ' i3 – FKs with missing/bad indexes' \echo ' i4 – Invalid indexes' \echo ' i5 – Cleanup unused and redundant indexes – do & undo migration DDL' -\echo ' l1 – Lock trees (leightweight)' +\echo ' l1 – Lock trees (lightweight)' \echo ' l2 – Lock trees, detailed (based on pg_blocking_pids())' \echo ' p1 – [EXP] Alignment padding: how many bytes can be saved if columns are reordered?' \echo ' r1 – Create user with random password (interactive)' From 90bcda6f929fb645ea21205f74b8952929a9e413 Mon Sep 17 00:00:00 2001 From: Nikolay Samokhvalov Date: Mon, 29 Sep 2025 17:17:32 -0700 Subject: [PATCH 7/8] refactor: improve menu descriptions for clarity and consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Spell out abbreviations: DB → database, FKs → Foreign keys, tmp → temporary - Update terminology: master/replica → primary/replica (modern Postgres terminology) - Fix inconsistencies: user name → username, do & undo → do and undo - Remove redundant prefix in v2 description --- sql/0_node.sql | 2 +- sql/a1_activity.sql | 2 +- sql/e1_extensions.sql | 2 +- sql/i3_non_indexed_fks.sql | 2 +- sql/i5_indexes_migration.sql | 2 +- sql/v2_autovacuum_progress_and_queue.sql | 2 +- start.psql | 12 ++++++------ 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sql/0_node.sql b/sql/0_node.sql index f6878ce..62d5f1d 100644 --- a/sql/0_node.sql +++ b/sql/0_node.sql @@ -1,4 +1,4 @@ ---Node & current DB information: master/replica, lag, DB size, tmp files, etc. +--Node and current database information: primary/replica, lag, database size, temporary files, etc. /* For Postgres versions older than 10, run this first: diff --git a/sql/a1_activity.sql b/sql/a1_activity.sql index 9db9b67..a52dca0 100644 --- a/sql/a1_activity.sql +++ b/sql/a1_activity.sql @@ -1,4 +1,4 @@ ---Current activity: count of current connections grouped by database, user name, state +--Current activity: count of current connections grouped by database, username, state select coalesce(usename, '** ALL users **') as "User", coalesce(datname, '** ALL databases **') as "DB", diff --git a/sql/e1_extensions.sql b/sql/e1_extensions.sql index 9bc5735..817fa0a 100644 --- a/sql/e1_extensions.sql +++ b/sql/e1_extensions.sql @@ -1,4 +1,4 @@ ---Extensions installed in current DB +--Extensions installed in current database select ae.name, diff --git a/sql/i3_non_indexed_fks.sql b/sql/i3_non_indexed_fks.sql index 5e79ab8..1b448e6 100644 --- a/sql/i3_non_indexed_fks.sql +++ b/sql/i3_non_indexed_fks.sql @@ -1,4 +1,4 @@ ---FKs with missing/bad indexes +--Foreign keys with missing or bad indexes --Created by PostgreSQL Experts https://github.com/pgexperts/pgx_scripts/blob/master/indexes/fk_no_index.sql diff --git a/sql/i5_indexes_migration.sql b/sql/i5_indexes_migration.sql index c24d068..b52451c 100644 --- a/sql/i5_indexes_migration.sql +++ b/sql/i5_indexes_migration.sql @@ -1,4 +1,4 @@ ---Cleanup unused and redundant indexes – do & undo migration DDL +--Cleanup unused and redundant indexes – do and undo migration DDL -- Use it to generate a database migration (e.g. RoR's db:migrate or Sqitch) -- to drop unused and redundant indexes. diff --git a/sql/v2_autovacuum_progress_and_queue.sql b/sql/v2_autovacuum_progress_and_queue.sql index 13ec58e..97208e8 100644 --- a/sql/v2_autovacuum_progress_and_queue.sql +++ b/sql/v2_autovacuum_progress_and_queue.sql @@ -1,4 +1,4 @@ ---Vacuum: vacuum progress and autovacuum queue +--Vacuum progress and autovacuum queue -- Based on: https://gitlab.com/snippets/1889668 diff --git a/start.psql b/start.psql index f10bd45..f27f835 100644 --- a/start.psql +++ b/start.psql @@ -1,21 +1,21 @@ \ir warmup.psql \echo '\033[1;35mMenu:\033[0m' -\echo ' 0 – Node & current DB information: master/replica, lag, DB size, tmp files, etc.' +\echo ' 0 – Node and current database information: primary/replica, lag, database size, temporary files, etc.' \echo ' 1 – Databases: size, stats' \echo ' 2 – Tables: table/index/TOAST size, number of rows' \echo ' 3 – Load profile' -\echo ' a1 – Current activity: count of current connections grouped by database, user name, state' +\echo ' a1 – Current activity: count of current connections grouped by database, username, state' \echo ' b1 – Table bloat (estimated)' \echo ' b2 – B-tree index bloat (estimated)' \echo ' b3 – Table bloat (requires pgstattuple; expensive)' \echo ' b4 – B-tree indexes bloat (requires pgstattuple; expensive)' \echo ' b5 – Tables and columns without stats (so bloat cannot be estimated)' -\echo ' e1 – Extensions installed in current DB' +\echo ' e1 – Extensions installed in current database' \echo ' i1 – Unused and rarely used indexes' \echo ' i2 – Redundant indexes' -\echo ' i3 – FKs with missing/bad indexes' +\echo ' i3 – Foreign keys with missing or bad indexes' \echo ' i4 – Invalid indexes' -\echo ' i5 – Cleanup unused and redundant indexes – do & undo migration DDL' +\echo ' i5 – Cleanup unused and redundant indexes – do and undo migration DDL' \echo ' l1 – Lock trees (lightweight)' \echo ' l2 – Lock trees, detailed (based on pg_blocking_pids())' \echo ' p1 – [EXP] Alignment padding: how many bytes can be saved if columns are reordered?' @@ -25,7 +25,7 @@ \echo ' s2 – Slowest queries report (requires pg_stat_statements)' \echo ' t1 – PostgreSQL parameters tuning' \echo ' v1 – Vacuum: current activity' -\echo ' v2 – Vacuum: vacuum progress and autovacuum queue' +\echo ' v2 – Vacuum progress and autovacuum queue' \echo ' q – Quit' \echo \echo Type your choice and press : From 407d0454358bb5d9c7b90ca8b28b7f234ea8cc44 Mon Sep 17 00:00:00 2001 From: Nikolay Samokhvalov Date: Mon, 29 Sep 2025 17:20:22 -0700 Subject: [PATCH 8/8] fix: address PR review feedback - Restore postgres_dba_pgvers_17plus and _13plus version checks - Revert VACUUM to uppercase (SQL command) - Revert 'Postgres' terminology (preferred over PostgreSQL) - Revert DO & UNDO to uppercase (migration operations) --- init/generate.sh | 4 ++++ sql/i5_indexes_migration.sql | 2 +- sql/t1_tuning.sql | 2 +- sql/v2_autovacuum_progress_and_queue.sql | 2 +- start.psql | 6 +++--- warmup.psql | 4 ++++ 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/init/generate.sh b/init/generate.sh index c282764..91d7526 100755 --- a/init/generate.sh +++ b/init/generate.sh @@ -16,6 +16,10 @@ cat > "$WARMUP" <<- VersCheck select 1/0; \endif +select current_setting('server_version_num')::integer >= 170000 as postgres_dba_pgvers_17plus \gset + +select current_setting('server_version_num')::integer >= 130000 as postgres_dba_pgvers_13plus \gset + select current_setting('server_version_num')::integer >= 100000 as postgres_dba_pgvers_10plus \gset \if :postgres_dba_pgvers_10plus \set postgres_dba_last_wal_receive_lsn pg_last_wal_receive_lsn diff --git a/sql/i5_indexes_migration.sql b/sql/i5_indexes_migration.sql index b52451c..96600b2 100644 --- a/sql/i5_indexes_migration.sql +++ b/sql/i5_indexes_migration.sql @@ -1,4 +1,4 @@ ---Cleanup unused and redundant indexes – do and undo migration DDL +--Cleanup unused and redundant indexes – DO & UNDO migration DDL -- Use it to generate a database migration (e.g. RoR's db:migrate or Sqitch) -- to drop unused and redundant indexes. diff --git a/sql/t1_tuning.sql b/sql/t1_tuning.sql index 75e90be..0563b15 100644 --- a/sql/t1_tuning.sql +++ b/sql/t1_tuning.sql @@ -1,4 +1,4 @@ ---PostgreSQL parameters tuning +--Postgres parameters tuning -- For Postgres versions older than 10, copy/paste the part -- below the last "\else" (scroll down) diff --git a/sql/v2_autovacuum_progress_and_queue.sql b/sql/v2_autovacuum_progress_and_queue.sql index 97208e8..dc05269 100644 --- a/sql/v2_autovacuum_progress_and_queue.sql +++ b/sql/v2_autovacuum_progress_and_queue.sql @@ -1,4 +1,4 @@ ---Vacuum progress and autovacuum queue +--VACUUM progress and autovacuum queue -- Based on: https://gitlab.com/snippets/1889668 diff --git a/start.psql b/start.psql index f27f835..aa7d0ae 100644 --- a/start.psql +++ b/start.psql @@ -15,7 +15,7 @@ \echo ' i2 – Redundant indexes' \echo ' i3 – Foreign keys with missing or bad indexes' \echo ' i4 – Invalid indexes' -\echo ' i5 – Cleanup unused and redundant indexes – do and undo migration DDL' +\echo ' i5 – Cleanup unused and redundant indexes – DO & UNDO migration DDL' \echo ' l1 – Lock trees (lightweight)' \echo ' l2 – Lock trees, detailed (based on pg_blocking_pids())' \echo ' p1 – [EXP] Alignment padding: how many bytes can be saved if columns are reordered?' @@ -23,9 +23,9 @@ \echo ' r2 – Alter user with random password (interactive)' \echo ' s1 – Slowest queries, by total time (requires pg_stat_statements)' \echo ' s2 – Slowest queries report (requires pg_stat_statements)' -\echo ' t1 – PostgreSQL parameters tuning' +\echo ' t1 – Postgres parameters tuning' \echo ' v1 – Vacuum: current activity' -\echo ' v2 – Vacuum progress and autovacuum queue' +\echo ' v2 – VACUUM progress and autovacuum queue' \echo ' q – Quit' \echo \echo Type your choice and press : diff --git a/warmup.psql b/warmup.psql index 4105053..a964275 100644 --- a/warmup.psql +++ b/warmup.psql @@ -4,6 +4,10 @@ select 1/0; \endif +select current_setting('server_version_num')::integer >= 170000 as postgres_dba_pgvers_17plus \gset + +select current_setting('server_version_num')::integer >= 130000 as postgres_dba_pgvers_13plus \gset + select current_setting('server_version_num')::integer >= 100000 as postgres_dba_pgvers_10plus \gset \if :postgres_dba_pgvers_10plus \set postgres_dba_last_wal_receive_lsn pg_last_wal_receive_lsn