From df320ce3ffdc07ea8a3277510dedf4a97b4a4907 Mon Sep 17 00:00:00 2001 From: Emanuel Calvo <3manuek@gmail.com> Date: Tue, 20 Jun 2023 19:12:03 +0200 Subject: [PATCH] feat: queries related to lsn updated Signed-off-by: Emanuel Calvo <3manuek@gmail.com> --- sql/Checkpoints/.gitkeep | 0 sql/Checkpoints/checkpoint_distance.sql | 5 ++--- sql/Checkpoints/checkpoint_distance_v9.sql | 3 +++ sql/WAL/distance_wals_from_dir.sql | 12 ++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) delete mode 100644 sql/Checkpoints/.gitkeep create mode 100644 sql/Checkpoints/checkpoint_distance_v9.sql create mode 100644 sql/WAL/distance_wals_from_dir.sql diff --git a/sql/Checkpoints/.gitkeep b/sql/Checkpoints/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/sql/Checkpoints/checkpoint_distance.sql b/sql/Checkpoints/checkpoint_distance.sql index 12286cb..49df040 100644 --- a/sql/Checkpoints/checkpoint_distance.sql +++ b/sql/Checkpoints/checkpoint_distance.sql @@ -1,3 +1,2 @@ --- Given the current xlog location, it calculates the size of the current active WAL --- Source: https://www.cybertec-postgresql.com/en/checkpoint-distance-and-amount-of-wal/ -SELECT pg_size_pretty(pg_current_xlog_location() - '0/00000000'::pg_lsn); +-- Amount of generated WALS so far +SELECT pg_size_pretty(pg_current_wal_lsn() - '0/00000000'::pg_lsn); \ No newline at end of file diff --git a/sql/Checkpoints/checkpoint_distance_v9.sql b/sql/Checkpoints/checkpoint_distance_v9.sql new file mode 100644 index 0000000..12286cb --- /dev/null +++ b/sql/Checkpoints/checkpoint_distance_v9.sql @@ -0,0 +1,3 @@ +-- Given the current xlog location, it calculates the size of the current active WAL +-- Source: https://www.cybertec-postgresql.com/en/checkpoint-distance-and-amount-of-wal/ +SELECT pg_size_pretty(pg_current_xlog_location() - '0/00000000'::pg_lsn); diff --git a/sql/WAL/distance_wals_from_dir.sql b/sql/WAL/distance_wals_from_dir.sql new file mode 100644 index 0000000..5e33d15 --- /dev/null +++ b/sql/WAL/distance_wals_from_dir.sql @@ -0,0 +1,12 @@ +-- Current amount of WALs present in the waldir +WITH oldest_mod_walfile AS ( + SELECT (substring(name from 9 for 8) || '/' || substring(name from 17 for 8 ))::pg_lsn as oldest_lsn + FROM pg_ls_waldir() + ORDER BY modification DESC LIMIT 1 +) +SELECT pg_size_pretty(pg_wal_lsn_diff( pg_current_wal_lsn(),oldest_lsn)) +FROM oldest_mod_walfile; + + + +