Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: Table creation time

Tags:

postgresql

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.

like image 372
kiruthika Avatar asked Apr 05 '10 06:04

kiruthika


People also ask

How do you check who created a table in Postgres?

Interestingly, the solution was quite simple: select tablename, tableowner from pg_catalog. pg_tables where schemaname = 'public' ; All of the schemas in our db are the default public , so to eliminate some of the tables Postgres provides, I included that filter.

How many tables we can create in PostgreSQL?

Technically Postgres does not have a limit on the number of tables. However, each table is a file on the OS filesystem. And the OS probably has some opinion on how many files is "too many".

How do you find when was the table last updated in Postgres?

You can do it via checking last modification time of table's file. In postgresql,every table correspond one or more os files,like this: select relfilenode from pg_class where relname = 'test'; the relfilenode is the file name of table "test".


Video Answer


2 Answers

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).
like image 139
Alex Korban Avatar answered Sep 20 '22 11:09

Alex Korban


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.

like image 31
Magnus Hagander Avatar answered Sep 23 '22 11:09

Magnus Hagander