Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina descrive come attivare l'isolamento delle transazioni negli snapshot dei database Microsoft SQL Server e MySQL nei job di replica di Cloud Data Fusion.
Quando configuri un job di replica per un database, il job acquisisce un'immagine iniziale delle tabelle di origine. Per garantire la coerenza dei dati, applica i blocchi a queste tabelle.
Dopo lo snapshot iniziale, le modifiche incrementali all'origine vengono acquisite e applicate al target BigQuery nell'ambito del processo di replica in corso.
SQL Server
Per acquisire le modifiche nelle tabelle di origine di un database SQL Server, il job di replica utilizza un connettore Debezium. Durante la fase
snapshotting,
Debezium acquisisce i blocchi in base al valore configurato
snapshot.isolation.mode.
La seguente tabella mette a confronto le modalità di isolamento supportate per i job di replica.
Modalità di isolamento
Serrature acquisite
Coerenza dei dati
read_uncommitted
Nessuno
No.
read_committed
Blocchi condivisi su un batch di righe alla volta
Parziale. Un record aggiunto può essere visualizzato due volte: una volta nello snapshot iniziale e una volta nella fase di streaming.
repeatable_read (valore predefinito)
Blocchi condivisi su tutte le righe
Parziale. Un record aggiunto può essere visualizzato due volte: una volta nello snapshot iniziale e una volta nella fase di streaming.
Per impostazione predefinita, la modalità di isolamento degli snapshot è repeatable_read. Questa modalità acquisisce i blocchi condivisi su tutti i dati letti durante la fase di creazione degli snapshot. Impedire ad altre transazioni di modificare le righe esistenti e può potenzialmente consentire l'inserimento di nuovi record (vedi Escalation dei blocchi).
Per acquisire le modifiche nelle tabelle di origine di un database MySQL, il job di replica utilizza un connettore Debezium. Durante la fase
snapshotting,
Debezium acquisisce i blocchi in base al valore configurato
snapshot.locking.mode.
Per impostazione predefinita, la modalità di blocco delle istantanee è minimal. In questa modalità, il connettore detiene il blocco di lettura globale per la parte iniziale dello snapshot mentre legge gli schemi di database e altri metadati. Il connettore recupera quindi tutte le righe tramite una lettura coerente, utilizzando la transazione REPEATABLE READ, che non blocca le tabelle.
Per evitare blocchi, imposta la modalità su none.
In alternativa, per evitare blocchi sui database MySQL in esecuzione su Cloud SQL, esegui la replica dalla replica anziché dal database transazionale.
Modificare il comportamento di blocco durante lo snapshot per MySQL
Per modificare il comportamento di blocco degli snapshot nel database MySQL, imposta l'argomento di runtime, la proprietà snapshot.locking.mode, su un valore appropriato della modalità di blocco.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eThis document details how to manage transaction isolation and locking during the snapshotting phase of replication jobs in Microsoft SQL Server and MySQL databases within Cloud Data Fusion.\u003c/p\u003e\n"],["\u003cp\u003eFor SQL Server, setting the \u003ccode\u003esnapshot.isolation.mode\u003c/code\u003e to \u003ccode\u003esnapshot\u003c/code\u003e provides full data consistency without locking tables, though it requires enabling snapshot isolation in the SQL Server database.\u003c/p\u003e\n"],["\u003cp\u003eSQL Server's default isolation mode \u003ccode\u003erepeatable_read\u003c/code\u003e uses shared locks, potentially allowing duplicate records; alternatively \u003ccode\u003eread_committed\u003c/code\u003e can be used but requires caution against schema changes.\u003c/p\u003e\n"],["\u003cp\u003eIn MySQL, the \u003ccode\u003esnapshot.locking.mode\u003c/code\u003e can be set to \u003ccode\u003enone\u003c/code\u003e to prevent locks, but schema changes during snapshotting should be avoided to ensure consistency, alternatively, you can replicate from the replica instead of the transactional database.\u003c/p\u003e\n"],["\u003cp\u003eOracle source replication via Datastream does not lock tables, ensuring minimal disruption.\u003c/p\u003e\n"]]],[],null,["# Isolation levels in replication\n\nThis page describes how to enable *transaction isolation* in Microsoft SQL\nServer and MySQL database snapshots in Cloud Data Fusion\nreplication jobs.\n\nWhen you set up a replication job for a database, the job takes an\ninitial snapshot of the source tables. To ensure data consistency, place\nlocks on those tables.\n\nAfter the initial snapshot, incremental changes at the source are captured and\napplied to the BigQuery target as part of the ongoing replication\nprocess. \n\n### SQL Server\n\nTo capture changes in the source tables in a SQL Server database, the\nreplication job uses a Debezium connector. During the\n[`snapshotting`](/data-fusion/docs/concepts/replication#table_states) phase,\nDebezium acquires locks according to the configured\n[`snapshot.isolation.mode`](https://debezium.io/documentation/reference/1.3/connectors/sqlserver.html#sqlserver-property-snapshot-isolation-mode).\n\nThe following table compares the supported isolation modes for\nreplication jobs.\n\nFor more information about isolation modes, see\n[Set transaction isolation level](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql).\n\nBy default, the snapshot isolation mode is `repeatable_read`. This mode takes\nshared locks on all data that's read during the snapshotting phase. It\nprevents other transactions from modifying the existing rows, and can\npotentially allow insertion of new records (see\n[lock escalation](https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide?view=sql-server-ver16#lock-escalation)).\n\nReplication with snapshot isolation is recommended if it's already enabled on\nthe source database because it provides full data consistency without locking\nthe tables. If it's not enabled, learn more about the impact of\n[row versioning-based isolation levels in the SQL Server Database Engine](https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide?#Row_versioning)\nbefore you enable it.\n\nAs an alternative, use the `read_committed` isolation mode, which\ndoesn't lock the tables during the snapshotting phase.\n| **Warning:** If you use `read_committed` mode, ensure that no schema changes are applied on the database during the snapshotting phase, as it may cause data inconsistency in replication.\n\nEnable snapshot isolation in a replication job\n----------------------------------------------\n\n1. Enable snapshot isolation in the SQL Server database:\n\n ```\n ALTER DATABASE DATABASE_NAME\n SET ALLOW_SNAPSHOT_ISOLATION ON\n ```\n\n Replace \u003cvar translate=\"no\"\u003eDATABASE_NAME\u003c/var\u003e with the name of the SQL Server\n database.\n2. Set the runtime argument `snapshot.isolation.mode` to `snapshot`. For more\n information, see\n [Pass a runtime argument to a replication job](/data-fusion/docs/how-to/pass-runtime-args-in-replication).\n\n### MySQL\n\nTo capture changes in the source tables in a MySQL database, the\nreplication job uses a Debezium connector. During the\n[`snapshotting`](/data-fusion/docs/concepts/replication#table_states) phase,\nDebezium acquires locks according to the configured\n[`snapshot.locking.mode`](https://debezium.io/documentation/reference/1.3/connectors/mysql.html#mysql-property-snapshot-locking-mode).\n\nBy default, the snapshot locking mode is `minimal`. In this mode, the\nconnector holds the global read lock for the initial portion of the snapshot\nas it reads the database schemas and other metadata. Then the connector\nfetches all rows through a consistent read, using the `REPEATABLE READ`\ntransaction, which doesn't lock the tables.\n\nTo prevent any locks, set the mode to `none`.\n| **Warning:** If you use `none`, ensure that no schema changes are applied on the database during the snapshotting phase, as it may cause data inconsistency in replication.\n\nAs an alternative, to prevent locks on MySQL databases running on\nCloud SQL, replicate from the\n[Replica](https://debezium.io/documentation/reference/1.3/connectors/mysql.html#mysql-supported-topologies_debezium)\ninstead of the transactional database.\n\nChange the locking behavior during the snapshot for MySQL\n---------------------------------------------------------\n\n- To change snapshot locking behavior in the MySQL database, set the runtime argument, `snapshot.locking.mode` property, to an appropriate [locking mode](https://debezium.io/documentation/reference/1.3/connectors/mysql.html#mysql-property-snapshot-locking-mode) value.\n\n| **Note:** Tables defined with the MyISAM engine continue to be locked despite the property being set to `none`.\n\nFor more information, see [Pass a Debezium argument to a replication job](/data-fusion/docs/how-to/pass-runtime-args-in-replication#debezium-arguments).\n\nLimitations\n-----------\n\n- Replication in Cloud Data Fusion supports Debezium Connector version 1.3.\n\nOracle sources in Cloud Data Fusion\n-----------------------------------\n\nReplication from Oracle sources in Cloud Data Fusion is powered by\nDatastream. Datastream [doesn't lock tables](/datastream/docs/faq#general-source).\n\nWhat's next\n-----------\n\n- Learn more about [Replication](/data-fusion/docs/concepts/replication)."]]