Updated on 2024-06-03 GMT+08:00

Lock Management

In GaussDB, a deadlock may occur when concurrently executed transactions compete for resources. This section describes parameters used for managing transaction locks.

deadlock_timeout

Parameter description: Specifies the deadlock timeout interval. When the applied lock exceeds the preset value, the system will check whether a deadlock occurs. This parameter takes effect only for common locks.

Parameter type: integer.

Unit: ms

Value range: 1 to 2147483647.

Default value: 1s

Setting method: This is a SUSET parameter. Set it based on instructions in Table 1.

Setting suggestion:

  • The check for deadlock is relatively expensive. Therefore, the server does not check it when waiting for a lock every time. Deadlocks seldom occur when the system is running. Therefore, the system just needs to wait on the lock for a while before checking for deadlocks. Increasing the value of deadlock_timeout reduces the time wasted in deadlock check, but slows down reporting of real deadlock errors. On a heavily loaded server, you may need to set deadlock_timeout to a larger value. It is recommended that this value exceed the transaction time to avoid deadlock check before locks are released.
  • When log_lock_waits is set to on, deadlock_timeout determines a waiting time to write the lock waiting time information during query execution to logs. To study the lock delay, you can set deadlock_timeout to a value smaller than the normal value.

lockwait_timeout

Parameter description: Specifies the timeout for attempts to acquire a lock. If the time spent in waiting for a lock exceeds the specified time, an error is reported. This parameter takes effect only for common locks.

Parameter type: integer.

Unit: ms

Value range: 0 to 2147483647

Default value: 20min

Setting method: This is a USERSET parameter. Set it based on instructions in Table 1. For example, if the value is 900 without a unit, lockwait_timeout indicates 900 ms. If the value is 20min, lockwait_timeout indicates 20 minutes. If the unit is required, the value must be ms, s, min, h, or d.

Setting suggestion: Retain the default value. Alternatively, set this parameter based on the service requirements.

update_lockwait_timeout

Parameter description: Specifies 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 spent in waiting for a lock exceeds the specified time, an error is reported. This parameter takes effect only for common locks.

Parameter type: integer.

Unit: ms

Value range: 0 to 2147483647

Default value: 2min (120000 ms)

Setting method: This is a SUSET parameter. Set it based on instructions in Table 1. For example, if the value is 900 without a unit, update_lockwait_timeout indicates 900 ms. If the value is 2min, update_lockwait_timeout indicates 2 minutes. If the unit is required, the value must be ms, s, min, h, or d.

Setting suggestion: Observe the workload of transactions that concurrently update the same row. For common TP services, the execution time is less than two minutes. In this case, the probability of false positives is low. If a large number of transactions concurrently update the same row and the execution time exceeds two minutes, you can increase the value of this parameter to prevent false positives due to lock timeout.

max_locks_per_transaction

Parameter description: Determines the average number of object locks allocated to each transaction.

Parameter type: integer.

Unit: none

Value range: 10 to 2147483647

Default value: 256

Setting method: This is a POSTMASTER parameter. Set it based on instructions in Table 1.

Setting suggestion:

  • The maximum number of hash tables that can be locked by a shared lock at any time is calculated based on an assumption: max_locks_per_transaction x (max_connections + max_prepared_transactions) and max_locks_per_transaction ≥ Number of concurrent service transactions x Number of object locks added by each service transaction/(max_connections + max_prepared_transactions). In this case an upper limit is determined for this parameter.
  • Within the specified range, objects can be locked simultaneously at any time. You may need to increase the value of this parameter if many different tables are modified in a single transaction.
  • Increasing the value of this parameter may cause GaussDB to request more System V-shared memory than the OS's default configuration allows, leading to database startup failure.
  • When running a standby node, you must set this parameter to a value that is no less than that on the primary node. Otherwise, queries will not be allowed on the standby node.

max_pred_locks_per_transaction

Parameter description: Specifies the average number of predicate locks allocated for each transaction.

  • The size of the shared predicate 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 whose amount does not exceed the preset number can be locked simultaneously at any time. You may need to increase this value if many different tables are modified in a single transaction. This parameter can only be set at server start.
  • Increasing the value of this parameter may cause GaussDB to request more System V-shared memory than the OS's default configuration allows.

This is a POSTMASTER parameter. Set it based on instructions in Table 1.

Value range: an integer ranging from 10 to 2147483647

Default value: 64

gs_clean_timeout

Parameter description: Controls the average interval between gs_clean callings by the Coordinator.

  • Transactions in GaussDB are committed in two phases. An unfinished two-phase transaction may hold a table-level lock, keeping tables from being locked by other connections. In this case, the database needs to call the gs_clean tool to clean unfinished two-phase transactions in cluster. gs_clean_timeout is used to control the interval for the Coordinator to call the gs_clean tool.
  • A larger value of this parameter indicates a low frequency of calling gs_clean in GaussDB to clean unfinished two-phase transactions.

This is a SIGHUP parameter. Set it based on instructions in Table 1.

Value range: an integer ranging from 0 to 2147483. The unit is s.

Default value: 1min

partition_lock_upgrade_timeout

