pg_drop_events
pg_drop_events
pg_drop_events : logs transaction ids of drop table, drop column, drop materialized view statements
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5850 | pg_drop_events | pg_drop_events | 0.1.0 | ADMIN | PostgreSQL | SQL |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
----d-- | No | No | No | Yes | no | no |
| Relationships | |
|---|---|
| Schemas | public |
| Requires | plpgsql |
| See Also | pg_savior table_log pgaudit pg_auditor temporal_tables emaj pg_upless pgauditlogtofile |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 0.1.0 | 18 17 16 15 14 | pg_drop_events | plpgsql |
| RPM | PGDG | 0.1.0 | 18 17 16 15 14 | pg_drop_events_$v | - |
| DEB | PIGSTY | 0.1.0 | 18 17 16 15 14 | postgresql-$v-pg-drop-events | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
el8.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
el9.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
el9.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
el10.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
el10.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
d12.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
d12.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
d13.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
d13.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
u22.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
u22.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
u24.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
u24.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
Source
pig build pkg pg_drop_events; # 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_drop_events; # install via package name, for the active PG version
pig install pg_drop_events -v 18; # install for PG 18
pig install pg_drop_events -v 17; # install for PG 17
pig install pg_drop_events -v 16; # install for PG 16
pig install pg_drop_events -v 15; # install for PG 15
pig install pg_drop_events -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pg_drop_events CASCADE; -- requires plpgsqlUsage
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.
Last updated on