CHANGE_SESSION_PRIORITY - Amazon Redshift

CHANGE_SESSION_PRIORITY

CHANGE_SESSION_PRIORITY 使超级用户可以立即更改系统中任何会话的优先级。只有一个会话、用户或查询可以使用优先级 CRITICAL 运行。

语法

CHANGE_SESSION_PRIORITY(pid, priority)

参数

pid

更改其优先级的会话的进程标识符。值 -1 指的是当前会话。需要 INTEGER 值。

priority

要分配给会话的新优先级。此参数必须是包含以下值的字符串:CRITICALHIGHESTHIGHNORMALLOWLOWEST

返回类型

示例

要返回处理当前会话的服务器进程的进程标识符,请使用以下示例。

SELECT pg_backend_pid(); +----------------+ | pg_backend_pid | +----------------+ | 30311 | +----------------+

在此示例中,将当前会话的优先级更改为 LOWEST

SELECT CHANGE_SESSION_PRIORITY(30311, 'Lowest'); +---------------------------------------------------------------------------------------+ | change_session_priority | +---------------------------------------------------------------------------------------+ | Succeeded to change session priority. Changed session (pid:30311) priority to lowest. | +---------------------------------------------------------------------------------------+

在此示例中,将当前会话的优先级更改为 HIGH

SELECT CHANGE_SESSION_PRIORITY(-1, 'High'); +-------------------------------------------------------------------------------------------------+ | change_session_priority | +-------------------------------------------------------------------------------------------------+ | Succeeded to change session priority. Changed session (pid:30311) priority from lowest to high. | +-------------------------------------------------------------------------------------------------+

要创建用于更改会话优先级的存储过程,请使用以下示例。运行此存储过程的权限授予数据库用户 test_user

CREATE OR REPLACE PROCEDURE sp_priority_low(pid IN int, result OUT varchar) AS $$ BEGIN SELECT CHANGE_SESSION_PRIORITY(pid, 'low') into result; END; $$ LANGUAGE plpgsql SECURITY DEFINER; GRANT EXECUTE ON PROCEDURE sp_priority_low(int) TO test_user;

然后,名为 test_user 的数据库用户调用该过程。

CALL sp_priority_low(pg_backend_pid()); +------------------------------------------------------+ | result | +------------------------------------------------------+ | Success. Change session (pid:13155) priority to low. | +------------------------------------------------------+