Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions roles/alter_user_with_random_password.psql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions roles/create_user_with_random_password.psql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sql/i3_non_indexed_fks.sql
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion sql/i5_indexes_migration.sql
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion sql/l1_lock_trees.sql
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions sql/r1_create_user_with_random_password.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--Create user with random password (interactive)
\ir ../roles/create_user_with_random_password.psql
2 changes: 2 additions & 0 deletions sql/r2_alter_user_with_random_password.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--Alter user with random password (interactive)
\ir ../roles/alter_user_with_random_password.psql
4 changes: 2 additions & 2 deletions sql/t1_tuning.sql
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sql/v2_autovacuum_progress_and_queue.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--Vacuum: VACUUM progress and autovacuum queue
--Vacuum: vacuum progress and autovacuum queue
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VACUUM was fine here


-- Based on: https://gitlab.com/snippets/1889668

Expand Down
22 changes: 17 additions & 5 deletions start.psql
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
\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 ' l1 – Lock trees (leightweight)'
\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?'
\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'
\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'
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think VACUUM here should be uppercase

\echo ' q – Quit'
\echo
\echo Type your choice and press <Enter>:
Expand All @@ -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,
Expand Down Expand Up @@ -134,6 +138,14 @@ select
\ir ./sql/p1_alignment_padding.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_r1
\ir ./sql/r1_create_user_with_random_password.sql
\prompt 'Press <Enter> to continue…' d_dummy
\ir ./start.psql
\elif :d_step_is_r2
\ir ./sql/r2_alter_user_with_random_password.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
Expand Down
4 changes: 0 additions & 4 deletions warmup.psql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading