pg_strict
pg_strict
pg_strict : Prevent dangerous UPDATE and DELETE without WHERE clause
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5830 | pg_strict
|
pg_strict
|
1.0.5 |
ADMIN
|
MIT
|
Rust
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--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 upgraded PGRX from 0.16.1 to 0.17.0 by Vonng
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
1.0.5 |
18
17
16
15
14
|
pg_strict |
- |
| RPM | PIGSTY
|
1.0.5 |
18
17
16
15
14
|
pg_strict_$v |
- |
| DEB | PIGSTY
|
1.0.5 |
18
17
16
15
14
|
postgresql-$v-pg-strict |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
el8.aarch64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
el9.x86_64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
el9.aarch64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
el10.x86_64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
el10.aarch64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
d12.x86_64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
d12.aarch64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
d13.x86_64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
d13.aarch64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
u22.x86_64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
u22.aarch64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
u24.x86_64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
u24.aarch64
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
PIGSTY 1.0.5
|
Source
pig build pkg pg_strict; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Config 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
| Parameter | Modes | Description |
|---|---|---|
pg_strict.require_where_on_update |
on/warn/off |
Enforce WHERE on UPDATE |
pg_strict.require_where_on_delete |
on/warn/off |
Enforce WHERE on DELETE |
on: Reject statements without WHERE (raises error)warn: Allow but emit a warning logoff: 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