Syntax
Parameters
WITH options
Notes
CREATE CDC TABLErecords metadata only.ALTER CDC TABLE ... ATTACH STREAMnames the stream that feeds the table, and ingestion starts withALTER CDC TABLE ... RESUME. One stream feeds one CDC table.- CDC tables are supported on single-node Engines only.
CREATE CDC TABLEandALTER CDC TABLE ... RESUMEreturn an error on an Engine with more than one node.SUSPEND,ATTACH STREAM, andDETACH STREAMare still accepted, so a CDC table on an Engine that was resized can be stopped and detached. - Merge-key columns are implicitly
NOT NULL. - In
readmode, merge-key columns must beBOOLEAN,INTEGER,BIGINT,DATE,TIMESTAMP,TIMESTAMPTZ,NUMERIC, orTEXT(NUMERIConly as a single-column key). Usemerge_mode = 'write'for other key types. - Column names beginning with
__, andlast_seq, are reserved for CDC bookkeeping. merge_modecannot be changed after creation.- In
readmode, direct DML,TRUNCATE, column-levelALTER TABLE,SET PRIMARY INDEX, and aggregating indexes are rejected; renaming the table is allowed.writetables behave like ordinary tables.
Examples
Mirror a Postgres table
Mirror a MongoDB collection
A MongoDB stream’s columns are always_id and doc, so the table’s are too:
Sort the table for analytics instead of by key
ALTER CDC TABLE
Attaches a stream to a CDC table and controls its ingest worker:-
ATTACH STREAMtakes a stream whose columns match the table’s. Attaching the stream the table was detached from continues where it stopped; attaching a stream that has not loaded a table before reloads the table from that stream’s snapshot on the nextRESUME. A stream that has already loaded a table does not load another one, so mirroring into a new table needs a new stream. -
DETACH STREAMstops the worker and unlinks the stream. The table stays queryable at its last state. -
RESUMEbinds the ingest worker to the Engine that runs the statement and persists the enabled state. A worker that an earlierRESUMEstarted on another Engine stops after the statement it is running finishes (for an initial load, after the whole load) and after any cascade already in progress. After an Engine restart, runRESUMEagain on the Engine where ingestion should continue. The firstRESUMEbackfills the table from a source snapshot before streaming.RESUMEis rejected while the attachment is inerror(see CDC tables); the error includes the recorded reason. -
RESUMErequires a single-node Engine. On an Engine with more than one node it returns an error and starts nothing. -
SUSPENDstops the worker without a final consolidation. For Postgres sources, the idle replication slot retains WAL on the source while suspended. On an attachment inerror,SUSPENDhas no effect; a worker still applying what it had staged continues until it is done.
DROP TABLE
DROP TABLE <table_name> drops a CDC table together with its hidden staging storage and stops its ingest worker. Dropping the table does not drop the stream; see DROP STREAM for source-side cleanup.
Related
- CDC tables: semantics, merge modes, monitoring.
- CREATE STREAM: define the change feed.
information_schema.cdc_ingests: ingest state, progress, and errors.