1

I am trying to find out the date that each table was created in the database. I used the following code:

SELECT relfilenode, 
relname, (pg_stat_file('./base/24576' || '/' || relfilenode::text)).*
FROM pg_class 
WHERE relkind LIKE 'r'
AND relfilenode <> 0
order by modification ASC;

The result has null for the creation date of all tables:

enter image description here

How can I have the correct creation date for the tables??

1 Answer 1

3

As per the documentation, the creation date column only applies to Windows platforms.

Besides, that's not a very reliable way to get the creation date of a table. When you perform a VACUUM FULL on a table, the relfilenode will change (as well as a few other maintenance commands)--when that happens, you would be led to think that the "creation date" was "just now." If you want to track schema changes, you should implement event triggers.

Disclosure: I work for EnterpriseDB (EDB).

Sign up to request clarification or add additional context in comments.

3 Comments

yes, I am using linux thats why the creation date is null.
@richyen Thanks for the link to the sample code. I found it very useful. The second trigger has a bug though I think, it should be IF tg_tag = 'DROP TABLE' THEN FOR r IN SELECT * FROM pg_event_trigger_dropped_objects()
@Dowlers, thanks for bringing that to my attention--I'm having that fixed ASAP

Your Answer

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.