Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Databases 18 min read

Physical vs Logical Replication: How Chinese Databases Handle Master-Slave Sync

The article compares physical and logical replication for database master-slave synchronization, detailing their mechanisms, trade-offs in consistency, latency, flexibility, and compatibility, and examines how major Chinese domestic databases such as GoldenDB, TDSQL, openGauss, GaussDB, OceanBase, TiDB, and Dameng implement each approach, with a summary table.

1. Database Replication Basic Concepts

Database master-slave replication is a critical technique for achieving financial-grade high availability. By maintaining identical data copies across multiple nodes, the system remains operational even if a node fails. Replication can be classified by synchronization mode (synchronous, semi-synchronous, asynchronous), direction (unidirectional, bidirectional), and implementation level (storage-level, database-level). This article focuses on the two primary database-level approaches: physical replication and logical replication.

2. Physical Replication

2.1 Definition and Benefits

Physical replication, also called binary or streaming replication, sends the database's physical files (data files, log files) or their changes (e.g., binary log entries) byte-by-byte from the master to the slave. The slave applies these changes to maintain physical-level consistency. Key benefits:

High data consistency : Master and slave remain consistent at the physical layer, meeting financial-grade reliability requirements without logical-level discrepancies.

Low latency : Redo records generated during transaction execution are applied to the standby in real time; data is visible immediately after commit.

High replication efficiency : Copying at the physical block level achieves higher throughput than executing SQL statements.

2.2 PostgreSQL Example

In PostgreSQL, DML/DDL operations generate WAL (Write-Ahead Log) records. The wal sender process on the primary streams these records to the standby's wal receiver, which writes them to local WAL. The startup process then reads and applies the WAL to the standby database.

PostgreSQL streaming replication architecture
PostgreSQL streaming replication architecture

Before PostgreSQL 9.0, the primary shipped whole WAL files only after they were filled, causing high replication lag. Version 9.0 introduced streaming replication , allowing the standby to fetch WAL records nearly in real time.

2.3 Limitations of Physical Replication

Data page corruption : Physical file copying can propagate disk errors or file read/write failures, leading to corrupted data on the standby.

Instance-level only : Cannot filter at the table or logical object level (e.g., exclude certain DDL operations from replication).

Version/OS compatibility : Replication across different database versions or operating systems may encounter compatibility issues, especially during upgrades.

3. Logical Replication

3.1 Definition and Characteristics

Logical replication operates at the SQL layer, parsing and replicating logical changes such as INSERT, UPDATE, DELETE statements. Characteristics:

High flexibility : Can selectively replicate specific tables or operations without replicating the entire instance.

Heterogeneous database sync : Because it works with logical SQL operations, it enables synchronization between different database systems.

Potential latency : Parsing and transforming SQL statements introduces overhead; large transactions or limited standby performance can cause replication lag.

3.2 MySQL Example

On the master, committed changes are written to the binary log ( binlog). The slave's I/O thread connects to the master, reads the binlog, and writes events to a local relay log. The slave's SQL thread then reads the relay log and applies each event to the slave database.

MySQL logical replication architecture
MySQL logical replication architecture

Logical replication may suffer delays due to network I/O, large transactions, standby performance bottlenecks, or high concurrency. However, in high-concurrency scenarios the binlog typically reaches the standby, achieving RPO = 0 (zero data loss potential).

4. Physical vs Logical Replication: Detailed Comparison

Comparison of physical and logical replication characteristics
Comparison of physical and logical replication characteristics

Data consistency : Physical replication guarantees high consistency at the block level. Logical replication, being SQL-based, can encounter inconsistencies such as primary key conflicts or data loss; manual repair of the standby is required when discrepancies arise.

Replication efficiency : Physical replication is faster because it copies data files directly, whereas logical replication must execute many SQL statements.

Data file integrity : Physical replication risks file corruption during transfer; unreadable files on the standby require repair or re-transfer.

Compatibility : Physical replication faces version and OS compatibility challenges. Logical replication, redoing SQL, avoids these issues.

Flexibility : Logical replication allows custom SQL and selective replication strategies (e.g., exclude certain tables or statement types).

Replication latency : Logical replication latency is influenced by network I/O, standby performance, and high-concurrency write workloads. Physical replication latency mainly depends on network and standby performance.

Additional limitations: PostgreSQL logical replication cannot synchronize DDL, sequences, or large objects. Physical replication standbys are read-only and may conflict with logical replication or backup operations.

