Updated on 2024-12-18 GMT+08:00

Lock Management

In GaussDB(DWS), concurrent transactions may cause single-node deadlocks or distributed deadlocks due to resource competition. This section describes parameters used for managing transaction lock mechanisms.

deadlock_timeout

Parameter description: Specifies the time, in milliseconds, to wait on a lock before checking whether there is a deadlock condition. When the applied lock exceeds the preset value, the system will check whether a deadlock occurs.

  • The check for deadlock is relatively expensive. Therefore, the server does not check it when waiting for a lock every time. Deadlocks do not frequently occur when the system is running. Therefore, the system just needs to wait on the lock for a while before checking for a deadlock. Increasing this value reduces the time wasted in needless deadlock checks, but slows down reporting of real deadlock errors. On a heavily loaded server, you may need to raise it. The value you have set needs to exceed the transaction time. By doing this, the possibility that a lock will be released before the waiter decides to check for deadlocks will be reduced.
  • When log_lock_waits is set, this parameter also determines the duration you need to wait before a log message about the lock wait is issued. If you are trying to investigate locking delays, you need to set this parameter to a value smaller than normal deadlock_timeout.

Type: SUSET

Value range: an integer ranging from 1 to 2147483647. The unit is millisecond (ms).

Default value: 1s

ddl_lock_timeout

Parameter description: Indicates the number of seconds a DDL command should wait for the locks to become available. If the time spent in waiting for a lock exceeds the specified time, an error is reported. This parameter is supported only by clusters of version 8.1.3.200 or later.

Type: SUSET

Value range: an integer ranging from 0 to INT_MAX. The unit is millisecond (ms).

  • If the value of this parameter is 0, this parameter does not take effect.
  • If the value of this parameter is greater than 0, the lock wait time of DDL statements is the value of this parameter, and the lock wait time of other locks is the value of lockwait_timeout.

Default value: 0

This parameter has a higher priority than lockwait_timeout and takes effect only for AccessExclusiveLock.

ddl_select_concurrent_mode

Parameter description: Specifies the concurrency mode of DDL and SELECT statements. This parameter is supported only by clusters of version 8.1.3.320, 8.2.1, or later.

Type: SUSET

Value range: a string

  • none: DDL and select statements cannot be executed concurrently. Waiting statements are in the lock wait state.
  • truncate: When the TRUNCATE statement is blocked by the SELECT statement, the SELECT statement is interrupted and the TRUNCATE statement is executed first.
  • exchange: When the EXCHANGE statement is blocked by the SELECT statement, the SELECT statement is interrupted and the EXCHANGE statement is executed first.
  • vacuum_full: When the vacuum_full statement is blocked by the SELECT statement, the SELECT statement is interrupted and the vacuum_full statement is executed first. This is supported only by clusters of version 9.1.0.200 or later.
  • insert_overwrite: When the insert_overwrite statement is blocked by the SELECT statement, the SELECT statement is interrupted and the insert_overwrite statement is executed first. This is supported only by clusters of version 9.1.0.200 or later.

Default value: none

  • To reserve time for the SELECT statement to respond to signals, if the value of ddl_lock_timeout is less than 1 second in the current version, 1 second is used.
  • Concurrency is not supported when there are conflicts with locks of higher levels (more than one level). For example, autoanalyze is triggered by SELECT when autoanalyze_mode is set to normal.
  • This parameter allows for SELECT statements in either a single statement or a transaction block. However, in other versions, it only supports SELECT statements in a single statement. For concurrent SELECT operations in a single statement or transaction block, learn more information in the description of parameter enable_cancel_select_in_txnblock.
  • Values other than none can be used together. For example, if this parameter is set to truncate, exchange, the TRUNCATE and EXCHANGE statements are blocked by the SELECT statement. The SELECT statement is interrupted and executed first.

enable_cancel_select_in_txnblock

Parameter description: Specifies whether the SELECT statement in a transaction block can be interrupted. This parameter is supported only by clusters of version 8.2.1, 9.1.0.200, or later.

Type: USERSET

Value range: Boolean

  • on indicates that the select operation in the transaction block can be interrupted.
  • off indicates that the select operation in the transaction block cannot be interrupted.

Default value: on

  • This parameter controls whether the SELECT statement in a transaction block can be interrupted by the DDL operation specified in ddl_select_concurrent_mode.
  • The ddl_select_concurrent_mode parameter controls DDL statements such as TRUNCATE and EXCHANGE, and the enable_cancel_select_in_txnblock parameter controls SELECT statements.

lockwait_timeout

Parameter description: Specifies the longest time to wait before a single lock times out. If the time you wait before acquiring a lock exceeds the specified time, an error is reported.

Type: SUSET

Value range: an integer ranging from 0 to INT_MAX. The unit is millisecond (ms).

Default value: 20 min

update_lockwait_timeout

Parameter description: sets the maximum duration that a lock waits for concurrent updates on a row to complete when the concurrent update feature is enabled. If the time you wait before acquiring a lock exceeds the specified time, an error is reported.

Type: SUSET

Value range: an integer ranging from 0 to INT_MAX. The unit is millisecond (ms).

Default value: 2min

max_locks_per_transaction

