有谁知道在 PostgreSQL (9.1) 中查询数据库服务器设置是否有可能(以及如何,如果有)?
我需要检查 max_connections
(打开的数据库连接的最大数量)设置。
最佳答案
您可以使用 SHOW
:
SHOW max_connections;
这将返回当前有效的设置。请注意,它可能与 postgresql.conf
中的设置不同,因为有一个 multiple ways to set run-time parameters in PostgreSQL。 .要在当前 session 中从 postgresql.conf
重置“原始”设置:
RESET max_connections;
但是,不适用于此特定设置。 The manual:
This parameter can only be set at server start.
查看所有设置:
SHOW ALL;
还有pg_settings
:
The view
pg_settings
provides access to run-time parameters of the server. It is essentially an alternative interface to theSHOW
andSET
commands. It also provides access to some facts about each parameter that are not directly available fromSHOW
, such as minimum and maximum values.
对于您的原始请求:
SELECT *
FROM pg_settings
WHERE name = 'max_connections';
最后,有 current_setting()
,可以嵌套在 DML 语句中:
SELECT current_setting('max_connections');
相关:
关于postgresql - 查询一个参数(postgresql.conf 设置)比如 "max_connections",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8288823/