pg_drop_events
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_drop_events | 0.1.0 | ADMIN | PostgreSQL | SQL |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 5850 | pg_drop_events | No | No | No | Yes | No | No | public |
| Related | plpgsql pg_savior table_log pgaudit pg_auditor temporal_tables emaj pg_upless pgauditlogtofile |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 0.1.0 | 1817161514 | pg_drop_events | plpgsql |
| RPM | PGDG | 0.1.0 | 1817161514 | pg_drop_events_$v | - |
| DEB | PIGSTY | 0.1.0 | 1817161514 | postgresql-$v-pg-drop-events | - |
Build
You can build the RPM / DEB packages for pg_drop_events using pig build:
pig build pkg pg_drop_events # build RPM / DEB packages
Install
You can install pg_drop_events directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_drop_events; # Install for current active PG version
pig ext install -y pg_drop_events -v 18 # PG 18
pig ext install -y pg_drop_events -v 17 # PG 17
pig ext install -y pg_drop_events -v 16 # PG 16
pig ext install -y pg_drop_events -v 15 # PG 15
pig ext install -y pg_drop_events -v 14 # PG 14
dnf install -y pg_drop_events_18 # PG 18
dnf install -y pg_drop_events_17 # PG 17
dnf install -y pg_drop_events_16 # PG 16
dnf install -y pg_drop_events_15 # PG 15
dnf install -y pg_drop_events_14 # PG 14
apt install -y postgresql-18-pg-drop-events # PG 18
apt install -y postgresql-17-pg-drop-events # PG 17
apt install -y postgresql-16-pg-drop-events # PG 16
apt install -y postgresql-15-pg-drop-events # PG 15
apt install -y postgresql-14-pg-drop-events # PG 14
Create Extension:
CREATE EXTENSION pg_drop_events CASCADE; -- requires: plpgsql
Usage
pg_drop_events: logs transaction ids of drop table, drop column, drop materialized view statements
The pg_drop_events extension uses event triggers to automatically log details about DROP operations on tables, columns, and materialized views. The logged information can be used for point-in-time recovery (PITR) after accidental drops.
Tracked Operations
DROP TABLEDROP COLUMN(viaALTER TABLE)DROP MATERIALIZED VIEW
Logged Information
| Column | Description |
|---|---|
pid | Process identifier |
usename | Database user who executed the command |
query | The SQL statement |
xact_id | Transaction identifier |
wal_position | Write-ahead log position |
objid | Object identifier |
object_name | Fully qualified name of dropped object |
object_type | Object classification (table, table column, etc.) |
xact_time | Timestamp of the transaction |
Example
CREATE EXTENSION pg_drop_events;
-- Drop a table
DROP TABLE t.t3;
-- NOTICE: table t.t3 dropped by transaction 1085.
-- Query the event log
SELECT * FROM pg_drop_events;
Point-in-Time Recovery
The logged data maps directly to PostgreSQL recovery parameters:
| pg_drop_events column | Recovery parameter |
|---|---|
xact_id | recovery_target_xid |
xact_time | recovery_target_time |
wal_position | recovery_target_lsn |
Use these values in postgresql.conf or recovery.conf to restore the database to a point just before the accidental drop.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.