Quick revision
The short answer
Long queries on the primary hold back the xmin horizon and compete with production for buffers, CPU and I/O, so we would not allow them there. PostgreSQL offers hot standby replicas, where long queries either get cancelled by recovery conflicts or, with hot_standby_feedback, push bloat back to the primary; a dedicated reporting replica with relaxed conflict settings that accepts replay lag; and logical replication or CDC into a separate analytical store. For a company with 200 services, we would make a CDC pipeline into a warehouse the standard, with a reporting replica as a stopgap.
What to remember
In this answer, we saw that 30-minute queries on the primary hold back the xmin horizon and compete with production for buffers, CPU and I/O. Hot standbys move the load but either cancel long queries through recovery conflicts or, with hot_standby_feedback, move the bloat back to the primary. A dedicated reporting replica with relaxed conflict settings isolates the primary at the cost of lag, and logical replication or CDC into a warehouse separates analytics completely. For 200 services, CDC into a warehouse is the scalable standard, with a reporting replica as a bridge.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Long queries on the primary hold back the xmin horizon and compete with production for buffers, CPU and I/O, so we would not allow them there. PostgreSQL offers hot standby replicas, where long queries either get cancelled by recovery conflicts or, with hot_standby_feedback, push bloat back to the primary; a dedicated reporting replica with relaxed conflict settings that accepts replay lag; and logical replication or CDC into a separate analytical store. For a company with 200 services, we would make a CDC pipeline into a warehouse the standard, with a reporting replica as a stopgap.
Why this question is asked
Every company reaches the point where analysts want direct access to production data, and every product team worries about what that does to their database. Both sides are right, and the answer depends on how fresh the data must be, how much querying there is, and what it costs to run. Interviewers ask this scenario to see whether we know the options PostgreSQL offers, what each one really costs, and how the choice changes at company scale. In this answer, we will see why the primary is the wrong place, compare hot standbys, a dedicated reporting replica and CDC into a warehouse, and choose for 200 services.
1Why Not the Primary
A 30-minute query holds a snapshot for 30 minutes. While it runs, vacuum on the primary cannot remove row versions deleted after it started, in any table of that database. With dozens of such queries a day, busy tables never get fully cleaned and bloat steadily.
The query also competes for resources. A large scan pulls pages into shared_buffers and the operating system cache, pushing out the hot pages that user requests depend on, and it uses CPU and disk bandwidth that the services need. So user-facing latency rises exactly while the analysts work. Neither problem is a bug we can configure away; they follow from sharing one database between two workloads.
2Option 1: Hot Standby Replicas
A hot standby is a physical replica that replays the primary's WAL and accepts read-only queries. Moving the analysts there removes the CPU and buffer competition from the primary. But a new problem appears: recovery conflicts. When the primary's vacuum removes row versions that a long standby query still needs, replay on the standby has to either wait or cancel the query.
Two settings choose between the bad outcomes. max_standby_streaming_delay sets how long replay waits before cancelling, 30 seconds by default; raising it lets queries finish, but the replica falls behind. hot_standby_feedback makes the standby report its oldest snapshot to the primary, so the primary keeps those versions and nothing gets cancelled, but then the primary bloats again, as if the query ran there.
3Option 2: A Dedicated Reporting Replica
If replicas that serve the applications must stay fresh, we add one replica only for reporting. On it we accept lag: max_standby_streaming_delay is set high, perhaps 30 minutes or -1 (never cancel), and hot_standby_feedback stays off, so the primary is not affected. During a long query, replay pauses and the reporting replica may be up to 30 minutes behind, which is usually fine for analysts.
This is cheap and quick to set up, and the analysts keep using SQL on familiar tables. Its limits show at scale: it is still a row store, so the 30-minute queries stay 30 minutes, it needs one replica per source database, and its schema is the production schema, which changes whenever a service team deploys.
4Option 3: Logical Replication or CDC Into a Warehouse
The most complete separation copies changes out of the production databases into a separate analytical system. PostgreSQL logical replication can publish selected tables to another PostgreSQL instance. CDC tools such as Debezium read the WAL through a logical replication slot and stream changes, usually through Kafka, into a warehouse with columnar storage. The analytical side can have its own schema, combine data from many services, keep history, and run 30-minute queries in seconds.
The costs are a pipeline to operate, replication slots to monitor (an abandoned slot keeps WAL on the primary forever), schema changes to coordinate with source teams, and freshness measured in minutes rather than milliseconds.
| Option | Effect on primary | Freshness | Main cost |
|---|---|---|---|
| Query the primary | bloat and resource contention | real time | user latency |
| Shared hot standby | bloat if feedback is on | seconds | cancelled queries |
| Dedicated reporting replica | none | seconds to 30 min lag | a replica per database |
| CDC into a warehouse | a replication slot | about 1 to 15 minutes | pipeline and contracts |
5Choosing for 200 Services
For one or two databases, a dedicated reporting replica is often the pragmatic answer. For 200 services the picture changes. Analysts need data from many services together, which replicas cannot join. Running a reporting replica per database multiplies cost and on-call work. And the production schemas change constantly. So we would make CDC into a warehouse the standard: each service publishes the tables analysts need through a data contract, a shared pipeline lands them in the warehouse, and curated models give everyone the same definitions.
While the pipeline is built, a reporting replica for the two or three most requested databases buys time. The deciding factors stay explicit: how fresh the data must be, how many queries run and how heavy they are, and what each option costs to run.
- Only a few databases and modest volume?YesDedicated reporting replicaNoContinue
- Need joins across many services or history?YesCDC into a warehouseNoReporting replica per database
- Fresher than about 5 minutes needed?YesOperational read model or replica for that caseNoWarehouse is enough
- Never: long queries on the primary
4 steps in order. Play them, or step through them one at a time.
6Follow-up questions
What would you tell an analyst who needs data fresher than 5 minutes?
First, I would ask what decision depends on that freshness, because many requests for real time turn out to be satisfied by 5 or 15 minutes. If the need is real, a well-tuned CDC pipeline can usually deliver changes within a minute or two into a store built for it, such as a real-time analytics engine. For a narrow operational view, such as current open orders, a read model or a short query on a reporting replica may be the right tool. What I would not do is give long-running access to the primary.
Can logical replication replace Debezium here?
For copying tables into one reporting PostgreSQL, yes, and it is built in. For feeding a warehouse from 200 services, a CDC platform adds connectors, schema change handling and a Kafka stream other consumers can reuse.
How do you protect the primary from the CDC pipeline itself?
Monitor every replication slot's retained WAL, set max_slot_wal_keep_size so an abandoned slot cannot fill the disk, and alert when a connector stops. Initial snapshots of large tables should be scheduled or taken from a replica where the tool supports it.
7Conclusion
In this answer, we saw that 30-minute queries on the primary hold back the xmin horizon and compete with production for buffers, CPU and I/O. Hot standbys move the load but either cancel long queries through recovery conflicts or, with hot_standby_feedback, move the bloat back to the primary. A dedicated reporting replica with relaxed conflict settings isolates the primary at the cost of lag, and logical replication or CDC into a warehouse separates analytics completely. For 200 services, CDC into a warehouse is the scalable standard, with a reporting replica as a bridge.
Open with
I would not let 30-minute queries run on the primary. They hold a snapshot the whole time, so vacuum cannot clean up anything deleted after they started, in any table, and they compete with production for shared buffers, CPU and I/O, so users feel it.
Then, if they want more
PostgreSQL gives us a few alternatives. A hot standby moves the load off the primary, but long queries there get cancelled by recovery conflicts when replay needs to remove rows they still read, unless we raise max_standby_streaming_delay, which adds lag, or turn on hot_standby_feedback, which moves the bloat back to the primary.
A dedicated reporting replica with relaxed conflict settings and feedback off is a good compromise: the primary is isolated and analysts accept some lag. The fullest separation is logical replication or CDC with something like Debezium into a warehouse, which also lets analysts join data across services, keep history and use a schema designed for analysis.
For a company with 200 services, I would choose CDC into a warehouse as the standard, with data contracts per service, because one replica per database does not scale and analysts need cross-service data.
I would use a reporting replica for the most requested databases as a stopgap while the pipeline is built, and decide each case on freshness, query volume and cost.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Analysts want to run 30-minute queries against the production primary, and the product...": https://scrivio-interview-library.netlify.app/databases/postgresql/de115054c1/