[ $davids.sh ] โ€” david shekunts blog

๐Ÿ” Creating an Audit Log for PostgreSQL from Scratch ๐Ÿ”Ž

# [ $davids.sh ] ยท message #145

๐Ÿ” Creating an Audit Log for PostgreSQL from Scratch ๐Ÿ”Ž

https://www.bluelabellabs.com/blog/how-to-setup-automatic-audit-logging-in-postgres-using-triggers-and-trigger-functions/

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:

  1. Create a table to store the log
  2. Create a function that describes the creation of records in this log
  3. Create a trigger for each table on Update, Insert, and Delete, which will launch the function to create a log of the operation
  4. 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 ๐Ÿ’ช

Link to the article on Medium