pg_cheat_funcs

pg_cheat_funcs

pg_cheat_funcs : Provides cheat (but useful) functions

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
5220
pg_cheat_funcs
pg_cheat_funcs
1.0
ADMIN
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
pg_crash
pg_snakeoil
pg_dirtyread
pg_savior
pg_surgery
adminpack
pageinspect
pg_repack

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
1.0
18
17
16
15
14
pg_cheat_funcs-
RPM
PIGSTY
1.0
18
17
16
15
14
pg_cheat_funcs_$v-
DEB
PIGSTY
1.0
18
17
16
15
14
postgresql-$v-pg-cheat-funcs-
Linux / 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
PackageVersionOSORGSIZEFile URL
pg_cheat_funcs_181.0el8.x86_64pigsty48.7 KiBpg_cheat_funcs_18-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_181.0el8.aarch64pigsty48.2 KiBpg_cheat_funcs_18-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_181.0el9.x86_64pigsty53.2 KiBpg_cheat_funcs_18-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_181.0el9.aarch64pigsty53.0 KiBpg_cheat_funcs_18-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_181.0el10.x86_64pigsty53.3 KiBpg_cheat_funcs_18-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_181.0el10.aarch64pigsty53.3 KiBpg_cheat_funcs_18-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-cheat-funcs1.0d12.x86_64pigsty93.1 KiBpostgresql-18-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-cheat-funcs1.0d12.aarch64pigsty92.3 KiBpostgresql-18-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-cheat-funcs1.0d13.x86_64pigsty93.1 KiBpostgresql-18-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-cheat-funcs1.0d13.aarch64pigsty92.2 KiBpostgresql-18-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-cheat-funcs1.0u22.x86_64pigsty118.9 KiBpostgresql-18-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-cheat-funcs1.0u22.aarch64pigsty118.1 KiBpostgresql-18-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-cheat-funcs1.0u24.x86_64pigsty111.4 KiBpostgresql-18-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-18-pg-cheat-funcs1.0u24.aarch64pigsty110.8 KiBpostgresql-18-pg-cheat-funcs_1.0-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_cheat_funcs_171.0el8.x86_64pigsty48.8 KiBpg_cheat_funcs_17-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_171.0el8.aarch64pigsty48.2 KiBpg_cheat_funcs_17-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_171.0el9.x86_64pigsty53.2 KiBpg_cheat_funcs_17-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_171.0el9.aarch64pigsty53.2 KiBpg_cheat_funcs_17-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_171.0el10.x86_64pigsty53.2 KiBpg_cheat_funcs_17-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_171.0el10.aarch64pigsty53.3 KiBpg_cheat_funcs_17-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-cheat-funcs1.0d12.x86_64pigsty93.9 KiBpostgresql-17-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-cheat-funcs1.0d12.aarch64pigsty93.1 KiBpostgresql-17-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-cheat-funcs1.0d13.x86_64pigsty93.8 KiBpostgresql-17-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-cheat-funcs1.0d13.aarch64pigsty93.1 KiBpostgresql-17-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-cheat-funcs1.0u22.x86_64pigsty124.5 KiBpostgresql-17-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-cheat-funcs1.0u22.aarch64pigsty123.9 KiBpostgresql-17-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-cheat-funcs1.0u24.x86_64pigsty111.4 KiBpostgresql-17-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-17-pg-cheat-funcs1.0u24.aarch64pigsty110.9 KiBpostgresql-17-pg-cheat-funcs_1.0-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_cheat_funcs_161.0el8.x86_64pigsty48.8 KiBpg_cheat_funcs_16-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_161.0el8.aarch64pigsty48.2 KiBpg_cheat_funcs_16-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_161.0el9.x86_64pigsty53.1 KiBpg_cheat_funcs_16-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_161.0el9.aarch64pigsty53.3 KiBpg_cheat_funcs_16-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_161.0el10.x86_64pigsty53.2 KiBpg_cheat_funcs_16-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_161.0el10.aarch64pigsty53.4 KiBpg_cheat_funcs_16-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-cheat-funcs1.0d12.x86_64pigsty93.7 KiBpostgresql-16-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-cheat-funcs1.0d12.aarch64pigsty93.1 KiBpostgresql-16-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-cheat-funcs1.0d13.x86_64pigsty93.8 KiBpostgresql-16-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-cheat-funcs1.0d13.aarch64pigsty93.1 KiBpostgresql-16-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-cheat-funcs1.0u22.x86_64pigsty123.8 KiBpostgresql-16-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-cheat-funcs1.0u22.aarch64pigsty123.1 KiBpostgresql-16-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-cheat-funcs1.0u24.x86_64pigsty111.4 KiBpostgresql-16-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-16-pg-cheat-funcs1.0u24.aarch64pigsty110.9 KiBpostgresql-16-pg-cheat-funcs_1.0-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_cheat_funcs_151.0el8.x86_64pigsty49.0 KiBpg_cheat_funcs_15-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_151.0el8.aarch64pigsty48.5 KiBpg_cheat_funcs_15-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_151.0el9.x86_64pigsty53.3 KiBpg_cheat_funcs_15-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_151.0el9.aarch64pigsty53.6 KiBpg_cheat_funcs_15-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_151.0el10.x86_64pigsty53.4 KiBpg_cheat_funcs_15-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_151.0el10.aarch64pigsty53.6 KiBpg_cheat_funcs_15-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-cheat-funcs1.0d12.x86_64pigsty94.4 KiBpostgresql-15-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-cheat-funcs1.0d12.aarch64pigsty93.7 KiBpostgresql-15-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-cheat-funcs1.0d13.x86_64pigsty94.2 KiBpostgresql-15-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-cheat-funcs1.0d13.aarch64pigsty93.5 KiBpostgresql-15-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-cheat-funcs1.0u22.x86_64pigsty124.3 KiBpostgresql-15-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-cheat-funcs1.0u22.aarch64pigsty124.1 KiBpostgresql-15-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-cheat-funcs1.0u24.x86_64pigsty112.0 KiBpostgresql-15-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-15-pg-cheat-funcs1.0u24.aarch64pigsty111.2 KiBpostgresql-15-pg-cheat-funcs_1.0-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_cheat_funcs_141.0el8.x86_64pigsty48.9 KiBpg_cheat_funcs_14-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_141.0el8.aarch64pigsty48.4 KiBpg_cheat_funcs_14-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_141.0el9.x86_64pigsty53.2 KiBpg_cheat_funcs_14-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_141.0el9.aarch64pigsty53.5 KiBpg_cheat_funcs_14-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_141.0el10.x86_64pigsty53.4 KiBpg_cheat_funcs_14-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_141.0el10.aarch64pigsty53.6 KiBpg_cheat_funcs_14-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-cheat-funcs1.0d12.x86_64pigsty93.4 KiBpostgresql-14-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-cheat-funcs1.0d12.aarch64pigsty92.6 KiBpostgresql-14-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-cheat-funcs1.0d13.x86_64pigsty93.2 KiBpostgresql-14-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-cheat-funcs1.0d13.aarch64pigsty92.5 KiBpostgresql-14-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-cheat-funcs1.0u22.x86_64pigsty124.6 KiBpostgresql-14-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-cheat-funcs1.0u22.aarch64pigsty123.7 KiBpostgresql-14-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-cheat-funcs1.0u24.x86_64pigsty111.8 KiBpostgresql-14-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-14-pg-cheat-funcs1.0u24.aarch64pigsty110.9 KiBpostgresql-14-pg-cheat-funcs_1.0-1PIGSTY~noble_arm64.deb

Source

pig build pkg pg_cheat_funcs;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_cheat_funcs;		# install via package name, for the active PG version

pig install pg_cheat_funcs -v 18;   # install for PG 18
pig install pg_cheat_funcs -v 17;   # install for PG 17
pig install pg_cheat_funcs -v 16;   # install for PG 16
pig install pg_cheat_funcs -v 15;   # install for PG 15
pig install pg_cheat_funcs -v 14;   # install for PG 14

Create this extension with:

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 updated on