Skip to content

Instantly share code, notes, and snippets.

View cevian's full-sized avatar

Matvey Arye cevian

View GitHub Profile
@cevian
cevian / info_vacuum_queries.sql
Last active November 23, 2022 21:10
info_vacuum_queries.sql
\pset pager off
\set ECHO all
\set ON_ERROR_STOP 0
select version();
\dx
select now();
\x off
SELECT datname,
@cevian
cevian / info_ha_queries.sql
Last active November 23, 2022 21:10
info_ha_queries.sql
\pset pager off
\set ECHO all
\set ON_ERROR_STOP 0
select version();
\dx
select now()
\x off
select * from _prom_catalog.ha_leases
@cevian
cevian / exec_vacuum.sql
Last active November 23, 2022 21:10
exec_vacuum.sql
\timing on
with info as (
SELECT
stat.relid as relid,
stat.relid::regclass as regclass,
age(c.relfrozenxid) > current_setting('vacuum_freeze_min_age')::int
and age(c.relfrozenxid) > current_setting('vacuum_freeze_table_age')::int autovacuum_can_freeze,
ROUND(100*(age(c.relfrozenxid)/current_setting('vacuum_freeze_table_age')::float)) as perc_to_frozen,
ROUND(100*(age(c.relfrozenxid)/ current_setting('autovacuum_freeze_max_age')::float)) perc_to_wrap,
CASE WHEN c.reltuples > 0 THEN
@cevian
cevian / info_disk_space_queries.sql
Last active November 23, 2022 21:09
info_disk_space_queries.sql
\pset pager off
\set ECHO all
\set ON_ERROR_STOP 0
select version();
\dx
select now();
--sanity_check: avg_not_yet_compressed_chunks is < 2
\x on
@cevian
cevian / uuid.sql
Last active August 30, 2023 19:36
uuids
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
CREATE OR REPLACE FUNCTION uuid_timestamp(uuid UUID) RETURNS TIMESTAMPTZ AS $$
DECLARE
bytes bytea;
BEGIN
bytes := uuid_send(uuid);
if (get_byte(bytes, 6) >> 4)::int2 != 1 then
RAISE EXCEPTION 'UUID version is not 1';