Parameter description: Controls the average number of object locks allocated for each transaction.

  • The size of the shared lock table is calculated under the condition that a maximum of N independent objects need to be locked at any time. N = max_locks_per_transaction x (max_connections + max_prepared_transactions). Objects that do not exceed the preset number can be locked simultaneously at any time. You may need to increase this value when you modify many different tables in a single transaction. This parameter can only be set at database start.
  • If this parameter is set to a large value, GaussDB(DWS) may require more System V shared memory than the default setting.
  • When running a standby server, you must set this parameter to a value that is no less than that on the primary server. Otherwise, queries will not be allowed on the standby server.

Type: POSTMASTER

Value range: an integer ranging from 10 to INT_MAX

Default value: 256

max_pred_locks_per_transaction

Parameter description: Controls the average number of predicated locks allocated for each transaction.

  • The size of the shared and predicated lock table is calculated under the condition that a maximum of N independent objects need to be locked at any time. N = max_pred_locks_per_transaction x (max_connections + max_prepared_transactions). Objects that do not exceed the preset number can be locked simultaneously at any time. You may need to increase this value when you modify many different tables in a single transaction. This parameter can only be set at server start.
  • If this parameter is set to a large value, GaussDB(DWS) may require more System V shared memory than the default setting.

Type: POSTMASTER

Value range: an integer ranging from 10 to INT_MAX

Default value: 64

partition_lock_upgrade_timeout

Parameter description: Specifies the time to wait before the attempt of a lock upgrade from ExclusiveLock to AccessExclusiveLock times out on partitions.

  • When you do MERGE PARTITION and CLUSTER PARTITION on a partitioned table, temporary tables are used for data rearrangement and file exchange. To concurrently perform as many operations as possible on the partitions, ExclusiveLock is acquired for the partitions during data rearrangement and AccessExclusiveLock is acquired during file exchange.
  • Generally, a partition waits until it acquires a lock, or a timeout occurs if the partition waits for a period of time longer than specified by the lockwait_timeout parameter.
  • When doing MERGE PARTITION or CLUSTER PARTITION on a partitioned table, you need to acquire AccessExclusiveLock during file exchange. If the lock fails to be acquired, the acquisition is retried in 50 ms. This parameter specifies the time to wait before the lock acquisition attempt times out.
  • If this parameter is set to –1, the lock upgrade never times out. The lock upgrade is continuously retried until it succeeds.

Type: USERSET

Value range: an integer ranging from –1 to 3000, in seconds

Default value: 1800

enable_release_scan_lock

Parameter description: Specifies whether a SELECT statement releases a level-1 lock after the statement execution is complete. This parameter reduces DDL conflicts with SELECT locks within transaction blocks. This parameter is supported only by clusters of version 8.3.0 or later.

Type: USERSET

Value range: Boolean

  • on indicates that DDL operations will be blocked to wait for the release of cluster locks. The SELECT statement releases the level-1 lock after it finishes, not when the transaction commits.
  • off indicates that DDL operations will not be blocked.

Default value: off

enable_global_deadlock_detector

Parameter description: Specifies whether the distributed deadlock detection function module is enabled. This parameter is supported only by clusters of 8.3.0 and later versions.

Type: SIGHUP

Value range: Boolean

  • on indicates that DDL operations will be blocked to wait for the release of cluster locks.
  • off indicates that DDL operations will not be blocked.

    Default value: off

    When distributed deadlock detection is on, the system can find and break deadlocks within a time limit. It does this by releasing the locked resources and canceling the most recent transaction. The user then sees an error "cancelled by global deadlock detector".

global_deadlock_detector_period

Parameter description: Specifies the distributed deadlock detection interval. This parameter is supported only by cluster versions 8.3.0 and later.

Type: SIGHUP

Value range: an integer ranging from 1 to INT_MAX. The unit is s.

Default value: 5s

vacuum_full_interruptible

Parameter description: Controls the behavior that the VACUUM FULL statement gives a lock to other statements. This is supported only by clusters of version 9.1.0.200 or later.

Type: USERSET

Value range: Boolean

  • on indicates that DDL operations will be blocked to wait for the release of cluster locks. When VACUUM FULL blocks other statements, it interrupts the execution and gives the lock to other statements.
  • off indicates that DDL operations will not be blocked. When VACUUM FULL blocks other statements, it does not interrupt the execution. Other statements can be executed only after VACUUM FULL has completed and released the lock.

Default value: off

forbid_interrupt_vacuum_full_appnames

Parameter description: Specifies which statements are given locks by the VACUUM FULL statement when vacuum_full_interruptible is set to on. If the application name of the statement is included in the list specified by the parameter, VACUUM FULL does not lock the statement even if vacuum_full_interruptible is set to on. This is supported only by clusters of version 9.1.0.200 or later.

Type: SIGHUP

Value range: a string

Default value: CalculateSpaceInfo,OM,gs_roach

  • If multiple application names are configured, separate them with commas (,), for example, forbid_interrupt_vacuum_full_appnames='CalculateSpaceInfo,OM,gs_roach'.
  • The application name can contain only letters, digits, and underscores (_) and cannot contain special characters such as spaces and quotation marks.
  • The application name is case insensitive. That is, om and OM are considered as the same application name.
  • When vacuum_full_interruptible is off, VACUUM FULL does not give locks to any statement.