pg_recyclebin
pg_recyclebin · Intercepts DROP TABLE and TRUNCATE to retain recoverable table data and metadata in a recycle-bin schema.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101083 | pg_recyclebin | pg_recyclebin | 0.1.0 | ADMIN | MIT | Rust |
PostgreSQL · 14, 15, 16, 17, 18
Usage
Sources:
- Pinned current upstream README
- Version 0.1.0 installation SQL
- Pinned Cargo metadata
- Pinned backup and restore test matrix
pg_recyclebin version 0.1.0 intercepts selected DROP and TRUNCATE operations. Dropped tables are moved and renamed under flashback_recycle; truncated data is copied there. Metadata under flashback records the original owner, schema, operation, dependencies, and retention deadline so an entry can be listed, restored, or permanently purged.
Preload and recovery example
The current project documents PostgreSQL 14 through 18 and pgrx 0.16.1. A background worker purges expired entries. Its default connection database is postgres; installations in another database should set flashback.database_name. Runtime limits control retention days, table count, total size, worker interval, and excluded schemas.
Recovery is not backup
The hook deliberately changes normal DROP and TRUNCATE semantics, including multi-table commands, CASCADE, and DROP SCHEMA CASCADE. It may move partitions, recreate dependent views and incoming foreign keys, preserve policies and triggers, or copy a complete truncated table. These operations add DDL latency, storage and WAL pressure, lock interactions, and new failure modes. Test transactional rollback, dependencies, partitions, identity sequences, ownership, RLS, and quoted names against the exact release.
The recycle bin cannot protect against DROP DATABASE, cluster or disk loss, temporary or excluded tables, privileged purge, retention eviction, extension failure, or corruption. Keep independent tested backups and point-in-time recovery. Restrict restore and purge functions, monitor recycle storage, and rehearse both ordinary restore and mass recovery before relying on it for operator mistakes.