How in postgresql to find out the date of adding the last record in the table?

  • one
    To fix the data yourself. - Alexander Semikashev

2 answers 2

Postgresql does not save time when lines were added / updated / deleted (this would slow down postgresql).

You will need to do it yourself: add a timestamp column to the table. When inserting, changing a row, update the column where you keep the time to the current one. By such a request, it will be possible to find out the time of change, if you fulfill the conditions above.

SELECT time from yourtable ORDER BY time limit 1; 

    No PostgreSQL does not keep statistics on data modification time.

    If your goal is to find out that the table is not used, then you need to save the output of usage counters for it from the pg_stat_all_tables system table (or reset the base statistics with the pg_stat_reset() functions or pg_stat_reset_single_table_counters(oid) ) and see what has changed in these counters after some time.