在 YugabyteDB 中以每个用户为基础设置 statement_timeout

Set statement_timeout on a per-user basis in YugabyteDB

[用户在 YugabyteDB Community Slack] 上发布的问题

Postgres 提供了一种通过更改角色在每个用户的基础上设置 statement_timeout 的方法:https://www.postgresql.org/docs/11/sql-alterrole.html

有一个已知的解决方法可以在连接建立后设置 statement_timeout,但在角色级别设置它会很有帮助。

YugabyteDB 也有可用的东西吗?

这应该已经可以像在 PostgreSQL 中那样实现了。示例:

yugabyte=# ALTER ROLE yugabyte SET statement_timeout = 5000;

然后打开另一个 shell 并尝试做:

yugabyte=# select pg_sleep(5);
ERROR:  canceling statement due to statement timeout
yugabyte=# select pg_sleep(4);
 pg_sleep 
----------
 
(1 row)

在 2.9.0.0 上测试