pg_cheat_funcs

pg_cheat_funcs

pg_cheat_funcs : Provides cheat (but useful) functions

Overview

ID Extension Package Version Category License Language
5220
pg_cheat_funcs
pg_cheat_funcs
1.0
ADMIN
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--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

Type Repo Version PG Major Compatibility Package Pattern Dependencies
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 / PG PG18 PG17 PG16 PG15 PG14
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
Package Version OS ORG SIZE File URL
pg_cheat_funcs_18 1.0 el8.x86_64 pigsty 48.7 KiB pg_cheat_funcs_18-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_18 1.0 el8.aarch64 pigsty 48.2 KiB pg_cheat_funcs_18-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_18 1.0 el9.x86_64 pigsty 53.2 KiB pg_cheat_funcs_18-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_18 1.0 el9.aarch64 pigsty 53.0 KiB pg_cheat_funcs_18-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_18 1.0 el10.x86_64 pigsty 53.3 KiB pg_cheat_funcs_18-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_18 1.0 el10.aarch64 pigsty 53.3 KiB pg_cheat_funcs_18-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-cheat-funcs 1.0 d12.x86_64 pigsty 93.1 KiB postgresql-18-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-cheat-funcs 1.0 d12.aarch64 pigsty 92.3 KiB postgresql-18-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-cheat-funcs 1.0 d13.x86_64 pigsty 93.1 KiB postgresql-18-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-cheat-funcs 1.0 d13.aarch64 pigsty 92.2 KiB postgresql-18-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-cheat-funcs 1.0 u22.x86_64 pigsty 118.9 KiB postgresql-18-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-cheat-funcs 1.0 u22.aarch64 pigsty 118.1 KiB postgresql-18-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-cheat-funcs 1.0 u24.x86_64 pigsty 111.4 KiB postgresql-18-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-18-pg-cheat-funcs 1.0 u24.aarch64 pigsty 110.8 KiB postgresql-18-pg-cheat-funcs_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_cheat_funcs_17 1.0 el8.x86_64 pigsty 48.8 KiB pg_cheat_funcs_17-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_17 1.0 el8.aarch64 pigsty 48.2 KiB pg_cheat_funcs_17-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_17 1.0 el9.x86_64 pigsty 53.2 KiB pg_cheat_funcs_17-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_17 1.0 el9.aarch64 pigsty 53.2 KiB pg_cheat_funcs_17-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_17 1.0 el10.x86_64 pigsty 53.2 KiB pg_cheat_funcs_17-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_17 1.0 el10.aarch64 pigsty 53.3 KiB pg_cheat_funcs_17-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-cheat-funcs 1.0 d12.x86_64 pigsty 93.9 KiB postgresql-17-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-cheat-funcs 1.0 d12.aarch64 pigsty 93.1 KiB postgresql-17-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-cheat-funcs 1.0 d13.x86_64 pigsty 93.8 KiB postgresql-17-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-cheat-funcs 1.0 d13.aarch64 pigsty 93.1 KiB postgresql-17-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-cheat-funcs 1.0 u22.x86_64 pigsty 124.5 KiB postgresql-17-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-cheat-funcs 1.0 u22.aarch64 pigsty 123.9 KiB postgresql-17-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-cheat-funcs 1.0 u24.x86_64 pigsty 111.4 KiB postgresql-17-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-17-pg-cheat-funcs 1.0 u24.aarch64 pigsty 110.9 KiB postgresql-17-pg-cheat-funcs_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_cheat_funcs_16 1.0 el8.x86_64 pigsty 48.8 KiB pg_cheat_funcs_16-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_16 1.0 el8.aarch64 pigsty 48.2 KiB pg_cheat_funcs_16-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_16 1.0 el9.x86_64 pigsty 53.1 KiB pg_cheat_funcs_16-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_16 1.0 el9.aarch64 pigsty 53.3 KiB pg_cheat_funcs_16-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_16 1.0 el10.x86_64 pigsty 53.2 KiB pg_cheat_funcs_16-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_16 1.0 el10.aarch64 pigsty 53.4 KiB pg_cheat_funcs_16-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-cheat-funcs 1.0 d12.x86_64 pigsty 93.7 KiB postgresql-16-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-cheat-funcs 1.0 d12.aarch64 pigsty 93.1 KiB postgresql-16-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-cheat-funcs 1.0 d13.x86_64 pigsty 93.8 KiB postgresql-16-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-cheat-funcs 1.0 d13.aarch64 pigsty 93.1 KiB postgresql-16-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-cheat-funcs 1.0 u22.x86_64 pigsty 123.8 KiB postgresql-16-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-cheat-funcs 1.0 u22.aarch64 pigsty 123.1 KiB postgresql-16-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-cheat-funcs 1.0 u24.x86_64 pigsty 111.4 KiB postgresql-16-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-16-pg-cheat-funcs 1.0 u24.aarch64 pigsty 110.9 KiB postgresql-16-pg-cheat-funcs_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_cheat_funcs_15 1.0 el8.x86_64 pigsty 49.0 KiB pg_cheat_funcs_15-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_15 1.0 el8.aarch64 pigsty 48.5 KiB pg_cheat_funcs_15-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_15 1.0 el9.x86_64 pigsty 53.3 KiB pg_cheat_funcs_15-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_15 1.0 el9.aarch64 pigsty 53.6 KiB pg_cheat_funcs_15-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_15 1.0 el10.x86_64 pigsty 53.4 KiB pg_cheat_funcs_15-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_15 1.0 el10.aarch64 pigsty 53.6 KiB pg_cheat_funcs_15-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-cheat-funcs 1.0 d12.x86_64 pigsty 94.4 KiB postgresql-15-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-cheat-funcs 1.0 d12.aarch64 pigsty 93.7 KiB postgresql-15-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-cheat-funcs 1.0 d13.x86_64 pigsty 94.2 KiB postgresql-15-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-cheat-funcs 1.0 d13.aarch64 pigsty 93.5 KiB postgresql-15-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-cheat-funcs 1.0 u22.x86_64 pigsty 124.3 KiB postgresql-15-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-cheat-funcs 1.0 u22.aarch64 pigsty 124.1 KiB postgresql-15-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-cheat-funcs 1.0 u24.x86_64 pigsty 112.0 KiB postgresql-15-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-15-pg-cheat-funcs 1.0 u24.aarch64 pigsty 111.2 KiB postgresql-15-pg-cheat-funcs_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_cheat_funcs_14 1.0 el8.x86_64 pigsty 48.9 KiB pg_cheat_funcs_14-1.0-1PIGSTY.el8.x86_64.rpm
pg_cheat_funcs_14 1.0 el8.aarch64 pigsty 48.4 KiB pg_cheat_funcs_14-1.0-1PIGSTY.el8.aarch64.rpm
pg_cheat_funcs_14 1.0 el9.x86_64 pigsty 53.2 KiB pg_cheat_funcs_14-1.0-1PIGSTY.el9.x86_64.rpm
pg_cheat_funcs_14 1.0 el9.aarch64 pigsty 53.5 KiB pg_cheat_funcs_14-1.0-1PIGSTY.el9.aarch64.rpm
pg_cheat_funcs_14 1.0 el10.x86_64 pigsty 53.4 KiB pg_cheat_funcs_14-1.0-1PIGSTY.el10.x86_64.rpm
pg_cheat_funcs_14 1.0 el10.aarch64 pigsty 53.6 KiB pg_cheat_funcs_14-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-cheat-funcs 1.0 d12.x86_64 pigsty 93.4 KiB postgresql-14-pg-cheat-funcs_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-cheat-funcs 1.0 d12.aarch64 pigsty 92.6 KiB postgresql-14-pg-cheat-funcs_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-cheat-funcs 1.0 d13.x86_64 pigsty 93.2 KiB postgresql-14-pg-cheat-funcs_1.0-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-cheat-funcs 1.0 d13.aarch64 pigsty 92.5 KiB postgresql-14-pg-cheat-funcs_1.0-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-cheat-funcs 1.0 u22.x86_64 pigsty 124.6 KiB postgresql-14-pg-cheat-funcs_1.0-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-cheat-funcs 1.0 u22.aarch64 pigsty 123.7 KiB postgresql-14-pg-cheat-funcs_1.0-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-cheat-funcs 1.0 u24.x86_64 pigsty 111.8 KiB postgresql-14-pg-cheat-funcs_1.0-1PIGSTY~noble_amd64.deb
postgresql-14-pg-cheat-funcs 1.0 u24.aarch64 pigsty 110.9 KiB postgresql-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

Parameter Default Description
pg_cheat_funcs.log_memory_context off Log memory context stats after query execution
pg_cheat_funcs.hide_appname false Hide client application_name
pg_cheat_funcs.log_session_start_options off Log connection startup options
pg_cheat_funcs.scheduling_priority 0 Process scheduling priority (-20..19)
pg_cheat_funcs.exit_on_segv off If on, segfault terminates session only
Last updated on