How does database replication work?

In short
Database replication keeps copies of the same data on several database servers. One server accepts writes, and the others receive every change so they stay in step. This lets a backup take over when the main server fails, or lets several servers share read traffic. The main trade-off is between safety and speed.
What replication is for
A database server stores your data and answers queries. Sometimes one machine is not enough. You may want a second server ready to take over if the first one fails. You may also want several machines to answer read requests so the load is spread out. Replication is the set of techniques that makes this possible by keeping copies of the same data in sync.
The PostgreSQL documentation on high availability explains the core problem. Read-only copies are easy to add. Once writes come into the picture, things get harder. A write made on one server must reach every other server, so that later reads return consistent results no matter which server answers. That synchronization step is the hard part, and there is no single method that removes its cost in every case. This is why several approaches exist, each trading off something different.
Primary and standby servers
Most replication setups use roles. The server that accepts changes is the primary. It may also be called the master or read/write server. The other servers track the changes made on the primary. They are called standby or secondary servers.
The documentation describes two kinds of standby. A warm standby cannot accept client connections until it is promoted to become a primary. A hot standby accepts connections and can serve read-only queries while it follows the primary. A hot standby is useful for read load, while a warm standby mainly waits as a safety copy.
When the primary fails, a standby can be promoted and take over the writes. This is the basic idea behind failover.
Synchronous and asynchronous replication
The most important choice is how a commit is confirmed. A commit is the moment a transaction becomes permanent. In synchronous replication, a transaction is not treated as committed until all servers have committed it. In return, a failover should not lose data, and every server returns the same results.
Asynchronous replication allows a short delay between the commit on the primary and its arrival on the other servers. The primary does not wait. This is faster, but a few recent transactions could be lost if the primary fails before they are sent. Standbys can also return slightly old results. Asynchronous replication is typically chosen when waiting for every server would be too slow.
Performance matters here. The documentation notes that a fully synchronous setup over a slow network can cut performance by more than half, while an asynchronous one may have a minimal effect. You have to decide how much data loss you can accept.
Granularity
Replication can also differ in scope. Some solutions copy an entire database server as one unit. Others let you choose at the level of individual tables or whole databases. Finer control gives you flexibility but usually adds configuration work.
Common mistakes
A common mistake is assuming that a standby is a backup in every sense. A replica that follows the primary also copies a bad change, such as an accidental delete. Replication protects against hardware failure, not against user error. You still need separate backups.
Another mistake is sending read traffic to an asynchronous replica and expecting it to match the primary exactly. Read a value right after writing it and you may get the older version. Plan your application for that delay, or send such reads to the primary.
Finally, do not pick synchronous replication only because it sounds safe. Test how much latency it adds on your real network before you commit to it.
Where to start
If you are new to this, first decide what you need: failover, read scaling, or both. Then choose synchronous or asynchronous based on how much data loss and delay you can accept. Read the official PostgreSQL high availability chapter for the exact options and setup steps, since the details differ between solutions.
FAQ
What is the difference between a primary and a standby server?
The primary accepts writes and changes to the data. A standby receives those changes from the primary and keeps its own copy. Standbys can take over as primary if the original one fails.
Does synchronous replication make writes slower?
It can. A transaction waits until every server has committed it, so slow networks add delay. The documentation notes that on a slow network a fully synchronous setup may cut performance by more than half.
Can replication replace backups?
No. Replication copies changes quickly, including mistakes like a dropped table. Keep separate backups so you can recover from errors as well as hardware failures.
Why might a read return old data on a replica?
Asynchronous replication allows a short delay before changes reach other servers. A read sent to a replica during that window can return the previous value.
Sources
This page is based on the official documentation below. Read it for full detail.
Database replication — official documentation ↗Database replication in the news
Pinecone Releases Open Source pg_pinecone Extension for Vector Search in PostgreSQL
Pinecone has released pg_pinecone, an Apache 2.0 licensed PostgreSQL extension that adds its own vector search engine to existing pgvector columns. The company says it applies filters during search rather than after, and reports benchmark results against pgvector's HNSW index.
AlloyDB Omni Can Now Call Local Models Like Gemma 4 Directly From SQL
Google says its AlloyDB Omni PostgreSQL-compatible database now connects to locally hosted large language models such as Gemma 4 and Qwen3.8. The integration lets SQL queries call a model that runs inside the same environment as the data.
pgjumbo Adds Write Previews and Plan Comparison to a New PostgreSQL Client
Benjamin Ibrulj has released pgjumbo, a PostgreSQL client for macOS, Windows and Linux. It shows the likely impact of writes before they run and offers an optional AI assistant built on Claude Code.


