Postgresql – large number of tables and postgres query performace

optimizationpostgresqlquery-performance

I have a scenario where there are 40000 tables in the database. but there are no huge unions. Very simple single table select queries are performing much slower than usual (table with just 600,000 rows and 10-15 columns).

Does the (large) number of tables in a database can affect query performance? If Yes, How?

Best Answer

If anything, the large number of tables would affect planning time.

EXPLAIN (ANALYZE, BUFFERS) your query to see the planning time and figure out where the time is spent.