pg_strict

pg_strict

pg_strict : Prevent dangerous UPDATE and DELETE without WHERE clause

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
5830
pg_strict
pg_strict
1.0.2
ADMIN
MIT
Rust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--
No
Yes
Yes
Yes
no
no
Relationships
See Also
safeupdate
pg_savior
pg_upless
pg_drop_events
pg_readonly
table_log
pgaudit
pg_permissions

manually patched

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
1.0.2
18
17
16
15
14
pg_strict-
RPM
PIGSTY
1.0.2
18
17
16
15
14
pg_strict_$v-
DEB
PIGSTY
1.0.2
18
17
16
15
14
pg_strict_$v-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
el8.aarch64
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
el9.x86_64
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
el9.aarch64
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
el10.x86_64
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
el10.aarch64
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
PIGSTY 1.0.2
d12.x86_64
MISS
MISS
MISS
MISS
MISS
d12.aarch64
MISS
MISS
MISS
MISS
MISS
d13.x86_64
MISS
MISS
MISS
MISS
MISS
d13.aarch64
MISS
MISS
MISS
MISS
MISS
u22.x86_64
MISS
MISS
MISS
MISS
MISS
u22.aarch64
MISS
MISS
MISS
MISS
MISS
u24.x86_64
MISS
MISS
MISS
MISS
MISS
u24.aarch64
MISS
MISS
MISS
MISS
MISS
PackageVersionOSORGSIZEFile URL
pg_strict_181.0.2el8.x86_64pigsty324.1 KiBpg_strict_18-1.0.2-1PIGSTY.el8.x86_64.rpm
pg_strict_181.0.2el8.aarch64pigsty217.9 KiBpg_strict_18-1.0.2-1PIGSTY.el8.aarch64.rpm
pg_strict_181.0.2el9.x86_64pigsty338.9 KiBpg_strict_18-1.0.2-1PIGSTY.el9.x86_64.rpm
pg_strict_181.0.2el9.aarch64pigsty232.5 KiBpg_strict_18-1.0.2-1PIGSTY.el9.aarch64.rpm
pg_strict_181.0.2el10.x86_64pigsty339.1 KiBpg_strict_18-1.0.2-1PIGSTY.el10.x86_64.rpm
pg_strict_181.0.2el10.aarch64pigsty232.6 KiBpg_strict_18-1.0.2-1PIGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
pg_strict_171.0.2el8.x86_64pigsty324.4 KiBpg_strict_17-1.0.2-1PIGSTY.el8.x86_64.rpm
pg_strict_171.0.2el8.aarch64pigsty217.8 KiBpg_strict_17-1.0.2-1PIGSTY.el8.aarch64.rpm
pg_strict_171.0.2el9.x86_64pigsty339.0 KiBpg_strict_17-1.0.2-1PIGSTY.el9.x86_64.rpm
pg_strict_171.0.2el9.aarch64pigsty232.8 KiBpg_strict_17-1.0.2-1PIGSTY.el9.aarch64.rpm
pg_strict_171.0.2el10.x86_64pigsty339.3 KiBpg_strict_17-1.0.2-1PIGSTY.el10.x86_64.rpm
pg_strict_171.0.2el10.aarch64pigsty232.3 KiBpg_strict_17-1.0.2-1PIGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
pg_strict_161.0.2el8.x86_64pigsty324.5 KiBpg_strict_16-1.0.2-1PIGSTY.el8.x86_64.rpm
pg_strict_161.0.2el8.aarch64pigsty217.8 KiBpg_strict_16-1.0.2-1PIGSTY.el8.aarch64.rpm
pg_strict_161.0.2el9.x86_64pigsty339.1 KiBpg_strict_16-1.0.2-1PIGSTY.el9.x86_64.rpm
pg_strict_161.0.2el9.aarch64pigsty232.8 KiBpg_strict_16-1.0.2-1PIGSTY.el9.aarch64.rpm
pg_strict_161.0.2el10.x86_64pigsty339.2 KiBpg_strict_16-1.0.2-1PIGSTY.el10.x86_64.rpm
pg_strict_161.0.2el10.aarch64pigsty232.7 KiBpg_strict_16-1.0.2-1PIGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
pg_strict_151.0.2el8.x86_64pigsty323.7 KiBpg_strict_15-1.0.2-1PIGSTY.el8.x86_64.rpm
pg_strict_151.0.2el8.aarch64pigsty217.8 KiBpg_strict_15-1.0.2-1PIGSTY.el8.aarch64.rpm
pg_strict_151.0.2el9.x86_64pigsty338.9 KiBpg_strict_15-1.0.2-1PIGSTY.el9.x86_64.rpm
pg_strict_151.0.2el9.aarch64pigsty232.8 KiBpg_strict_15-1.0.2-1PIGSTY.el9.aarch64.rpm
pg_strict_151.0.2el10.x86_64pigsty339.2 KiBpg_strict_15-1.0.2-1PIGSTY.el10.x86_64.rpm
pg_strict_151.0.2el10.aarch64pigsty232.4 KiBpg_strict_15-1.0.2-1PIGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
pg_strict_141.0.2el8.x86_64pigsty323.8 KiBpg_strict_14-1.0.2-1PIGSTY.el8.x86_64.rpm
pg_strict_141.0.2el8.aarch64pigsty217.8 KiBpg_strict_14-1.0.2-1PIGSTY.el8.aarch64.rpm
pg_strict_141.0.2el9.x86_64pigsty338.6 KiBpg_strict_14-1.0.2-1PIGSTY.el9.x86_64.rpm
pg_strict_141.0.2el9.aarch64pigsty232.7 KiBpg_strict_14-1.0.2-1PIGSTY.el9.aarch64.rpm
pg_strict_141.0.2el10.x86_64pigsty338.8 KiBpg_strict_14-1.0.2-1PIGSTY.el10.x86_64.rpm
pg_strict_141.0.2el10.aarch64pigsty232.7 KiBpg_strict_14-1.0.2-1PIGSTY.el10.aarch64.rpm

