Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

Read Replicas Do Not Fix a Bad Query Plan

A read replica adds capacity for reads, but it doesn't rewrite a query, add an index or fix planner statistics. Here's how to tell a plan problem from a capacity problem.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A read replica gives you more places to run reads. It does not make any single read cheaper. If a query scans far more data than it should, picks a poor join order, or relies on misleading planner estimates, it can do the same wasteful work on a replica. The difference is per-query efficiency versus workload capacity, and the two need different fixes.

What a replica changes and what it leaves alone

AWS describes routing application reads to Amazon RDS read replicas as a way to reduce load on the source database and scale read-heavy workloads. Its feature comparison names scalability as the main purpose of read replicas, and says replication is asynchronous for non-Aurora read replicas. That is a capacity claim, and it only applies to reads your application actually sends to the replica.

A replica does not, by itself:

  • rewrite the SQL or reduce the work one execution needs;
  • create the index the query needs;
  • improve stale or inadequate planner statistics;
  • change an inefficient access path.

One caution runs the other way: don’t assume the plan on the replica is identical to the plan on the primary. Engine, statistics, configuration and service architecture all matter, so capture the plan on the instance that actually serves the query.

How the planner fits in

The PostgreSQL 17 documentation (section 14.1, “Using EXPLAIN”) puts it plainly: “PostgreSQL devises a query plan for each query it receives.” EXPLAIN shows that plan as a tree. It has scan nodes at the bottom and, where needed, join, aggregation, sort or other nodes above them. If the tree is wasteful, moving the query to another server changes where the waste happens, not whether it happens.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Diagnose before you add capacity

1. Pin down the statement and where it runs

Identify the exact slow statement, its parameter values, how often it runs, its concurrency, and the instance that serves it. Write traffic is a separate workload that a replica does not absorb.

2. Capture the plan on representative data

EXPLAIN SELECT ...;
EXPLAIN ANALYZE SELECT ...;

EXPLAIN ANALYZE executes the statement and adds observed row counts and timings. Three limits apply, per the PostgreSQL documentation:

  • it does not send result rows to the client, so its time is not end-to-end application latency;
  • measurement can add its own overhead;
  • estimates vary with sampled statistics and platform conditions.

Because it runs the query, use it with care on statements that modify data or are very expensive.

3. Read the tree from the scans upward

  • Estimated versus actual rows. A large gap usually means the planner is choosing on bad information.
  • Scan type. A sequential scan is not inherently bad. PostgreSQL notes that on a small table it can be the sensible choice even when indexes exist. It is suspect when the table is large and the predicate is selective.
  • Join, sort and aggregation work. Check that it matches the shape of what the query is meant to return.

4. Check statistics and index usability

Ask whether statistics reflect the current data, and whether the query’s predicates and joins can use existing indexes. Don’t add an index blindly. Its value depends on the query, the data distribution, the write cost it imposes and the competing workload.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Change one thing and compare

Compare plan and latency before and after any SQL, statistics, schema, index, configuration or version change. Only once the query is reasonably efficient and the remaining problem is read concurrency should you test replica capacity. Then measure both response time and lag, and state your read-after-write and freshness requirements explicitly.

Replica lag is a separate problem

Freshness and plan quality are independent. AWS’s RDS for PostgreSQL documentation describes native PostgreSQL replication to read-only replicas. It also notes that the reported lag value can climb to five minutes when no transactions run on the source, because the default WAL segment switch interval is five minutes. That is documented reporting behavior for that product, not a guarantee of how stale your data really is.

Aurora works differently. Aurora replicas share a cluster volume with the writer, and ReplicaLag refers to the reader’s page-cache lag relative to the writer. AWS describes it as usually much less than 100 milliseconds. Treat that as a description, not a promise, because workload and write rate affect it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choosing among the real options

Option Use it when Compare on
Query, statistics, schema or index changes The plan shows excess work in this statement Actual vs. estimated rows, latency, write overhead, storage, effect on other statements
Read replicas The limit is aggregate read throughput or contention on the source Capacity gained, routing and application changes, lag, freshness tolerance, operating cost
Plan stability controls A plan regressed after a change such as new statistics or a version upgrade Control gained vs. the feature’s maintenance and version constraints
Larger instance or a different architecture The plan is reasonably efficient but CPU, memory or I/O is the limit, or the workload suits another system Workload-specific measurements; no universal threshold is established

Replica count is not a measure of query efficiency. Ten replicas running a bad plan are ten places to run it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When plan regression is the actual problem

Sometimes a query was fine and then got worse. AWS defines plan regression as the optimizer choosing a less optimal plan after an environmental change, such as changed statistics or a PostgreSQL version change. Aurora PostgreSQL query plan management can constrain the optimizer to a set of known plans. It is a proprietary Aurora capability with its own supported statements and configuration requirements, so check the current AWS documentation before relying on it. It does not apply to vanilla PostgreSQL or other vendors.

A practical rule

If one execution is slow, fix the plan. If many acceptable executions together overload the source, add read capacity. If both are true, fix the plan first. A replica then multiplies efficient work instead of expensive work.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.