如何使 Redshift 中的空闲用户会话超时?

How to timeout idle user sessions in Redshift?

我正在寻找一种方法来终止在 Redshift 中处于非活动状态或打开了任意时间的用户会话。我注意到在 STV_SESSIONS 中我有大量会话打开,通常是为同一用户打开的,有时几天前就已经初始化了。虽然我知道这可能是 Redshift 关闭某些东西的方式的一个更大问题的征兆,但我希望有一个可配置的超时解决方案。

在 AWS 文档中我找到了 PG_TERMINATE_BACKEND (http://docs.aws.amazon.com/redshift/latest/dg/PG_TERMINATE_BACKEND.html),但我希望有一个更自动化的解决方案。

您可以在 AWS redshift 中使用工作负载管理配置。您可以在其中设置用户组、查询组和超时会话。您可以将所有相同的用户分组在一起并为他们分配一个组名并为他们设置超时会话。

我就是这样做的。根据您的优先级设置查询队列,然后设置用户组的并发级别和以毫秒为单位的超时。


更多信息,您可以参考AWS文档。
来源 - Workload Management
- Configuring Workload Management

它非常简单直接。
如果我做出了错误的假设,请发表评论,我会重新调整我的回答。

超时仅适用于超时查询,不适用于会话。

超时(毫秒)

The maximum time, in milliseconds, queries can run before being canceled. If a read-only query, such as a SELECT statement, is canceled due to a WLM timeout, WLM attempts to route the query to the next matching queue based on the WLM Queue Assignment Rules. If the query doesn't match any other queue definition, the query is canceled; it is not assigned to the default queue. For more information, see WLM Query Queue Hopping. WLM timeout doesn’t apply to a query that has reached the returning state. To view the state of a query, see the STV_WLM_QUERY_STATE system table.

JSON property: max_execution_time

您可以使用 Redshift 中新引入的 idle session timeout 功能。它在 creating a user and post creation (using Alter statement) 时都可用。查找 SESSION TIMEOUT 参数。