DataGrip Schema Synchronization Missing Exclusive Metadata Lock Option
0 reputation · 07 Nov 2021, 08:41 UTC
0 reputation · 07 Nov 2021, 08:41 UTC
DataGrip's Schema Synchronization wizard generates SQL scripts that can run inside a transaction and leverage online DDL hints such as ALGORITHM=INPLACE for MySQL or CONCURRENTLY for PostgreSQL. This enables structural changes with minimal blocking for read and write workloads.
However, the tool does not automatically acquire a short‑term exclusive metadata lock before executing the script, nor does it surface a configuration toggle to request one. It also provides no warning when another session holds or requests a conflicting DDL lock on the same objects during synchronization.
Without an explicit lock acquisition step or a guardrail setting, the generated script may wait indefinitely for a metadata lock or fail mid‑run if a concurrent ALTER TABLE executes in parallel. This behavior is version‑dependent: MySQL 5.6+ and PostgreSQL 12+ support non‑blocking DDL, but older versions or SQL Server still require full table locks that DataGrip does not detect.
Is there a supported way to configure DataGrip to prepend an explicit LOCK TABLES or pg_advisory_xact_lock call before the synchronization script runs? Does the IDE expose any hidden option under Tools → Database → Data Extractors and Synchronization → Options to enable automatic metadata lock acquisition? How can a team verify that the generated script will not contend with concurrent DDL in a production environment without a maintenance window?
No. DataGrip does not provide a supported setting to prepend an explicit LOCK TABLES, pg_advisory_xact_lock or equivalent metadata lock before a Schema Synchronization script, and there is no hidden toggle under Tools → Database → Data Extractors and Synchronization → Options to enable automatic metadata lock acquisition.
ALGORITHM=INPLACE and PostgreSQL CONCURRENTLY, and can wrap the script in BEGIN/COMMIT via the "Wrap in transaction" option.DataGrip is a schema design and DDL generation tool. Lock orchestration and serialization are deliberately left to the database engine and to deployment tooling. Adding an IDE-level lock would be engine-specific, risk breaking transactional semantics, and would not prevent a concurrent session from starting DDL after the lock is released.
LOCK TABLES or advisory lock calls.SHOW ENGINE INNODB STATUS and performance_schema.metadata_locks, PostgreSQL pg_locks and pg_stat_activity, SQL Server sys.dm_tran_locks. This shows actual metadata lock waits.SELECT pg_advisory_xact_lock(id) for PostgreSQL, or use a maintenance window / blue-green deployment. DataGrip scripts can be edited before execution.To give a precise recommendation for a safe deployment pattern, what database engine and DataGrip build are you using? The available native locking primitives and the exact Options UI differ by engine and version.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 07 Nov 2021, 19:27 UTC
Since DataGrip does not natively inject lock orchestration into the synchronization wizard, the most reliable safeguard is leveraging the SQL Preview window. Because the IDE generates the script before execution, you can manually prepend dialect-specific lock commands to the script body.
pg_advisory_xact_lock() within the transaction block can prevent concurrent DDL conflicts without locking the entire table for reads.LOCK TABLES is an option, it is often safer to set a session-level lock_wait_timeout (e.g., SET session lock_wait_timeout = 5;) at the start of the script. This prevents the synchronization from hanging indefinitely and blocking other production queries.Note that if you are using CREATE INDEX CONCURRENTLY in PostgreSQL, you must ensure the script is executed outside of a transaction block, as PostgreSQL prohibits this specific operation within one.