Is it possible using triggers in PostgreSQL to create update and insert sql statements of changes that have happened to a table and log them to a file for later execution.
This is only to be used temporally so just something quick and dirty would do.
The link below should point you in the right direction.
http://developer.postgresql.org/pgdocs/postgres/sql-createtrigger.html
Depending on what you want to do, it probably is better to turn on logging.
example of an audit trigger from https://www.postgresql.org/docs/current/static/plpgsql-trigger.html
Do you actually need the audit log of queries stored in a table? The easiest way to get a file with all the queries that have been executed is to use postgresql's built-in logging.
In your postgresql.conf (usually in the $PG_DATA dir), set the following options appropriately:
That last option makes it log all the INSERT, UPDATE, DELETE, TRUNCATE, and COPY FROM statements.
More details in the Postgres docs: http://www.postgresql.org/docs/current/static/runtime-config-logging.html
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