Skip to content

pg_command_fw

DDL and utility command firewall for PostgreSQL

pg_command_fw · DDL and utility command firewall for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
7400pg_command_fwpg_command_fw0.1.0SECBSD-3-ClauseRust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Requires shared_preload_libraries = pg_command_fw to activate hooks for all sessions.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY0.1.019 18 17 16 15pg_command_fw-
RPMPIGSTY0.1.019 18 17 16 15pg_command_fw_$v-
DEBPIGSTY0.1.019 18 17 16 15postgresql-$v-pg-command-fw-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el8.aarch64N/APIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el9.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el9.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el10.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el10.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d12.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d12.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d13.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d13.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u22.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u22.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u24.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u24.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u26.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u26.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
PackageVersionOSORGSIZEFile URL
pg_command_fw_190.1.0el9.x86_64pigsty890.0 KiBpg_command_fw_19-0.1.0-4PGSTY.el9.x86_64.rpm
pg_command_fw_190.1.0el9.aarch64pigsty859.5 KiBpg_command_fw_19-0.1.0-4PGSTY.el9.aarch64.rpm
pg_command_fw_190.1.0el10.x86_64pigsty890.5 KiBpg_command_fw_19-0.1.0-4PGSTY.el10.x86_64.rpm
pg_command_fw_190.1.0el10.aarch64pigsty859.6 KiBpg_command_fw_19-0.1.0-4PGSTY.el10.aarch64.rpm
postgresql-19-pg-command-fw0.1.0d12.x86_64pigsty599.0 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~bookworm_amd64.deb
postgresql-19-pg-command-fw0.1.0d12.aarch64pigsty522.5 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~bookworm_arm64.deb
postgresql-19-pg-command-fw0.1.0d13.x86_64pigsty599.6 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~trixie_amd64.deb
postgresql-19-pg-command-fw0.1.0d13.aarch64pigsty523.5 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~trixie_arm64.deb
postgresql-19-pg-command-fw0.1.0u22.x86_64pigsty666.3 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~jammy_amd64.deb
postgresql-19-pg-command-fw0.1.0u22.aarch64pigsty618.6 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~jammy_arm64.deb
postgresql-19-pg-command-fw0.1.0u24.x86_64pigsty658.6 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~noble_amd64.deb
postgresql-19-pg-command-fw0.1.0u24.aarch64pigsty611.9 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~noble_arm64.deb
postgresql-19-pg-command-fw0.1.0u26.x86_64pigsty655.9 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~resolute_amd64.deb
postgresql-19-pg-command-fw0.1.0u26.aarch64pigsty610.3 KiBpostgresql-19-pg-command-fw_0.1.0-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_command_fw_180.1.0el8.x86_64pigsty864.7 KiBpg_command_fw_18-0.1.0-3PIGSTY.el8.x86_64.rpm
pg_command_fw_180.1.0el8.aarch64pigsty775.1 KiBpg_command_fw_18-0.1.0-3PIGSTY.el8.aarch64.rpm
pg_command_fw_180.1.0el9.x86_64pigsty885.7 KiBpg_command_fw_18-0.1.0-4PGSTY.el9.x86_64.rpm
pg_command_fw_180.1.0el9.aarch64pigsty853.2 KiBpg_command_fw_18-0.1.0-4PGSTY.el9.aarch64.rpm
pg_command_fw_180.1.0el10.x86_64pigsty885.1 KiBpg_command_fw_18-0.1.0-4PGSTY.el10.x86_64.rpm
pg_command_fw_180.1.0el10.aarch64pigsty856.6 KiBpg_command_fw_18-0.1.0-4PGSTY.el10.aarch64.rpm
postgresql-18-pg-command-fw0.1.0d12.x86_64pigsty597.8 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~bookworm_amd64.deb
postgresql-18-pg-command-fw0.1.0d12.aarch64pigsty521.1 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~bookworm_arm64.deb
postgresql-18-pg-command-fw0.1.0d13.x86_64pigsty596.9 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~trixie_amd64.deb
postgresql-18-pg-command-fw0.1.0d13.aarch64pigsty521.6 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~trixie_arm64.deb
postgresql-18-pg-command-fw0.1.0u22.x86_64pigsty664.4 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~jammy_amd64.deb
postgresql-18-pg-command-fw0.1.0u22.aarch64pigsty617.2 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~jammy_arm64.deb
postgresql-18-pg-command-fw0.1.0u24.x86_64pigsty655.2 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~noble_amd64.deb
postgresql-18-pg-command-fw0.1.0u24.aarch64pigsty609.8 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~noble_arm64.deb
postgresql-18-pg-command-fw0.1.0u26.x86_64pigsty653.1 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~resolute_amd64.deb
postgresql-18-pg-command-fw0.1.0u26.aarch64pigsty607.8 KiBpostgresql-18-pg-command-fw_0.1.0-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_command_fw_170.1.0el8.x86_64pigsty861.5 KiBpg_command_fw_17-0.1.0-3PIGSTY.el8.x86_64.rpm
pg_command_fw_170.1.0el8.aarch64pigsty772.7 KiBpg_command_fw_17-0.1.0-3PIGSTY.el8.aarch64.rpm
pg_command_fw_170.1.0el9.x86_64pigsty880.1 KiBpg_command_fw_17-0.1.0-4PGSTY.el9.x86_64.rpm
pg_command_fw_170.1.0el9.aarch64pigsty848.6 KiBpg_command_fw_17-0.1.0-4PGSTY.el9.aarch64.rpm
pg_command_fw_170.1.0el10.x86_64pigsty881.3 KiBpg_command_fw_17-0.1.0-4PGSTY.el10.x86_64.rpm
pg_command_fw_170.1.0el10.aarch64pigsty851.3 KiBpg_command_fw_17-0.1.0-4PGSTY.el10.aarch64.rpm
postgresql-17-pg-command-fw0.1.0d12.x86_64pigsty594.5 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~bookworm_amd64.deb
postgresql-17-pg-command-fw0.1.0d12.aarch64pigsty520.3 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~bookworm_arm64.deb
postgresql-17-pg-command-fw0.1.0d13.x86_64pigsty594.3 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~trixie_amd64.deb
postgresql-17-pg-command-fw0.1.0d13.aarch64pigsty520.2 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~trixie_arm64.deb
postgresql-17-pg-command-fw0.1.0u22.x86_64pigsty661.6 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~jammy_amd64.deb
postgresql-17-pg-command-fw0.1.0u22.aarch64pigsty614.8 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~jammy_arm64.deb
postgresql-17-pg-command-fw0.1.0u24.x86_64pigsty653.3 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~noble_amd64.deb
postgresql-17-pg-command-fw0.1.0u24.aarch64pigsty606.8 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~noble_arm64.deb
postgresql-17-pg-command-fw0.1.0u26.x86_64pigsty650.4 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~resolute_amd64.deb
postgresql-17-pg-command-fw0.1.0u26.aarch64pigsty604.6 KiBpostgresql-17-pg-command-fw_0.1.0-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_command_fw_160.1.0el8.x86_64pigsty861.0 KiBpg_command_fw_16-0.1.0-3PIGSTY.el8.x86_64.rpm
pg_command_fw_160.1.0el8.aarch64pigsty770.9 KiBpg_command_fw_16-0.1.0-3PIGSTY.el8.aarch64.rpm
pg_command_fw_160.1.0el9.x86_64pigsty879.3 KiBpg_command_fw_16-0.1.0-4PGSTY.el9.x86_64.rpm
pg_command_fw_160.1.0el9.aarch64pigsty846.5 KiBpg_command_fw_16-0.1.0-4PGSTY.el9.aarch64.rpm
pg_command_fw_160.1.0el10.x86_64pigsty879.3 KiBpg_command_fw_16-0.1.0-4PGSTY.el10.x86_64.rpm
pg_command_fw_160.1.0el10.aarch64pigsty847.5 KiBpg_command_fw_16-0.1.0-4PGSTY.el10.aarch64.rpm
postgresql-16-pg-command-fw0.1.0d12.x86_64pigsty593.6 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~bookworm_amd64.deb
postgresql-16-pg-command-fw0.1.0d12.aarch64pigsty519.6 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~bookworm_arm64.deb
postgresql-16-pg-command-fw0.1.0d13.x86_64pigsty593.3 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~trixie_amd64.deb
postgresql-16-pg-command-fw0.1.0d13.aarch64pigsty519.1 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~trixie_arm64.deb
postgresql-16-pg-command-fw0.1.0u22.x86_64pigsty661.7 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~jammy_amd64.deb
postgresql-16-pg-command-fw0.1.0u22.aarch64pigsty613.5 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~jammy_arm64.deb
postgresql-16-pg-command-fw0.1.0u24.x86_64pigsty655.0 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~noble_amd64.deb
postgresql-16-pg-command-fw0.1.0u24.aarch64pigsty605.6 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~noble_arm64.deb
postgresql-16-pg-command-fw0.1.0u26.x86_64pigsty649.1 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~resolute_amd64.deb
postgresql-16-pg-command-fw0.1.0u26.aarch64pigsty603.7 KiBpostgresql-16-pg-command-fw_0.1.0-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_command_fw_150.1.0el8.x86_64pigsty849.0 KiBpg_command_fw_15-0.1.0-3PIGSTY.el8.x86_64.rpm
pg_command_fw_150.1.0el8.aarch64pigsty760.1 KiBpg_command_fw_15-0.1.0-3PIGSTY.el8.aarch64.rpm
pg_command_fw_150.1.0el9.x86_64pigsty871.9 KiBpg_command_fw_15-0.1.0-4PGSTY.el9.x86_64.rpm
pg_command_fw_150.1.0el9.aarch64pigsty840.4 KiBpg_command_fw_15-0.1.0-4PGSTY.el9.aarch64.rpm
pg_command_fw_150.1.0el10.x86_64pigsty871.6 KiBpg_command_fw_15-0.1.0-4PGSTY.el10.x86_64.rpm
pg_command_fw_150.1.0el10.aarch64pigsty840.6 KiBpg_command_fw_15-0.1.0-4PGSTY.el10.aarch64.rpm
postgresql-15-pg-command-fw0.1.0d12.x86_64pigsty590.4 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~bookworm_amd64.deb
postgresql-15-pg-command-fw0.1.0d12.aarch64pigsty516.7 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~bookworm_arm64.deb
postgresql-15-pg-command-fw0.1.0d13.x86_64pigsty590.1 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~trixie_amd64.deb
postgresql-15-pg-command-fw0.1.0d13.aarch64pigsty516.3 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~trixie_arm64.deb
postgresql-15-pg-command-fw0.1.0u22.x86_64pigsty657.5 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~jammy_amd64.deb
postgresql-15-pg-command-fw0.1.0u22.aarch64pigsty610.8 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~jammy_arm64.deb
postgresql-15-pg-command-fw0.1.0u24.x86_64pigsty647.6 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~noble_amd64.deb
postgresql-15-pg-command-fw0.1.0u24.aarch64pigsty602.0 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~noble_arm64.deb
postgresql-15-pg-command-fw0.1.0u26.x86_64pigsty645.2 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~resolute_amd64.deb
postgresql-15-pg-command-fw0.1.0u26.aarch64pigsty600.2 KiBpostgresql-15-pg-command-fw_0.1.0-4PGSTY~resolute_arm64.deb

