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
|
Source
pig build pkg pg_cheat_funcs; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create this extension with:
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 timeMemory 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_bytesPrepared 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_customTransaction & 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 infoCheckpoint & 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_conninfoFile 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 fileText & 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 characterCompression
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 byteaAdvisory Lock Management
SELECT pg_advisory_xact_unlock(12345); -- release exclusive advisory lock
SELECT pg_advisory_xact_unlock_shared(12345); -- release shared advisory lockGUC 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