๐ Creating an Audit Log for PostgreSQL from Scratch ๐
Following up on my previous post, I'll add a way to create an Audit Log manually.
An Audit Log, in simple terms, is the storage of all database operations in a separate table. For example, Notion used to process these data with a script and transfer these operations to separate databases for sharding.
The process is straightforward:
- Create a table to store the log
- Create a function that describes the creation of records in this log
- Create a trigger for each table on Update, Insert, and Delete, which will launch the function to create a log of the operation
- Don't forget to add it to all tables
Well, and, of course, with a large amount of data, you can (1) create several tables to record the log, (2) sometimes clean it, (3) locally partition 1 table into several.
Powerful pumping ๐ช