5

I want to retrieve all the records that were modified in the past hour of running the command. It is purely a meta data command (with no regard to the content of any tabular column data). I want to identify tables and rows of those tables that had some DML modification with a specified temporal duration.

Does Postgres need special configuration to track such detailed meta data before I run a command to return the info I am looking for?

What query would I run to get the results I am looking for?

asked Dec 26, 2016 at 13:44

1 Answer 1

4

Postgres 9.5 introduced a feature to record commit timestamps. The manual:

track_commit_timestamp (bool)

Record commit time of transactions. This parameter can only be set in postgresql.conf file or on the server command line. The default value is off.

Some functions to work with it were added, too.

Once the DB server is restarted with this setting activated, Postgres tracks commit timestamps. Then, for example, to get all rows from a table that were changed in any way during the last 4 hours:

SELECT * FROM tbl
WHERE pg_xact_commit_timestamp(xmin) >= now() - interval '4 hours';

Related:

answered Dec 27, 2016 at 2:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.