Skip to content

Commit

Permalink
Adding documentation and cosmetic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
3manuek committed Aug 23, 2023
1 parent edea849 commit 27429f6
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Most active tables. 8.4
-- Most active tables. +v8.4
-- Table activity limited to top 10 by size of the table
-- This query will show the size of the table with/out indexes , how many times was accessed seq/index, and metrics of the several cache hits of the table(rows, index, pg_toast, index.pg_toast)
WITH most_active_tables AS (
Expand Down
3 changes: 3 additions & 0 deletions sql/DDL/get_create_table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Get CREATE TABLE query

This query brings the DDL of the defined table in the filter `c.relname like '<table>'`. Change the filter with the table that you want to inspect.
2 changes: 1 addition & 1 deletion sql/PgStatStatements/unstable_queries.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Unstable queries, with larges deltas.

-- Uses the standard deviation for calculating the query stability
SELECT queryid, calls,mean_exec_time, max_exec_time, query,
rows, shared_blks_read,

Expand Down
2 changes: 1 addition & 1 deletion sql/Replication/Logical/publication_info.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- getting publication info more verbose 10
-- Getting verbose publication info for +v10
select pubname, pu.usename, puballtables ,
pr.prrelid::regclass as source_class,
ltrim(case pubinsert when true then ' ins' end || case pubdelete when true then ' del' end || case pubupdate when true then ' upd' end) as events
Expand Down
34 changes: 17 additions & 17 deletions sql/Replication/Streaming/leader_replication_status_v10+.sql
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
-- Only for getting the status of those pids for streaming replication.
--
SELECT client_addr,
client_hostname,
client_port,
rs.slot_name,
rs.slot_type,
state,
pg_wal_lsn_diff(pg_current_wal_flush_lsn(), flush_lsn), --in bytes
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_flush_lsn(), flush_lsn)),
pg_wal_lsn_diff(pg_current_wal_lsn(), write_lsn) as fromCurrentToWriteLSN, --in bytes
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), write_lsn)) as fromCurrentToWriteLSN_pretty,
write_lsn, sent_lsn, flush_lsn, replay_lsn,
write_lag, flush_lag, replay_lag,
rs.restart_lsn, rs.confirmed_flush_lsn,
sync_state, sync_priority
FROM pg_stat_replication sr JOIN pg_replication_slots rs
ON (sr.pid = rs.active_pid)
WHERE rs.slot_type = 'physical';
SELECT client_addr,
client_hostname,
client_port,
rs.slot_name,
rs.slot_type,
state,
pg_wal_lsn_diff(pg_current_wal_flush_lsn(), flush_lsn), --in bytes
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_flush_lsn(), flush_lsn)),
pg_wal_lsn_diff(pg_current_wal_lsn(), write_lsn) as fromCurrentToWriteLSN, --in bytes
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), write_lsn)) as fromCurrentToWriteLSN_pretty,
write_lsn, sent_lsn, flush_lsn, replay_lsn,
write_lag, flush_lag, replay_lag,
rs.restart_lsn, rs.confirmed_flush_lsn,
sync_state, sync_priority
FROM pg_stat_replication sr JOIN pg_replication_slots rs
ON (sr.pid = rs.active_pid)
WHERE rs.slot_type = 'physical';
File renamed without changes.
6 changes: 6 additions & 0 deletions sql/Settings/all_settings.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Get settings ordered by context
SELECT name, setting,
short_desc::text , extra_desc::text,
context
FROM pg_settings
ORDER BY context;
15 changes: 0 additions & 15 deletions sql/Settings/generic.sql

This file was deleted.

5 changes: 5 additions & 0 deletions sql/SharedBuffers/shared_buffers_agg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Shared Buffers Aggregation

This query requires the `pg_buffercache` extension installed in the database.

> NOTE: beware that this extension needs locks for reading blocks in the shared buffers.
5 changes: 5 additions & 0 deletions sql/SharedBuffers/shared_buffers_inspection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Shared Buffers Inspection

It is recommended to LIMIT the bufs table expression in production environments.

> NOTE: beware that this extension needs locks over shared buffers, use carefully in production environments.
6 changes: 2 additions & 4 deletions sql/SharedBuffers/shared_buffers_inspection.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ SELECT c.relname as rel,
ORDER BY 2 DESC
-- In the case of Productive environments, you can limit the number of relations to reduce the LWLock issuing.
-- LIMIT 20
)
,
),
_settings AS (
-- TODO: We want also to consider wal_buffers, max_connection allocations
SELECT setting::int
Expand Down Expand Up @@ -47,5 +46,4 @@ SELECT rel, buffers,
-- The percentage of dirty shared buffers
sum( round(((100*dirtypages::double precision)/s.setting::double precision)::numeric,2) ) OVER () as dirty_perc_of_sb

from bufs b, _settings s
;
from bufs b, _settings s;
File renamed without changes.
3 changes: 2 additions & 1 deletion sql/WAL/distance_wals.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- Execute this on replica to know which is the
-- files need to be copied
-- files need to be copied. This returns the current WAL LSN in the replica,
-- you should copy all the WAL files newer than this point.
select pg_walfile_name(pg_current_wal_lsn());

0 comments on commit 27429f6

Please sign in to comment.