safeupdate
safeupdate
safeupdate : Require criteria for UPDATE and DELETE
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5820 | safeupdate
|
safeupdate
|
1.5 |
ADMIN
|
ISC
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sL---
|
No
|
Yes
|
Yes
|
No
|
no
|
no
|
| Relationships | |
|---|---|
| See Also | pg_readonly
pg_upless
pg_savior
pg_permissions
pgaudit
set_user
login_hook
noset
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG
|
1.5 |
18
17
16
15
14
|
safeupdate |
- |
| RPM | PGDG
|
1.5 |
18
17
16
15
14
|
safeupdate_$v |
- |
| DEB | PIGSTY
|
1.5 |
18
17
16
15
14
|
postgresql-$v-pg-safeupdate |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
el8.aarch64
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
el9.x86_64
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
el9.aarch64
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
el10.x86_64
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
el10.aarch64
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
PGDG 1.5
|
d12.x86_64
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
d12.aarch64
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
d13.x86_64
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
d13.aarch64
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
u22.x86_64
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
u22.aarch64
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
u24.x86_64
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
u24.aarch64
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
PIGSTY 1.5
|
Source
pig build pkg safeupdate; # build debInstall
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install safeupdate; # install via package name, for the active PG version
pig install safeupdate -v 18; # install for PG 18
pig install safeupdate -v 17; # install for PG 17
pig install safeupdate -v 16; # install for PG 16
pig install safeupdate -v 15; # install for PG 15
pig install safeupdate -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'safeupdate';This extension does not need CREATE EXTENSION DDL command
Usage
The safeupdate extension prevents accidental mass data changes by raising an error whenever UPDATE or DELETE statements are executed without a WHERE clause.
Activation
-- Per-session
LOAD 'safeupdate';
-- Per-database (persistent)
ALTER DATABASE mydb SET session_preload_libraries = 'safeupdate';
-- Global (all databases, requires restart)
-- shared_preload_libraries = 'safeupdate' -- in postgresql.confBehavior
-- Blocked: UPDATE without WHERE
UPDATE rack SET fan_speed = 70;
-- ERROR: UPDATE requires a WHERE clause
-- Blocked: DELETE without WHERE
DELETE FROM rack;
-- ERROR: DELETE requires a WHERE clause
-- Allowed: with WHERE clause
UPDATE rack SET fan_speed = 90 WHERE fan_speed = 70;
-- Workaround: explicit always-true condition
UPDATE rack SET fan_speed = 90 WHERE 1 = 1;Administrative Override
-- Temporarily disable protection in current session
SET safeupdate.enabled = 0;CTE-based modifications without WHERE conditions are also blocked. The extension is particularly useful with PostgREST or other systems that provide direct write access to the database.
Last updated on