自治事务特性函数
- gs_autonomous_transaction_detail()
描述:查看当前CN节点上用户所属的自治事务会话及其父子事务关系。具备MONADMIN权限或者SYSADMIN权限的用户,可以查看当前CN节点所有自治事务会话及其父子事务关系。不允许在DN节点调用。
参数:无。
返回值类型:setof record
返回值说明:如表1所示。
表1 gs_autonomous_transaction_detail函数返回值说明 名称
类型
描述
autonomous_transaction_session_id
bigint
自治事务会话ID。
autonomous_transaction_thread_id
bigint
自治事务线程ID。
parent_autonomous_transaction_session_id
bigint
自治事务父会话ID。
示例:
gaussdb=# CREATE OR REPLACE PROCEDURE proc_test() AS DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN pg_sleep(60); END; / gaussdb=# CALL proc_test(); -- 需要新建一个会话进行查询 -- gaussdb=# SELECT * FROM pg_catalog.gs_autonomous_transaction_detail() AS gaussdb-# (autonomous_transaction_session_id bigint, autonomous_transaction_thread_id bigint, parent_autonomous_transaction_session_id bigint); autonomous_transaction_session_id | autonomous_transaction_thread_id | parent_autonomous_transaction_session_id -----------------------------------+----------------------------------+------------------------------------------ 139778155607808 | 139778155607808 | 139777830549248 (1 row)
- gs_get_autonomous_transaction_count()
描述:查询当前CN节点的自治事务计数。不允许在DN节点调用。
参数:无。
返回值类型:integer
返回值说明:如表2所示。
表2 gs_get_autonomous_transaction_count函数返回值说明 名称
类型
描述
gs_get_autonomous_transaction_count
integer
当前自治事务计数。
示例:
gaussdb=# CREATE OR REPLACE PROCEDURE proc_test() AS DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN pg_sleep(60); END; / gaussdb=# CALL proc_test(); -- 需要新建一个会话进行查询 -- gaussdb=# SELECT gs_get_autonomous_transaction_count(); gs_get_autonomous_transaction_count ------------------------------------- 1 (1 row)
- gs_reset_autonomous_transaction_count()
描述:将当前CN节点的自治事务计数恢复至正确值,并返回当前正确的自治事务计数值。用户需拥有MONADMIN权限或者SYSADMIN权限才可调用该函数。不允许在DN节点调用。
参数:无。
返回值类型:integer
返回值说明:如表3所示。
表3 gs_reset_autonomous_transaction_count函数返回值说明 名称
类型
描述
gs_reset_autonomous_transaction_count
integer
恢复后正确的自治事务计数值。
示例:
gaussdb=# SELECT gs_reset_autonomous_transaction_count(); gs_reset_autonomous_transaction_count --------------------------------------- 0 (1 row) gaussdb=# CREATE OR REPLACE PROCEDURE proc_test() AS DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN pg_sleep(60); END; / gaussdb=# CALL proc_test(); -- 需要新建一个会话进行查询 -- gaussdb=# SELECT gs_reset_autonomous_transaction_count(); gs_reset_autonomous_transaction_count --------------------------------------- 1 (1 row)
- gs_global_autonomous_transaction_detail()
描述:查看每个CN节点上用户所属的自治事务会话及其父子事务关系。具备MONADMIN权限或者SYSADMIN权限的用户,可以查看每个CN节点所有自治事务会话及其父子事务关系。不允许在DN节点调用。
参数:无。
返回值类型:setof record
返回值说明:如表4所示。
当GUC参数enable_nonsysadmin_execute_direct=off时,该函数仅允许具备MONADMIN权限或者SYSADMIN权限的用户调用。
表4 gs_global_autonomous_transaction_detail函数返回值说明 名称
类型
描述
node_name
text
CN节点名称。
autonomous_transaction_session_id
bigint
自治事务会话ID。
autonomous_transaction_thread_id
bigint
自治事务线程ID。
parent_autonomous_transaction_session_id
bigint
自治事务父会话ID。
示例:
gaussdb=# CREATE OR REPLACE PROCEDURE proc_test() AS DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN pg_sleep(60); END; / gaussdb=# CALL proc_test(); -- 需要新建一个会话进行查询 -- gaussdb=# SELECT * FROM gs_global_autonomous_transaction_detail(); node_name | autonomous_transaction_session_id | autonomous_transaction_thread_id | parent_autonomous_transaction_session_id --------------+-----------------------------------+----------------------------------+------------------------------------------ coordinator1 | 140477506516736 | 140477506516736 | 140477683726080 (1 row)
- gs_global_get_autonomous_transaction_count()
描述:查询每个CN节点当前的自治事务计数。不允许在DN节点调用。
参数:无。
返回值类型:setof record
返回值说明:如表5所示。
当GUC参数enable_nonsysadmin_execute_direct=off时,该函数仅允许具备MONADMIN权限或者SYSADMIN权限的用户调用。
表5 gs_global_get_autonomous_transaction_count函数返回值说明 名称
类型
描述
node_name
text
CN节点名称。
gs_get_autonomous_transaction_count
integer
当前自治事务计数。
示例:
gaussdb=# CREATE OR REPLACE PROCEDURE proc_test() AS DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN pg_sleep(60); END; / gaussdb=# CALL proc_test(); -- 需要新建一个会话进行查询 -- gaussdb=# SELECT * FROM gs_global_get_autonomous_transaction_count(); node_name | gs_get_autonomous_transaction_count --------------+------------------------------------- coordinator1 | 1 (1 row)
- gs_global_reset_autonomous_transaction_count([exec_node_name text])
描述:将每个CN节点的自治事务计数恢复至正确值,并返回恢复后每个CN节点正确的自治事务计数值。若指定参数exec_node_name,则恢复指定节点的自治事务计数为正确值。调用该函数必须有MONADMIN权限或者SYSADMIN权限。不允许在DN节点调用。
参数:exec_node_name,指定的CN节点名称,可选参数。
返回值类型:setof record
返回值说明:如表6所示。
表6 gs_global_reset_autonomous_transaction_count函数返回值说明 名称
类型
描述
node_name
text
CN节点名称。
gs_reset_autonomous_transaction_count
integer
恢复后正确的自治事务计数值。
示例:
gaussdb=# CREATE OR REPLACE PROCEDURE proc_test() AS DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN pg_sleep(60); END; / gaussdb=# CALL proc_test(); -- 需要新建一个会话进行查询 -- gaussdb=# SELECT * FROM gs_global_reset_autonomous_transaction_count(); node_name | gs_reset_autonomous_transaction_count --------------+--------------------------------------- coordinator1 | 1 (1 row) gaussdb=# SELECT * FROM gs_global_reset_autonomous_transaction_count('coordinator1'); node_name | gs_reset_autonomous_transaction_count --------------+--------------------------------------- coordinator1 | 1 (1 row)