Source

pig build pkg pg_command_fw;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_command_fw;		# install by package name

pig install pg_command_fw -v 19;   # install for PG 19
pig install pg_command_fw -v 18;   # install for PG 18
pig install pg_command_fw -v 17;   # install for PG 17
pig install pg_command_fw -v 16;   # install for PG 16
pig install pg_command_fw -v 15;   # install for PG 15

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_command_fw';

Create this extension with:

CREATE EXTENSION pg_command_fw;

Usage

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:

shared_preload_libraries = 'pg_command_fw'

Then enable it in the database:

CREATE EXTENSION pg_command_fw;

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, default on, blocks non-superusers.
  • DROP TABLE: pg_command_fw.block_drop_table, default off, blocks non-superusers when enabled.
  • ALTER SYSTEM: pg_command_fw.block_alter_system, default on, blocks everyone.
  • LOAD: pg_command_fw.block_load, default on, blocks everyone.
  • COPY ... PROGRAM: pg_command_fw.block_copy_program, default on, blocks everyone.
  • plain COPY: pg_command_fw.block_copy, default off, blocks non-superusers when enabled.
  • pg_read_file(), pg_read_binary_file(), and pg_stat_file(): pg_command_fw.block_read_file, default on, 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.enabled to enable or disable all checks
  • pg_command_fw.block_truncate
  • pg_command_fw.block_drop_table
  • pg_command_fw.production_schemas
  • pg_command_fw.block_alter_system
  • pg_command_fw.block_load
  • pg_command_fw.block_copy_program
  • pg_command_fw.block_copy
  • pg_command_fw.block_read_file
  • pg_command_fw.blocked_roles
  • pg_command_fw.hint
  • pg_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:

ALTER SYSTEM SET pg_command_fw.block_truncate = on;
ALTER SYSTEM SET pg_command_fw.block_drop_table = on;
ALTER SYSTEM SET pg_command_fw.production_schemas = 'public,payments';
ALTER SYSTEM SET pg_command_fw.hint = 'Contact your DBA to request access';
SELECT pg_reload_conf();

Block a specific role from any governed command:

ALTER SYSTEM SET pg_command_fw.blocked_roles = 'app_deploy';
SELECT pg_reload_conf();

Temporarily disable the firewall in a maintenance session:

SET pg_command_fw.enabled = off;
TRUNCATE big_table;
SET pg_command_fw.enabled = on;

Table reader