pg_cheat_funcs

Provides cheat (but useful) functions

Overview

PackageVersionCategoryLicenseLanguage
pg_cheat_funcs1.0ADMINPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
5220pg_cheat_funcsNoYesNoYesNoYes-
Relatedpg_crash pg_snakeoil pg_dirtyread pg_savior pg_surgery adminpack pageinspect pg_repack

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.01817161514pg_cheat_funcs-
RPMPIGSTY1.01817161514pg_cheat_funcs_$v-
DEBPIGSTY1.01817161514postgresql-$v-pg-cheat-funcs-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el8.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0

Build

You can build the RPM / DEB packages for pg_cheat_funcs using pig build:

pig build pkg pg_cheat_funcs         # build RPM / DEB packages

Install

You can install pg_cheat_funcs directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_cheat_funcs;          # Install for current active PG version
pig ext install -y pg_cheat_funcs -v 18  # PG 18
pig ext install -y pg_cheat_funcs -v 17  # PG 17
pig ext install -y pg_cheat_funcs -v 16  # PG 16
pig ext install -y pg_cheat_funcs -v 15  # PG 15
pig ext install -y pg_cheat_funcs -v 14  # PG 14
dnf install -y pg_cheat_funcs_18       # PG 18
dnf install -y pg_cheat_funcs_17       # PG 17
dnf install -y pg_cheat_funcs_16       # PG 16
dnf install -y pg_cheat_funcs_15       # PG 15
dnf install -y pg_cheat_funcs_14       # PG 14
apt install -y postgresql-18-pg-cheat-funcs   # PG 18
apt install -y postgresql-17-pg-cheat-funcs   # PG 17
apt install -y postgresql-16-pg-cheat-funcs   # PG 16
apt install -y postgresql-15-pg-cheat-funcs   # PG 15
apt install -y postgresql-14-pg-cheat-funcs   # PG 14

Create Extension:

CREATE EXTENSION pg_cheat_funcs;

Usage

pg_cheat_funcs: Provides cheat (but useful) functions

The pg_cheat_funcs extension provides a collection of utility functions for debugging, diagnostics, and low-level PostgreSQL operations. Many are superuser-restricted.

Process Control

SELECT pg_signal_process(12345, 'TERM');       -- send signal to a PG process
SELECT pg_get_priority(pg_backend_pid());      -- get scheduling priority
SELECT pg_set_priority(pg_backend_pid(), 10);  -- set scheduling priority (-20..19)
SELECT pg_postmaster_pid();                    -- get postmaster PID
SELECT pg_backend_start_time();                -- server process start time

Memory Context Inspection

-- Show memory context statistics (PG 9.6-13)
SELECT * FROM pg_stat_get_memory_context();
-- Columns: name, parent, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes

Prepared Statement Inspection

-- Show cached plan info for a prepared statement
SELECT * FROM pg_cached_plan_source('my_stmt');
-- Columns: generic_cost, total_custom_cost, num_custom_plans, force_generic, force_custom

Transaction & WAL Functions

SELECT pg_xlogfile_name('0/1234568'::pg_lsn, false);  -- LSN to WAL filename
SELECT pg_wait_syncrep('0/1234568'::pg_lsn);           -- wait for sync rep
SELECT * FROM pg_stat_get_syncrep_waiters();            -- list sync rep waiters
SELECT pg_set_next_xid('100'::xid);                    -- set next transaction ID (dangerous)
SELECT * FROM pg_xid_assignment();                      -- XID state info

Checkpoint & Recovery

SELECT pg_checkpoint(true, true, true);  -- fast, wait, force
SELECT pg_promote(true);                 -- promote standby (PG <= 11)
SELECT * FROM pg_recovery_settings();    -- show recovery.conf parameters
SELECT pg_show_primary_conninfo();       -- show primary_conninfo

File Operations

SELECT * FROM pg_list_relation_filepath('my_table'::regclass);  -- list segment files
SELECT pg_file_write_binary('/tmp/test', '\x48656c6c6f'::bytea); -- write binary file
SELECT pg_file_fsync('/tmp/test');                                -- fsync file

Text & Encoding Conversion

SELECT to_octal(255);                   -- '377'
SELECT pg_text_to_hex('PostgreSQL');     -- '506f737467726553514c'
SELECT pg_hex_to_text('506f737467726553514c'); -- 'PostgreSQL'
SELECT pg_chr(9731);                     -- snowman character

Compression

SELECT pglz_compress('some text data');        -- PGLZ compress text to bytea
SELECT pglz_decompress(compressed_data);       -- decompress back to text
SELECT pglz_compress_bytea(data);              -- compress bytea
SELECT pglz_decompress_bytea(compressed_data); -- decompress to bytea

Advisory Lock Management

SELECT pg_advisory_xact_unlock(12345);              -- release exclusive advisory lock
SELECT pg_advisory_xact_unlock_shared(12345);       -- release shared advisory lock

GUC Parameters

ParameterDefaultDescription
pg_cheat_funcs.log_memory_contextoffLog memory context stats after query execution
pg_cheat_funcs.hide_appnamefalseHide client application_name
pg_cheat_funcs.log_session_start_optionsoffLog connection startup options
pg_cheat_funcs.scheduling_priority0Process scheduling priority (-20..19)
pg_cheat_funcs.exit_on_segvoffIf on, segfault terminates session only

Last Modified 2026-03-12: add pg extension catalog (95749bf)