5. Replication Implementations in Chinese Domestic Databases

5.1 MySQL-Compatible Databases (Logical Replication)

GoldenDB

TDSQL for MySQL

These databases use MySQL-compatible storage engines and implement master-slave replication via logical replication based on binlog parsing and synchronization.

5.2 PostgreSQL-Compatible Databases (Physical Replication)

openGauss

GaussDB (for openGauss)

These leverage native PostgreSQL capabilities, using WAL-based physical replication for master-slave synchronization.

5.3 OceanBase (Physical Replication via Paxos)

OceanBase employs a Paxos-based multi-replica architecture. Data is partitioned and replicated across replicas via log synchronization. RedoLog ensures transactionality : at commit, Paxos synchronizes RedoLog to a majority of nodes. Each replica (including the leader) votes after persisting the log; once a majority acknowledges, the transaction commits on the leader. Followers replay the received log operations. Paxos guarantees that even if the leader fails, a new leader can be elected from the majority with complete logs, ensuring high availability and consistency. This constitutes physical replication.

5.4 TiDB (Physical Replication via Raft + Logical Replication via TiCDC)

TiDB uses the Raft consensus protocol for intra-cluster replication. Each Region has multiple replicas with a single leader. Write flow:

Leader writes the operation to its Region Raft Log and sends it in parallel to all followers.

Followers persist the operation to their logs and acknowledge.

Upon receiving a majority of acknowledgments, the leader applies the operation to its state machine and responds success to the client.

Leader notifies followers to apply the operation to their state machines.

Thus, intra-region replication is physical. For cross-cluster high availability, TiDB uses TiCDC , which pulls change logs from upstream TiKV, parses them into ordered row-level changes, and outputs to downstream systems. TiCDC monitors each Region's Raft Log and generates change events from before/after data differences. It guarantees equivalence to upstream changes but does not reconstruct the exact original SQL. TiCDC-based replication is logical and has limitations: unsupported DDL (e.g., CREATE SEQUENCE), and no restore/import operations on synchronized tables during replication.

TiCDC cross-cluster replication architecture
TiCDC cross-cluster replication architecture

5.5 Dameng Database (Physical Replication with Two Modes)

Dameng's master-standby setup consists of master, standby, guardian process, and monitor. DM Data Guard ships Redo logs from master to standby, where they are reapplied. The guardian monitors synchronization status and handles exceptions.

Dameng Data Guard architecture
Dameng Data Guard architecture

Two synchronization modes:

Real-time mode (high performance) : Master sends Redo logs ( RLOG_PKG) to standby before writing to its online log file. Standby marks them as KEEP_PKG, immediately queues them for replay, and responds without waiting for replay completion. Master writes to its online log only after receiving standby's acknowledgment.

Instant mode (high reliability) : Master first writes Redo logs to its online log file, then transmits via the MAL system. Standby archives immediately and replies only after replay finishes. This ensures the standby's Redo log never exceeds the master's, guaranteeing transaction-level consistency.

6. Summary

Physical and logical replication are not mutually exclusive; each has distinct advantages and suitable scenarios. MySQL-compatible databases favor logical replication, while PostgreSQL-compatible and many distributed databases (like Oracle-style systems) use physical replication. Regardless of the method, the ultimate goal is to ensure data consistency between master and standby while meeting high replication performance and low latency requirements.

Summary Table of Domestic Databases

Dameng (centralized): intra-cluster physical replication; cross-cluster not specified.

OceanBase (distributed): intra-cluster physical replication; cross-cluster physical replication.

GoldenDB (distributed): intra-cluster logical replication; cross-cluster logical replication.

TDSQL for MySQL (distributed): intra-cluster logical replication; cross-cluster logical replication.

openGauss (centralized): intra-cluster physical replication; cross-cluster physical replication.

GaussDB (for openGauss) (distributed): intra-cluster physical replication; cross-cluster physical replication.

TiDB (distributed): intra-cluster physical replication (Raft); cross-cluster logical replication (TiCDC).

References:
https://www.modb.pro/db/52463
https://blog.csdn.net/Laugh_xiaoao/article/details/127033658
https://docs.pingcap.com/zh/tidb/stable/ticdc-overview
About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

MySQLPostgreSQLDatabase Replicationdistributed databasesPhysical ReplicationLogical ReplicationChinese Domestic DatabasesMaster-Slave Synchronization

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion