What is a transaction log? WAL, binlog, and oplog explained
A database changes a row in memory, acknowledges the transaction, and writes the page to disk later. If the server loses power between those steps, how does it recover the committed change?
The answer is a log. PostgreSQL has WAL. MySQL uses an InnoDB redo log for recovery and a binary log for replication. MongoDB replica sets have an oplog, while WiredTiger keeps a journal for recovery.
These logs record different information for different jobs. The difference determines what a CDC consumer can read, how it tracks progress, and how long the source can retain unread changes.
Recovery logs and replication logs
Crash-recovery logs follow the write-ahead rule: flush the recovery information before the related data page reaches durable storage. After a crash, the database replays that log from a checkpoint. PostgreSQL WAL, the InnoDB redo log, and the WiredTiger journal serve this purpose.
Replication logs carry changes to other servers or external consumers. MySQL replicas read the binary log. MongoDB replica-set members copy and apply oplog entries.
PostgreSQL uses WAL for both jobs. It supports crash recovery, physical replication, and logical decoding from the same log. MySQL and MongoDB split recovery and replication across separate logs, so a CDC reader does not necessarily consume the crash-recovery log.
PostgreSQL Write-Ahead Log
For WAL-logged relations, PostgreSQL records the recovery information needed for a changed data page before that page reaches durable storage. Temporary and unlogged relations follow different durability rules.
WAL files live in pg_wal. A segment is 16 MB by default, and initdb --wal-segsize can select another size when the cluster is created.
Log Sequence Numbers
PostgreSQL represents a WAL position with a Log Sequence Number (LSN). An LSN is a 64-bit byte position displayed as two hexadecimal numbers separated by a slash:
SELECT pg_current_wal_lsn();
-- 16/B374D848
Subtracting one LSN from another returns the number of WAL bytes between them. Monitoring systems use that difference to report lag in bytes.
wal_level
wal_level controls how much information PostgreSQL records:
minimalrecords enough for crash recovery but cannot support WAL archiving or replication.replicais the default. It adds the information required for archiving and physical replication.logicaladds the information required for logical decoding. PostgreSQL 14 through 18 require this level for Remac's logical source path.
Each level contains the information from the levels below it. Workload and replica-identity settings determine how much extra WAL the logical level produces.
CDC access
Remac's Logical CDC path requires wal_level = logical, a logical replication slot, a publication, and a logical replication connection. It uses pgoutput, PostgreSQL's standard logical-decoding output plugin.
An illustrative publisher configuration is:
wal_level = logical
max_replication_slots = 4 # logical consumers plus operational reserve
max_wal_senders = 4 # concurrent replication connections
Size both limits for the actual number of logical consumers, table-synchronization workers, physical replicas, and reconnect headroom. A replication slot can retain WAL indefinitely unless an operator sets and monitors a limit.
MySQL binary log
The binary log supports replication and point-in-time recovery after a backup. InnoDB's redo log handles storage-engine crash recovery.
For transactional tables, MySQL caches changes until COMMIT, writes the transaction to the binary log, and coordinates the binary log with the InnoDB commit. The binary log contains statements or row changes rather than physical page mutations.
File positions and GTIDs
A file position identifies a binary-log filename and byte offset, such as mysql-bin.000003 at position 4578. That position belongs to one server's sequence of binary-log files, so failover and topology changes require careful position handling.
A Global Transaction Identifier identifies a transaction independently of one filename and offset. It combines the originating server UUID with a transaction number:
7d73b822-75e1-11ef-a4da-4455e16762b4:553
GTIDs simplify position tracking when replicas can be promoted or reconfigured.
Row format and row images
MySQL 8.4 supports statement, row, and mixed binary logging. Row format is the default and the usual choice for row-level CDC.
binlog_row_image controls the columns included in row events:
FULLis the default. It records all columns in the applicable before and after images.MINIMALrecords the columns needed to identify the row in the before image and the changed columns in the after image.NOBLOBbehaves likeFULLbut omits unchangedBLOBandTEXTcolumns that are not needed to identify rows or have not changed.
A CDC consumer that needs complete row state requires FULL. Consumers with narrower requirements can support MINIMAL or NOBLOB, but they must handle missing columns explicitly.
MongoDB oplog
The oplog is MongoDB's replication log. WiredTiger uses a separate journal to recover writes made after the latest checkpoint.
The oplog is a capped collection named local.oplog.rs. Its default size depends on the platform and storage engine. WiredTiger uses 5 percent of free disk space on most Unix and Windows systems, with documented minimum and maximum defaults; 64-bit macOS uses a fixed 192 MB default. Operators can resize it.
Oplog operations are idempotent: applying one operation more than once produces the same target state. Because the oplog is finite, a consumer that falls behind the oldest retained entry must resynchronize.
Oplog timestamps and resume tokens
Each oplog entry has a ts value containing seconds since the Unix epoch and an increment that orders entries within the same second. A direct oplog reader can use that timestamp to track its position.
Applications using change streams should persist the opaque resume token in each event's _id field. Resuming also requires enough oplog history to locate the event or requested timestamp.
Change streams and direct oplog reads
Change streams provide MongoDB's application-facing change API. They can watch a collection, database, replica set, or sharded deployment and can filter events through an aggregation pipeline.
Direct oplog reading exposes MongoDB's internal replication records. A consumer must handle privileges, topology changes, parsing, and resume behavior itself.
Change streams require a replica set or sharded cluster. A standalone deployment does not provide the same replication and change-stream path, although WiredTiger still uses its journal for crash recovery.
How the logs differ
| PostgreSQL WAL | MySQL binary log | MongoDB oplog | |
|---|---|---|---|
| Primary role | Crash recovery and replication | Replication and PITR | Replication |
| Crash-recovery log | WAL | InnoDB redo log | WiredTiger journal |
| Format | PostgreSQL WAL records | Statement, row, or mixed binary events | BSON documents |
| Position | LSN | File offset or GTID | Oplog timestamp |
| Application-facing CDC path | Logical decoding through pgoutput | Row-based binary-log parsing | Change streams |
| Core configuration | wal_level = logical | binlog_format = ROW; row-image policy depends on the consumer | Replica set or sharded cluster |
CDC depends on the source log and position model
A native change log can expose deletes, source positions, ordering, and transaction metadata that table polling often loses. The result still depends on source configuration, selected operations, row-image settings, retention, and the consuming protocol.
The source adapter must use the correct log and position model. Treating a MySQL binary-log offset, PostgreSQL LSN, and MongoDB resume token as interchangeable would break recovery and replay.
For the broader processing model, see What is transaction log processing. The PostgreSQL-specific details continue in PostgreSQL WAL: how it works.
We built Remac with database-independent contracts in the processing core and native behavior at the source edge. PostgreSQL is the first implemented source. MySQL, MongoDB, and Oracle are planned.