Source

pig build pkg pg_strict;		# 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_strict;		# install via package name, for the active PG version

pig install pg_strict -v 18;   # install for PG 18
pig install pg_strict -v 17;   # install for PG 17
pig install pg_strict -v 16;   # install for PG 16
pig install pg_strict -v 15;   # install for PG 15
pig install pg_strict -v 14;   # install for PG 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_strict';

Create this extension with:

CREATE EXTENSION pg_strict;

Usage

pg_strict: Prevent dangerous UPDATE and DELETE without WHERE clause

The pg_strict extension blocks UPDATE and DELETE statements that lack a WHERE clause. It operates at the parse/analyze stage via post_parse_analyze_hook, providing three enforcement modes per statement type.

Configuration Parameters

ParameterModesDescription
pg_strict.require_where_on_updateon/warn/offEnforce WHERE on UPDATE
pg_strict.require_where_on_deleteon/warn/offEnforce WHERE on DELETE
  • on: Reject statements without WHERE (raises error)
  • warn: Allow but emit a warning log
  • off: Standard PostgreSQL behavior

Session-Level Configuration

SET pg_strict.require_where_on_update = 'on';
SET pg_strict.require_where_on_delete = 'warn';

Persistent Configuration

ALTER DATABASE postgres SET pg_strict.require_where_on_update = 'on';
ALTER ROLE app_service SET pg_strict.require_where_on_delete = 'on';
ALTER ROLE dba_admin SET pg_strict.require_where_on_update = 'off';

Transactional Override

BEGIN;
SET LOCAL pg_strict.require_where_on_delete = 'off';
DELETE FROM temp_table;  -- allowed within this transaction
COMMIT;

API Functions

SELECT pg_strict_version();           -- extension version
SELECT pg_strict_config();            -- all settings with values and descriptions

-- Validate queries programmatically
SELECT pg_strict_check_where_clause('DELETE FROM t', 'DELETE');  -- returns boolean
SELECT pg_strict_validate_update('UPDATE t SET x=1');
SELECT pg_strict_validate_delete('DELETE FROM t');

-- Quick mode toggles
SELECT pg_strict_enable_update();     -- set update enforcement to 'on'
SELECT pg_strict_warn_delete();       -- set delete enforcement to 'warn'
SELECT pg_strict_disable_update();    -- set update enforcement to 'off'

Any non-null WHERE condition is accepted (including WHERE false). CTE statements are supported.

Last updated on