Skip to content
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
u26.x86_64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
u26.aarch64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
Package Version OS ORG SIZE File URL
safeupdate_18 1.5 el8.x86_64 pgdg 13.4 KiB safeupdate_18-1.5-2PGDG.rhel8.x86_64.rpm
safeupdate_18 1.5 el8.aarch64 pgdg 13.4 KiB safeupdate_18-1.5-2PGDG.rhel8.aarch64.rpm
safeupdate_18 1.5 el9.x86_64 pgdg 12.8 KiB safeupdate_18-1.5-2PGDG.rhel9.x86_64.rpm
safeupdate_18 1.5 el9.aarch64 pgdg 12.6 KiB safeupdate_18-1.5-2PGDG.rhel9.aarch64.rpm
safeupdate_18 1.5 el10.x86_64 pgdg 13.2 KiB safeupdate_18-1.5-2PGDG.rhel10.x86_64.rpm
safeupdate_18 1.5 el10.aarch64 pgdg 13.2 KiB safeupdate_18-1.5-2PGDG.rhel10.aarch64.rpm
postgresql-18-pg-safeupdate 1.5 d12.x86_64 pigsty 8.7 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~bookworm_amd64.deb
postgresql-18-pg-safeupdate 1.5 d12.aarch64 pigsty 8.8 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~bookworm_arm64.deb
postgresql-18-pg-safeupdate 1.5 d13.x86_64 pigsty 8.7 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~trixie_amd64.deb
postgresql-18-pg-safeupdate 1.5 d13.aarch64 pigsty 8.8 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~trixie_arm64.deb
postgresql-18-pg-safeupdate 1.5 u22.x86_64 pigsty 8.8 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~jammy_amd64.deb
postgresql-18-pg-safeupdate 1.5 u22.aarch64 pigsty 8.9 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~jammy_arm64.deb
postgresql-18-pg-safeupdate 1.5 u24.x86_64 pigsty 9.0 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~noble_amd64.deb
postgresql-18-pg-safeupdate 1.5 u24.aarch64 pigsty 9.0 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~noble_arm64.deb
postgresql-18-pg-safeupdate 1.5 u26.x86_64 pigsty 9.1 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~resolute_amd64.deb
postgresql-18-pg-safeupdate 1.5 u26.aarch64 pigsty 9.2 KiB postgresql-18-pg-safeupdate_1.5-2PIGSTY~resolute_arm64.deb

Source

pig build pkg safeupdate;		# build deb

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

Install 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 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'safeupdate';

This extension does not need CREATE EXTENSION DDL command

Usage

safeupdate: Require criteria for UPDATE and DELETE

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.conf

Behavior

-- 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