pgnice
pgnice · Manage PostgreSQL backend process priorities and resource limits.
Overview
PostgreSQL · 13, 14, 15, 16, 17
Usage
Sources:
pgnice 0.0.0 lets a session inspect and change operating-system scheduling and resource limits for its current PostgreSQL backend process. Use it to deprioritize selected workloads or constrain a dedicated pool of backends. The settings affect a process, not a transaction or database role.
Core Workflow
Create the extension, inspect the current backend, then apply only limits supported by the host OS and PostgreSQL service account:
set_backend_rlimit assigns the same value to both the soft and hard limit. Supported resource names vary by operating system and include common values such as cpu, data, fsize, nofile, nproc, rss, stack, and as.
Function Index
pgnice.get_backend_nice()andpgnice.set_backend_nice(integer)read or set CPU scheduling niceness.pgnice.get_backend_ionice()andpgnice.set_backend_ionice(char, integer)read or set I/O class and level; classes areR(real-time),B(best-effort), andI(idle).pgnice.get_backend_rlimit(text)returns the current soft and hard resource limit.pgnice.set_backend_rlimit(text, bigint)sets both resource limits for the backend.
Operational and Security Caveats
The kernel enforces privilege checks. An ordinary PostgreSQL service account can usually lower its priority or hard limits but cannot later raise them, so a setting may be irreversible for the lifetime of that backend. With session or transaction pooling, the modified process can be reused by another client; separate pools and initialize each pool’s backends explicitly. I/O priority support is Linux-specific, while resource names differ across platforms.
Changing limits such as address space, open files, CPU time, or process count can terminate or destabilize a backend. Revoke public execution and grant only the functions and values required by a controlled workload policy.