pg_savior
pg_savior
pg_savior : Postgres extension to save OOPS mistakes
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5810 | pg_savior | pg_savior | 0.0.1 | ADMIN | Apache-2.0 | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pg_upless safeupdate pg_drop_events pg_cheat_funcs table_log pg_snakeoil pg_auditor temporal_tables |
-tuplestore_donestoring , breaks on pg18 @ el
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.1 | 18 17 16 15 14 | pg_savior | - |
| RPM | PIGSTY | 0.0.1 | 18 17 16 15 14 | pg_savior_$v | - |
| DEB | PIGSTY | 0.0.1 | 18 17 16 15 14 | postgresql-$v-pg-savior | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
el8.aarch64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
el9.x86_64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
el9.aarch64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
el10.x86_64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
el10.aarch64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
d12.x86_64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
d12.aarch64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
d13.x86_64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
d13.aarch64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
u22.x86_64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
u22.aarch64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
u24.x86_64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
u24.aarch64 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 | PIGSTY 0.0.1 |
Source
pig build pkg pg_savior;# 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_savior;# install via package name, for the active PG version pig install pg_savior -v 18; # install for PG 18 pig install pg_savior -v 17; # install for PG 17 pig install pg_savior -v 16; # install for PG 16 pig install pg_savior -v 15; # install for PG 15 pig install pg_savior -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pg_savior;Usage
The pg_savior extension intercepts query execution to prevent accidental data deletion. It hooks into the executor to detect dangerous DELETE operations and block them.
How It Works
When a DELETE statement is processed, pg_savior checks for:
- Missing WHERE clauses on DELETE commands
- Index scan operations in DELETE query plans
- Complex queries involving CTEs and subqueries in DELETE operations
When a risky DELETE is detected, the extension prevents execution and returns an informational message with zero rows affected.
Example
CREATE EXTENSION pg_savior; -- Attempting a DELETE without WHERE clause DELETE FROM emp; -- INFO: pg_savior: DELETE statement detected -- INFO: pg_savior: WHERE clause is mandatory for a DELETE statement -- DELETE 0 (no rows affected, data preserved) -- Normal DELETE with WHERE clause works as expected DELETE FROM emp WHERE id = 42; -- DELETE 1Notes
- The extension operates through PostgreSQL executor hooks, requiring no changes to application code
- Only DELETE statements are currently intercepted; UPDATE operations are not affected
- Planned features include preventing
CREATE INDEXwithoutCONCURRENTLYand blockingDROP DATABASE
Last updated on