Ever had the need to know what happened with your data? Tablelog could be your answer.
The usage is easy: you create a second table which has the same format like your original table you want to keep an eye on. Plus you need some additional columns to maintain the logged data.
But step by step:
First thing: you need the software. Get it from GitHub.
Unpack the archive, join the
table_log-version directory and type in:
This should work without problems. If you get an error about missing include files, please install the PostgreSQL development packages from your distribution.
If compilation was done successfully, install the library. You have to be a superuser to do that, so first become root with
sudo. Type in:
This will install the library into the PostgreSQL library directory.
Now we have to tell the database that we want to use
tablelog, so make sure, you have support for plpgsql enabled (with createlang). Connect as a superuser to the database which contains your tables and execute the following commands (you can find them in the file
After this you may add some supporting functions which will make life more easy, you can find them in the file
table_log_init.sql. Just paste the content into your database shell or include it using the
\i command in
Thats all, now you can use
tablelog in your database.
Here’s an example (taken from
You will see that the
test_log table contains all changes which happened to the original table. If you want to avoid the overhead for creating the logtable, take a look into the support functions created by
Ok, but what use would be the logging data if we have no good chance of using it?
So the next example will show you, how you can take a look into the state of your table at any time in the past:
The meaning of the arguments, from left to right: name of the original table, primary key of the original table, name of the logging table, primary key of the logging table, recovery table to create by
table_log_restore_table(), timestamp for the lookup. Some more arguments are available, take a look into the
README for a full description.
Have fun with your table history.
If you want to provide feedback, you will find contact infos at the end of the