I have inherited an existing Postgres database full of data. Most of the data has a 'created_date' column value. Some of the earlier data was inserted before this was being tracked.
Is there a Postgres metadata table hidden away somewhere that tracks when INSERT
queries were done?
You can enable track_commit_timestamp
in postgresql.conf
(and restart) to start tracking commit timestamps. Then you can get a timestamp for your xmin
. Related answer:
There is no such metadata in PostgreSQL unless you record it yourself.
You may be able to deduce some information from the row headers (HeapTupleHeaderData), in particular from the insert transaction id xmin
. It holds the ID of the transaction in which the row was inserted (needed to decide visibility in PostgreSQL's MVCC model). Try (for any table):
SELECT xmin, * FROM tbl LIMIT 10;
Some limitations apply:
xmin
is ambiguous.But for most databases you should be able to derive:
No timestamp, though.