On 27/11/2026 04:30, David Rowley wrote:
I'm currently processing various internal reports about slow
pg_upgrades. One of the points on the list is the
get_rel_infos_query() is sometimes slow. The report said the query
took 64.32 seconds for 100k tables. I was unable to get the EXPLAIN
output.

I was given the attached 03_get_rel_infos_100k_tables.sql script,
which I suspect was AI-generated from a "reverse engineer this issue"
type prompt as the script manually hacks reltuples and relpages to 1
for pg_class, pg_index, and pg_namespace. I see no reason why those
would ever be that low, but I understand that the stats can be
outdated because autovacuum doesn't run on the target instance during
the upgrade.

It seems bonkers to optimize for the case that the stats are bad like that, reltuples=1 and relpages=1 is a completely unrealistic case. Even if stats are missing, i.e. you haven't run vacuum, the default estimates are not reltuples=1 and relpages=1. Initdb runs ANALYZE, so even if the stats haven't been updated since, they would be a little better than that.

I think we'd need a little more realistic case to work with, before making any changes.

- Heikki



Reply via email to