How can I use a PostgreSQL triggers to store changes (SQL statements and row changes)

后端 未结 5 1061
轻奢々
轻奢々 2020-12-07 16:05

Using PostgreSQL triggers, is it possible to record the changes that have happened to a table due to INSERT or UPDATE SQL statements and log them to a file for later executi

5条回答
  •  囚心锁ツ
    2020-12-07 16:46

    PostgreSQL Table Log by Andreas Scherbaum is a Postgresql extension that uses a trigger to log any INSERTs, UPDATEs and DELETEs on a specific table into another table.

    The usage is easy: you create a second table which has the same format like your table you want to keep an eye on. Plus you need some additional columns to maintain the logged data.

    The second part of tablelog is able to restore the state of the original table or of a specific row for any time in the past.

    I haven't tried it myself, but it's supposedly working.

    There's also slides from a talk about tablelog, but I can't post a proper link here due to some stackoverflow antispam weirdness :) (http :// andreas.scherbaum.la/writings/tablelog.pdf).

    http://pgfoundry.org/projects/tablelog/

    http:// andreas.scherbaum.la/blog/archives/100-Log-Table-Changes-in-PostgreSQL-with-tablelog.html

提交回复
热议问题