Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discover what a Postgresql table's usage is?

Our team is working on a Postgresql database with lots of tables and views, without any referential constraints. The project is undocumented and there appears to be a great number of unused/temporary/duplicate tables/views dirtying the schema.

We need to discover what database objects have real value and are actually used and accessed. My inital thoughts were to query the Catalog/'data-dictionary'.

Is it possible to query the Postgresql Catalog to find an object's last query time.

Any thoughts, alternative approaches and or tools ideas?

like image 958
Fairy Bower Avatar asked Jan 28 '26 06:01

Fairy Bower


2 Answers

Check the Statistics Collector

like image 163
Frank Heikens Avatar answered Feb 01 '26 17:02

Frank Heikens


Not sure about the last query time but you can adjust your postgresql.conf to log all SQL:

log_min_duration_statement = 0

That will at least give you an idea of current activity.

like image 33
Alex Howansky Avatar answered Feb 01 '26 18:02

Alex Howansky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!