Parameter description: Specifies the timeout for attempts to upgrade an exclusive lock (read allowed) to an access exclusive lock (read/write blocked) on a partitioned table during the execution of some query statements. If there are concurrent read transactions running, the lock upgrade will need to wait. partition_lock_upgrade_timeout sets the waiting timeout for lock upgrade attempts.

  • 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, exclusive locks are acquired for the partitions during data rearrangement and access exclusive locks are acquired during file exchange.
  • Generally, a partition waits until it acquires a lock, or a timeout occurs if the partition waits for a period longer than the value specified by the lockwait_timeout parameter.
  • When doing MERGE PARTITION or CLUSTER PARTITION on a partitioned table, an access exclusive lock needs to be acquired during file exchange. If the lock fails to be acquired, the acquisition is retried at an interval of 50 ms until timeout occurs. The partition_lock_upgrade_timeout parameter specifies the time to wait before the lock acquisition attempt times out.
  • If partition_lock_upgrade_timeout is set to –1, the lock upgrade never times out. The lock upgrade is continuously retried until it succeeds.

    This is a USERSET parameter. Set it based on instructions in Table 1.

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

Default value: 1800

fault_mon_timeout

Parameter description: Specifies the period for detecting lightweight deadlocks. This is a SIGHUP parameter. Set it based on instructions in Table 1.

Value range: an integer ranging from 0 to 1440. The unit is minute.

Default value: 5min

enable_online_ddl_waitlock

Parameter description: Specifies whether to block DDL operations to wait for the release of cluster locks, such as pg_advisory_lock and pgxc_lock_for_backup. This parameter is mainly used in online OM operations and you are advised not to modify the settings.

This is a SIGHUP parameter. Set it based on instructions in Table 1.

Value range: Boolean

  • on: enabled.
  • off: disabled.

Default value: off

xloginsert_locks

Parameter description: Specifies the number of locks on concurrent write-ahead logging. This parameter is used to improve the efficiency of writing write-ahead logs.

Parameter type: integer.

Unit: none

Value range: 1 to 1000. If the CPU uses the NUMA architecture, the value must be an integer multiple of the number of NUMA nodes.

Default value: 16

Setting method: This is a POSTMASTER parameter. Set it based on instructions in Table 1.

Setting suggestion: When the concurrency pressure of the Arm CPU architecture is high, performance jitter may occur due to atomic operation competition. You can decrease the value of this parameter for stable running performance.

num_internal_lock_partitions

Parameter description: Specifies the number of internal lightweight lock partitions. It is mainly used for performance optimization in various scenarios. The content is organized in the KV format of keywords and numbers. Different types of locks are separated by commas (,). The sequence does not affect the setting result. For example, CLOG_PART=256,CSNLOG_PART=512 is equivalent to CSNLOG_PART=512,CLOG_PART=256. If you set the same keyword multiple times, only the latest setting takes effect. For example, if you set CLOG_PART to 256 and CLOG_PART to 2, the value of CLOG_PART is 2. If no keyword is set, the default value is used. The usage description, maximum value, minimum value, and default value of each lock type are as follows:

  • CLOG_PART: number of Clog file controllers. Increasing the value of this parameter improves the Clog writing efficiency and transaction commit performance, but increases the memory usage. Decreasing the value of this parameter reduces the memory usage, but may increase the conflict of writing Clogs and affect the performance. The value ranges from 1 to 256.
  • CSNLOG_PART: number of CSNLOG file controllers. Increasing the value of this parameter improves the CSNLOG writing efficiency and transaction commit performance, but increases the memory usage. Decreasing the value of this parameter reduces the memory usage, but may increase the conflict of writing CSNLOGs and affect the performance. The value ranges from 1 to 512.
  • LOG2_LOCKTABLE_PART: two logarithms of the number of ordinary table lock partitions. Increasing the value can improve the concurrency of obtaining locks in the normal process, but may increase the time required for transferring and clearing locks. When wait events occur in LockMgrLock, you can increase the value to improve the performance. The minimum value is 4, that is, the number of lock partitions is 16. The maximum value is 16, that is, the number of lock partitions is 65536.
  • TWOPHASE_PART: number of partitions of the two-phase transaction lock. Increasing the value can increase the number of concurrent two-phase transaction commits. The value ranges from 1 to 64.
  • FASTPATH_PART: maximum number of locks that each thread can obtain without using the main lock table. When a partitioned table is read, updated, inserted, or deleted and the wait event is LockMgrLock, you can increase the value of this parameter to prevent LockMgrLock from being obtained and improve performance. It is recommended that the value be greater than or equal to that calculated using the following formula: Number of partitions x (1 + Number of local indexes) + Number of global indexes + 10. Increasing the value will increase the memory usage. The value ranges from 20 to 10000.

This is a POSTMASTER parameter. Set it based on instructions in Table 1.

Value range: a string.

Default value:

  • CLOG_PART: 256
  • CSNLOG_PART: 512
  • LOG2_LOCKTABLE_PART: 4
  • TWOPHASE_PART: 1
  • FASTPATH_PART: 20

enable_wait_exclusive_lock

Parameter description: Specifies whether to enable the hang detection and cure function for the exclusive lock of ProcArrayLock.

This is a SIGHUP parameter. Set it based on instructions in Table 1.

Value range: Boolean

  • on: enabled.
  • off: disabled.

Default value: on

barrier_lock_timeout

Parameter description: Specifies the timeout interval for holding a barrier lock.

Parameter type: integer.

Unit: second

Value range: 0 to 3600

Default value: 30s

Setting method: This is a USERSET parameter. Set it based on instructions in Table 1.

Setting suggestion: Retain the default value.

enable_xid_abort_check

Parameter description: Specifies whether to verify transaction ID rollback is enabled when a transaction is committed.

Parameter type: Boolean.

Unit: none

Value range:

  • on: enabled.
  • off: disabled.

Default value: on

Setting method: This is a SIGHUP parameter. Set it based on instructions in Table 1.

Setting suggestion: Retain the default value.