Search⌘ K
AI Features

Auditing Changes with a Trigger

Explore how to implement auditing of database changes in PostgreSQL by using triggers combined with the hstore extension. This lesson helps you set up audit tables and triggers to capture and record updates, including the flexibility to track multiple tables and schema changes effectively.

Setup for capturing changes

First, we need some setup:

  • We’re going to track changes made when we update the MoMA collection, which we processed in “Batch Update, MoMA Collection.” The table we’re auditing is moma.artist.

  • The changes are recorded in a table named moma.audit, defined in a pretty generic way as we can see below.

  • Then we install PostgreSQL triggers on the moma.artist table to capture any change made to it and populate the ...