I recently ran into a weird problem while migrating from PG 9.4 => 11
I replicated the production server from PG 9.4 to PG 11 using pglogical
. Everything worked out well, except we discovered that a few complex queries were taking tens of seconds on the PG 11 server, while there were taking under one second on the 9.4 server.
It turns out that running ANALYZE
on the new server fixed the slow queries. So, I checked $PGDATA/pg_stat
and $PGDATA/pg_stat_tmp
and found them to be empty on both the servers!
Where does PG store statistics? (Follow-up question -- doesn't pglogical
collect statistics while it is replicating?)
Edit / follow-up:
Output of query on pg_stat_user_tables
on the new PG 11 server -
select analyze_count,autoanalyze_count, count(*) from pg_stat_user_tables group by 1,2;
analyze_count | autoanalyze_count | count
---------------+-------------------+-------
1 | 11 | 1
4 | 7 | 1
1 | 0 | 14
4 | 0 | 168
(4 rows)
Same query on old PG 9.4 server (current production server):
analyze_count | autoanalyze_count | count
---------------+-------------------+-------
0 | 13 | 3
0 | 226 | 1
0 | 1 | 31
0 | 5 | 6
0 | 21 | 2
0 | 16 | 2
0 | 601 | 1
0 | 8 | 1
0 | 20 | 1
0 | 4 | 2
0 | 9 | 2
0 | 10 | 2
0 | 12 | 1
0 | 7 | 2
0 | 41 | 1
0 | 2 | 11
0 | 6 | 1
0 | 3 | 8
0 | 731 | 1
0 | 39 | 1
0 | 11 | 1
0 | 0 | 99
0 | 50 | 1
0 | 66 | 1
0 | 241 | 1
0 | 14 | 2