---
title: "Copied PostgreSQL statistics do not reproduce the plan on an empty table | Proofline"
description: "Importing production statistics into an empty copy does not bring the production plan with it, because the planner uses the table's actual size."
url: https://proofline.sh/learn/postgres-plan-statistics-copy/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# Copied PostgreSQL statistics do not reproduce the plan on an empty table

Importing production statistics into an empty copy does not bring the production plan with it, because the planner uses the table's actual size. Give the copy a comparable number of pages, and check what the statistics reveal before you share them.

Capacity overruns The Proofline team November 24, 2026 2 min read

## Three copies of one table

The source has 200,000 orders, 0.1% of them `open`, and an index on `status`. The query is `SELECT * FROM orders WHERE status = 'open'`. Run with PostgreSQL 18.

| Copy | Plan | Estimated rows |
| --- | --- | --- |
| Source | Index Scan | 153 |
| Schema only, then `ANALYZE` | Seq Scan, cost 0.00 | 1 |
| Schema, and `pg_dump --statistics-only` from the source | Seq Scan, cost 0.00 | 1 |
| The third, after inserting 20,000 rows with no `ANALYZE` | Index Scan | 15 |
| The fourth, after `ANALYZE` | Bitmap Heap Scan | 10,000 |

In the third row, the import had worked: `pg_stats` listed the source's most common values. The plan did not change, because the table had no pages. The manual explains that the planner fetches the actual current number of pages, and if that differs from `relpages`, it scales `reltuples`. [Row estimation examples](https://www.postgresql.org/docs/current/row-estimation-examples.html)

In the fourth, the rows that were inserted are half `open`, and the plan still follows the imported 0.1%. `pg_class` still said 200,000 tuples and 1,471 pages from the import, while the estimate of 15 was scaled to the real size. `ANALYZE` then replaced the imported statistics with the synthetic ones. Autovacuum can run that `ANALYZE` without you, so the reproduction may change while you look at it.

```
ALTER TABLE orders SET (autovacuum_enabled = false);  -- on the scratch copy only
```

## Choose a reproduction

| Question | Copy |
| --- | --- |
| Does the query parse, and does an index match? | Schema only |
| Why does the planner choose this plan? | Schema, imported statistics and synthetic rows that fill a similar number of pages, with no `ANALYZE` |
| How long does it take? | Data of similar size and distribution, on similar hardware |
| Is the result correct? | Rows designed for the case |

`pg_dump --statistics-only` is listed in the [pg\_dump reference](https://www.postgresql.org/docs/current/app-pgdump.html). Check that your client version has it. Planner settings have to match too; [the EXPLAIN handoff](/learn/postgres-explain-handoff/) lists them.

## Statistics contain data

The dump for this table has this line:

```
'most_common_vals', '{closed,open}'::text,
```

For a status column that is harmless. For an email, name or diagnosis column, the most common values and histogram bounds are real values from production. Read the file, and treat it with the same approval as a data extract. To leave a column out, delete its `pg_restore_attribute_stats` call and say so, because plans that depend on it will differ.

## Worked example

This example is fictional. Ana sends schema and statistics to show a bad plan. Ben gets a sequential scan with cost 0 and replies that it looks fine. Ana's message gets two more lines: the table's page count, and a generator for rows that fill as many pages. With autovacuum off for that table, Ben's plan matches the shape of production's and its estimate is close. He then tries an extended statistics object on the copy. Whether it is faster in production is a separate test.

Return to [handing over evidence](/learn/engineering-handoff-evidence/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Hand over a PostgreSQL plan someone else can reason about](/learn/postgres-explain-handoff/)
    
    Capacity overruns The Proofline team November 24, 2026 3 min read
    
-   ### [Hand over a bug that needs one production account's state](/learn/production-only-account-state/)
    
    Schema conflicts The Proofline team November 24, 2026 3 min read
