non_truncate
non_truncate · Disables TRUNCATE by raising an error from a ProcessUtility hook
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100166 | non_truncate | non_truncate | 1.0 | ADMIN | Unknown | C |
PostgreSQL · 13, 14, 15, 16, 17, 18
Usage
Sources:
non_truncate 1.0 installs a PostgreSQL utility hook that rejects every TRUNCATE statement with an error. It declares support for PostgreSQL 13 or later and must be loaded at server start.
Load and register the extension
Add the library to shared_preload_libraries and restart PostgreSQL:
Then register the extension in databases where its presence should be visible in the extension catalog:
Cluster-wide effect
The blocking behavior starts when the shared library is preloaded, not when CREATE EXTENSION runs. Because shared_preload_libraries is cluster-wide, the hook also affects databases that do not contain an extension catalog entry. The version installation SQL creates no callable SQL object.
The hook rejects all TRUNCATE forms without an allowlist, role exemption, table exemption, or session switch. It does not prevent equivalent data removal with DELETE, table replacement, or other DDL, so it is a narrow guardrail rather than an authorization policy. Test hook chaining with every other utility-hook extension before deployment and keep a restart procedure for disabling it.