pg_cheat_funcs
Provides cheat (but useful) functions
Repository
MasaoFujii/pg_cheat_funcs
https://github.com/MasaoFujii/pg_cheat_funcs
Source
pg_cheat_funcs-1.0.tar.gz
pg_cheat_funcs-1.0.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_cheat_funcs | 1.0 | ADMIN | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 5220 | pg_cheat_funcs | No | Yes | No | Yes | No | Yes | - |
| Related | pg_crash pg_snakeoil pg_dirtyread pg_savior pg_surgery adminpack pageinspect pg_repack |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0 | 1817161514 | pg_cheat_funcs | - |
| RPM | PIGSTY | 1.0 | 1817161514 | pg_cheat_funcs_$v | - |
| DEB | PIGSTY | 1.0 | 1817161514 | postgresql-$v-pg-cheat-funcs | - |
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
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 |
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.