pg_drop_events

logs transaction ids of drop table, drop column, drop materialized view statements

Overview

PackageVersionCategoryLicenseLanguage
pg_drop_events0.1.0ADMINPostgreSQLSQL
IDExtensionBinLibLoadCreateTrustRelocSchema
5850pg_drop_eventsNoNoNoYesNoNopublic
Relatedplpgsql pg_savior table_log pgaudit pg_auditor temporal_tables emaj pg_upless pgauditlogtofile

Version

TypeRepoVersionPG VerPackageDeps
EXTMIXED0.1.01817161514pg_drop_eventsplpgsql
RPMPGDG0.1.01817161514pg_drop_events_$v-
DEBPIGSTY0.1.01817161514postgresql-$v-pg-drop-events-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
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

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 TABLE
  • DROP COLUMN (via ALTER TABLE)
  • DROP MATERIALIZED VIEW

Logged Information

ColumnDescription
pidProcess identifier
usenameDatabase user who executed the command
queryThe SQL statement
xact_idTransaction identifier
wal_positionWrite-ahead log position
objidObject identifier
object_nameFully qualified name of dropped object
object_typeObject classification (table, table column, etc.)
xact_timeTimestamp 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 columnRecovery parameter
xact_idrecovery_target_xid
xact_timerecovery_target_time
wal_positionrecovery_target_lsn

Use these values in postgresql.conf or recovery.conf to restore the database to a point just before the accidental drop.


Last Modified 2026-03-12: add pg extension catalog (95749bf)