{"schema": "pgtrue.report/1", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713", "published": "2026-10-19T06:26:45Z", "publisher": "PostgresAI", "article": {"title": "PG18 preserves planner statistics on upgrade \u2014 even from PG14", "url": "https://postgres.ai/blog/20260324-pg18-stats-upgrade-across-versions", "date_published": "2026-03-24T12:00:00Z", "author": "Nikolay Samokhvalov", "publisher": "PostgresAI"}, "grade": "A-", "axes": [{"axis": "Factual", "summary": "B+ \u00b7 1 wrong of 14 checked \u00b7 0 caveats"}, {"axis": "Applicable", "summary": "A \u00b7 0 wrong of 11 checked \u00b7 1 caveat"}, {"axis": "Consistent", "summary": "A \u00b7 0 wrong of 14 checked \u00b7 0 caveats"}, {"axis": "Transparent", "summary": "A \u00b7 0 wrong of 7 checked \u00b7 0 caveats"}, {"axis": "Safe", "summary": "A \u00b7 0 wrong of 11 checked \u00b7 0 caveats"}], "findings": [{"anchor": "F1", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F1", "claim": "\u2026the planner sees 10M\u2026", "title": "The empty-table catalog query does not show a 10-million-row planner estimate", "explanation": "The planner checks physical table size. src/backend/access/table/tableam.c:704 returns 0 tuples when the table has 0 pages. Imported reltuples can still contain approximately 10 million tuples. The displayed catalog value proves restoration, but it does not prove the stated planner estimate.", "verdict": "False", "sources": [{"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/backend/access/table/tableam.c#L700-L709", "label": "REL_18_3 \u00b7 src/backend/access/table/tableam.c:700-709"}]}, {"anchor": "F2", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F2", "claim": "\u2026the duration of ANALYZE increases proportionally\u2026", "title": "Increasing default_statistics_target does not proportionally increase every ANALYZE runtime", "explanation": "ANALYZE applies default_statistics_target only to columns without explicit targets. src/backend/commands/analyze.c:1177 also caps sampled blocks at the table's block count. Sample size can scale with the target. Total elapsed time need not scale proportionally.", "verdict": "Mostly accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/doc/src/sgml/config.sgml#L6372-L6377", "label": "REL_18_3 \u00b7 doc/src/sgml/config.sgml:6372-6377"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/backend/commands/analyze.c#L1894-L1900", "label": "REL_18_3 \u00b7 src/backend/commands/analyze.c:1894-1900"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/backend/commands/analyze.c#L1170-L1185", "label": "REL_18_3 \u00b7 src/backend/commands/analyze.c:1170-1185"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/backend/commands/analyze.c#L1887-L1958", "label": "REL_18_3 \u00b7 src/backend/commands/analyze.c:1887-1958"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/backend/commands/analyze.c#L1887-L1958", "label": "REL_18_3 \u00b7 src/backend/commands/analyze.c:1887-1958"}, {"url": "https://www.endpointdev.com/blog/2016/12/postgres-statistics-and-pain-of-analyze/", "label": "https://www.endpointdev.com/blog/2016/12/postgres-statistics-and-pain-of-analyze/"}]}, {"anchor": "F4", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F4", "claim": "\u2026PG18 preserves statistics during pg_upgrade\u2026", "title": "PG18 pg_upgrade exports statistics using the target pg_dump", "explanation": "src/bin/pg_upgrade/dump.c:54 invokes pg_dump from new_cluster.bindir against old_cluster. It passes --statistics unless statistics transfer is disabled. PostgreSQL 14 exposes the relation and column catalog fields the exporter reads.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/doc/src/sgml/ref/pgupgrade.sgml#L834-L839", "label": "REL_18_3 \u00b7 doc/src/sgml/ref/pgupgrade.sgml:834-839"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_upgrade/dump.c#L54-L62", "label": "REL_18_3 \u00b7 src/bin/pg_upgrade/dump.c:54-62"}, {"url": "https://github.com/postgres/postgres/blob/6b3806732b7c5df06bdd0ed150e8a07b4ad62315/src/include/catalog/pg_class.h#L59-L75", "label": "REL_14_24 \u00b7 src/include/catalog/pg_class.h:59-75"}, {"url": "https://github.com/postgres/postgres/blob/6b3806732b7c5df06bdd0ed150e8a07b4ad62315/src/backend/catalog/system_views.sql#L183-L201", "label": "REL_14_24 \u00b7 src/backend/catalog/system_views.sql:183-201"}]}, {"anchor": "F5", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F5", "claim": "\u2026reads from pg_class (for relpages , reltuples , relallvisible )\u2026", "title": "The exporter reads the named relation and column statistics", "explanation": "src/bin/pg_dump/pg_dump.c selects relpages, reltuples, and relallvisible. Its attribute query reads pg_stats fields including null_frac, avg_width, n_distinct, most_common_vals, histogram_bounds, and correlation.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L7084-L7115", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:7084-7115"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L10975-L11065", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:10975-11065"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/include/catalog/pg_class.h#L59-L75", "label": "REL_18_3 \u00b7 src/include/catalog/pg_class.h:59-75"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L10975-L11065", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:10975-11065"}]}, {"anchor": "F6", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F6", "claim": "pg_restore_relation_stats() and pg_restore_attribute_stats()\u2026", "title": "The PG18 restore functions update relation and column statistics", "explanation": "pg_restore_relation_stats calls relation_statistics_update in src/backend/statistics/relation_stats.c:239. pg_restore_attribute_stats calls attribute_statistics_update in src/backend/statistics/attribute_stats.c:1003. Their documentation describes table-level and column-level updates, respectively.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/doc/src/sgml/func.sgml#L30495-L30566", "label": "REL_18_3 \u00b7 doc/src/sgml/func.sgml:30495-30566"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/doc/src/sgml/func.sgml#L30588-L30660", "label": "REL_18_3 \u00b7 doc/src/sgml/func.sgml:30588-30660"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/backend/statistics/relation_stats.c#L226-L241", "label": "REL_18_3 \u00b7 src/backend/statistics/relation_stats.c:226-241"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/backend/statistics/attribute_stats.c#L991-L1004", "label": "REL_18_3 \u00b7 src/backend/statistics/attribute_stats.c:991-1004"}]}, {"anchor": "F7", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F7", "claim": "\u2026handles version differences gracefully\u2026", "title": "The exporter applies the stated source-version compatibility rules", "explanation": "src/bin/pg_dump/pg_dump.c remaps reltuples=0 to -1 before PostgreSQL 14. It omits range-specific fields before PostgreSQL 17. It substitutes relallfrozen=0 before PostgreSQL 18. The target catalog also defaults relallfrozen to 0.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L7084-L7115", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:7084-7115"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L11045-L11055", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:11045-11055"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L10984-L10992", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:10984-10992"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/include/catalog/pg_class.h#L59-L75", "label": "REL_18_3 \u00b7 src/include/catalog/pg_class.h:59-75"}]}, {"anchor": "F8", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F8", "claim": "The official pg_upgrade documentation recommends a two-step post-upgrade process\u2026", "title": "The two analysis commands match PostgreSQL 18 documentation", "explanation": "doc/src/sgml/ref/pgupgrade.sgml:850 recommends --analyze-in-stages --missing-stats-only, followed by --analyze-only. The documentation identifies missing optimizer statistics and cumulative maintenance statistics as reasons for these passes.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/doc/src/sgml/ref/pgupgrade.sgml#L834-L839", "label": "REL_18_3 \u00b7 doc/src/sgml/ref/pgupgrade.sgml:834-839"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/doc/src/sgml/ref/pgupgrade.sgml#L850-L856", "label": "REL_18_3 \u00b7 doc/src/sgml/ref/pgupgrade.sgml:850-856"}]}, {"anchor": "F10", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F10", "claim": "\u2026the stats dump is metadata-only \u2014 no table data is read, just catalog queries\u2026", "title": "Statistics-only export excludes table data", "explanation": "src/bin/pg_dump/pg_dump.c:881 disables data dumping for --statistics-only. The statistics exporter reads relation metadata and pg_stats. This confirms catalog-based export, without establishing the article's runtime estimate.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L7084-L7115", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:7084-7115"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L10975-L11065", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:10975-11065"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L879-L887", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:879-887"}, {"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/bin/pg_dump/pg_dump.c#L10975-L11065", "label": "REL_18_3 \u00b7 src/bin/pg_dump/pg_dump.c:10975-11065"}]}, {"anchor": "F12", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F12", "claim": "\u2026Postgres 18 introduces statistics export and import.", "title": "PostgreSQL 18 introduced planner-statistics preservation", "explanation": "The PostgreSQL 18 release announcement confirms planner-statistics preservation across major upgrades. It describes faster recovery of expected performance.", "verdict": "Accurate", "sources": [{"url": "https://www.postgresql.org/about/news/postgresql-18-released-3142/", "label": "https://www.postgresql.org/about/news/postgresql-18-released-3142/"}]}, {"anchor": "F13", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F13", "claim": "\u2026sometimes take longer than the entire rest of the upgrade\u2026", "title": "The 2016 post supports the historical analysis-delay comparison", "explanation": "Greg Sabino Mullane's December 2016 post says analysis sometimes exceeded the rest of the upgrade. The article preserves that conditional comparison.", "verdict": "Accurate", "sources": [{"url": "https://www.endpointdev.com/blog/2016/12/postgres-statistics-and-pain-of-analyze/", "label": "https://www.endpointdev.com/blog/2016/12/postgres-statistics-and-pain-of-analyze/"}]}, {"anchor": "F14", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F14", "claim": "\u2026it's going to be much better in Postgres 19\u2026", "title": "The partitioned-table analysis improvement targets PostgreSQL 19", "explanation": "Patch 5871 makes vacuumdb --analyze-only process partitioned tables. Its record identifies PostgreSQL 19 as the target and lists committed status.", "verdict": "Accurate", "sources": [{"url": "https://commitfest.postgresql.org/patch/5871/", "label": "https://commitfest.postgresql.org/patch/5871/"}]}, {"anchor": "F15", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F15", "claim": "\u2026pg_dump can also dump from PostgreSQL servers older than its own version.", "title": "The pg_dump compatibility quotation matches the manual", "explanation": "The pg_dump manual confirms support for servers older than the client. This supports connection compatibility, not every statistics-transfer version boundary.", "verdict": "Accurate", "sources": [{"url": "https://www.postgresql.org/docs/current/app-pgdump.html", "label": "https://www.postgresql.org/docs/current/app-pgdump.html"}]}, {"anchor": "F16", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F16", "claim": "\u2026updates the cumulative statistics used to trigger automatic vacuum and analyze\u2026", "title": "The second analysis pass matches PostgreSQL 18 guidance", "explanation": "PostgreSQL 18's upgrade manual recommends both analysis passes. It identifies updated cumulative statistics for automatic vacuum and analyze as the second pass's purpose.", "verdict": "Accurate", "sources": [{"url": "https://www.postgresql.org/docs/18/pgupgrade.html", "label": "https://www.postgresql.org/docs/18/pgupgrade.html"}, {"url": "https://www.postgresql.org/docs/18/pgupgrade.html", "label": "https://www.postgresql.org/docs/18/pgupgrade.html"}]}, {"anchor": "F18", "url": "https://pgtrue.postgres.ai/shared/brief/66dcbec1-e338-4b08-8207-c3dd1d527713#F18", "claim": "\u20269.999034e+06\u2026", "title": "The displayed reltuples value rounds correctly to 10 million rows", "explanation": "9.999034e+06 equals 9,999,034 rows. The difference from 10 million rows is 966 rows, or 0.00966%. The approximation is correct. This arithmetic does not independently verify the recorded measurement.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/62d6c7d3df6287f1bd83199c1a746e50d31571a0/src/include/catalog/pg_class.h#L32-L71", "label": "REL_18_3 \u00b7 src/include/catalog/pg_class.h:32-71"}]}]}