pg_command_fw
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_command_fw | 0.1.0 | SEC | BSD-3-Clause | Rust |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7400 | pg_command_fw | No | Yes | Yes | Yes | No | No | - |
| Related | pgextwlist supautils block_copy_command pg_kpart noset sepgsql set_user pg_permissions pg_readonly pg_roast |
|---|
Requires shared_preload_libraries = pg_command_fw to activate hooks for all sessions.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.1.0 | 1817161514 | pg_command_fw | - |
| RPM | PIGSTY | 0.1.0 | 1817161514 | pg_command_fw_$v | - |
| DEB | PIGSTY | 0.1.0 | 1817161514 | postgresql-$v-pg-command-fw | - |
Build
You can build the RPM / DEB packages for pg_command_fw using pig build:
Install
You can install pg_command_fw directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Preload:
Create Extension:
Usage
- Source: README
pg_command_fw is a PostgreSQL command firewall. It intercepts DDL and utility commands through the ProcessUtility hook and blocks selected built-in file-reading functions through the post-parse analyze hook. Each command category is controlled by its own GUC.
Enable It
The extension must be preloaded:
Then enable it in the database:
Pigsty package metadata is version 0.1.0 for PostgreSQL 15-18 and notes that preloading is required to activate hooks for all sessions. The upstream README also documents PostgreSQL 15-18 support.
Command Categories
The upstream README documents these firewall categories:
TRUNCATE:pg_command_fw.block_truncate, defaulton, blocks non-superusers.DROP TABLE:pg_command_fw.block_drop_table, defaultoff, blocks non-superusers when enabled.ALTER SYSTEM:pg_command_fw.block_alter_system, defaulton, blocks everyone.LOAD:pg_command_fw.block_load, defaulton, blocks everyone.COPY ... PROGRAM:pg_command_fw.block_copy_program, defaulton, blocks everyone.- plain
COPY:pg_command_fw.block_copy, defaultoff, blocks non-superusers when enabled. pg_read_file(),pg_read_binary_file(), andpg_stat_file():pg_command_fw.block_read_file, defaulton, blocks everyone.
Some categories block only non-superusers, while others block everyone including superusers. Superusers are only exempt from non-superuser categories unless they are explicitly listed in pg_command_fw.blocked_roles.
Important GUCs
pg_command_fw.enabledto enable or disable all checkspg_command_fw.block_truncatepg_command_fw.block_drop_tablepg_command_fw.production_schemaspg_command_fw.block_alter_systempg_command_fw.block_loadpg_command_fw.block_copy_programpg_command_fw.block_copypg_command_fw.block_read_filepg_command_fw.blocked_rolespg_command_fw.hintpg_command_fw.audit_log_enabled
When production_schemas is set, DROP TABLE checks are limited to schema-qualified table names in those schemas; the README says unqualified names are not resolved through search_path.
Audit Log
The extension records intercepted commands in command_fw.audit_log. The README documents columns such as:
- timestamp
- session and current user names
- original query text
- command type
- target schema or object
- client address
- whether the command was blocked
- internal block reason
Blocked audit inserts are best-effort because the row is rolled back with the blocked transaction; use the PostgreSQL server log as the authoritative record for blocked events.
Examples
Block TRUNCATE and DROP TABLE in production schemas:
Block a specific role from any governed command:
Temporarily disable the firewall in a maintenance session:
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)