tags:

views:

83

answers:

3

Hi all,

How can I find the table creation time in Postgresql.

Example ,

If I created a file I can find the file creation time like that I want to know the table creation time.

+1  A: 

I don't think it's possible from within PostgreSQL, but you'll probably find it in the underlying table file's creation time.

Marcelo Cantos
+1  A: 

I had a look through the pg_* tables, and I couldn't find any creation times in there. It's possible to locate the table files, but then on Linux you can't get file creation time. So I think the answer is that you can only find this information on Windows, using the following steps:

  • get the database id with select datname, datdba from pg_database;
  • get the table filenode id with select relname, relfilenode from pg_class;
  • find the table file and look up its creation time; I think the location should be something like <PostgreSQL folder>/main/base/<database id>/<table filenode id> (not sure what it is on Windows).
Alex - Aotea Studios
There are some operations on a table, such as CLUSTER, that will generate a new file and not re-use the old one. So this is not a reliable method.
Magnus Hagander
+4  A: 

You can't - the information isn't recorded anywhere. Looking at the table files won't necessarily give you the right information - there are table operations that will create a new file for you, in which case the date would reset.

Magnus Hagander