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 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. This parameter takes effect only for common locks.
- 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 checked for deadlocks before it is released will be reduced.
- 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.
This parameter is a SUSET parameter. Set it based on instructions provided in Table 1.
Value range: an integer ranging from 1 to 2147483647. The unit is ms.
Default value: 1s
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.
This parameter is a SUSET parameter. Set it based on instructions provided in Table 1.
Value range: an integer ranging from 0 to INT_MAX. The unit is ms.
Default value: 20min
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.
This parameter is a SUSET parameter. Set it based on instructions provided in Table 1.
Value range: an integer ranging from 0 to 2147483647. The unit is ms.
Default value: 2min (120000 ms)
max_locks_per_transaction
Parameter description: Determines 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 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 database start.
- Increasing the value of this parameter may cause GaussDB to request more System V-shared memory than the OS's default configuration allows.
- 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.
This is a POSTMASTER parameter. Set it based on instructions provided in Table 1.
Value range: an integer ranging from 10 to INT_MAX
Default value:
256 (196-core CPU/1536 GB memory, 128-core CPU/1024 GB memory, 104-core CPU/1024 GB memory, 96-core CPU/1024 GB memory, 96-core CPU/768 GB memory, 80-core CPU/640 GB memory, 64-core CPU/512 GB memory, 60-core CPU/480 GB memory, 32-core CPU/256 GB memory, 16-core CPU/128 GB memory, 8-core CPU/64 GB memory, 4-core CPU/32 GB memory); 64 (4-core CPU/16 GB memory)
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 provided in Table 1.
Value range: an integer ranging from 10 to INT_MAX
Default value: 64
gs_clean_timeout
Parameter description: Specifies the average interval for clearing temporary tables on the primary node.
- When the database connection is terminated abnormally, temporary tables may exist. In this case, you need to call the gs_clean tool to clear the temporary tables in the database.
- If this parameter is set to a larger value, the time for clearing GaussDB temporary tables may be prolonged.
This is a SIGHUP parameter. Set it based on instructions provided 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. This parameter 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 this parameter 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 provided 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 provided 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 database locks, such as pg_advisory_lock. This parameter is mainly used in online OM operations and you are not advised to modify the settings.
This parameter is a SIGHUP parameter. Set it based on instructions provided in Table 1.
Value range: Boolean
- on indicates that DDL operations will be blocked to wait for the lock release.
- off indicates that DDL operations will not be blocked.
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.
This parameter is a POSTMASTER parameter. Set it based on instructions provided in Table 1.
Value range: an integer ranging from 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
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 submission 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 log writing efficiency and transaction submission performance, but increases the memory usage. Decreasing the value of this parameter reduces the memory usage, but may increase the conflict of writing CSNLOG logs and affect the performance. The value ranges from 1 to 512.
- LOG2_LOCKTABLE_PART: two logarithms of the number of common 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 waiting 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 waiting 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 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 parameter is a POSTMASTER parameter. Set it based on instructions provided 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' (196-core CPU/1536 GB memory, 128-core CPU/1024 GB memory, 104-core CPU/1024 GB memory, 96-core CPU/1024 GB memory, 96-core CPU/768 GB memory, 80-core CPU/640 GB memory, 64-core CPU/512 GB memory, 60-core CPU/480 GB memory, 32-core CPU/256 GB memory, 16-core CPU/128 GB memory, 8-core CPU/64 GB memory, or 4-core CPU/32 GB memory); 'CLOG_PART=8,CSNLOG_PART=16,LOG2_LOCKTABLE_PART=4,TWOPHASE_PART=1,FASTPATH_PART=20' (4-core CPU/16 GB memory)
enable_wait_exclusive_lock
Parameter description: Specifies whether to enable the hang detection and cure function for the exclusive lock of ProcArrayLock.
This parameter is a SIGHUP parameter. Set it based on instructions provided in Table 1.
Value range: Boolean
- on: enabled.
- off: disabled.
Default value: on
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot