Find When was a table last changed in PostgreSQL?
In PostgreSQL, you can use the pg_class system catalog table to determine when a table was last changed. The pg_class table contains metadata about all tables in the database, including the timestamp of the last modification. Here is an example of a query that you can use to find when a table was last changed:
1 2 3 4 |
SELECT relname, relkind, reltuples, relpages, relacl, to_char(pg_relation_last_system_change(oid), 'YYYY-MM-DD HH24:MI:SS') as last_change FROM pg_class WHERE relname = 'mytable'; |
1 2 3 |
SELECT relname, last_vacuum, last_analyze, last_autovacuum FROM pg_stat_all_tables WHERE relname = 'mytable'; |