查询一个参数(postgresql.conf 设置),如“max_connections"; [英] Query a parameter (postgresql.conf setting) like "max_connections"
问题描述
有谁知道是否可以(以及如何,如果可以)在 PostgreSQL (9.1) 中查询数据库服务器设置?
Does anyone know if it's even possible (and how, if yes) to query a database server setting in PostgreSQL (9.1)?
我需要检查max_connections
(打开的数据库连接的最大数量)设置.
I need to check the max_connections
(maximum number of open db connections) setting.
推荐答案
您可以使用 SHOW
:
SHOW max_connections;
这将返回当前有效的设置.请注意,它可能与 postgresql.conf
中的设置不同,因为有一个 在 PostgreSQL 中设置运行时参数的多种方法.在当前会话中从 postgresql.conf
重置原始"设置:
This returns the currently effective setting. Be aware that it can differ from the setting in postgresql.conf
as there are a multiple ways to set run-time parameters in PostgreSQL. To reset the "original" setting from postgresql.conf
in your current session:
RESET max_connections;
但是,不适用于此特定设置.手册:
However, not applicable to this particular setting. The manual:
该参数只能在服务器启动时设置.
This parameter can only be set at server start.
查看所有设置:
SHOW ALL;
还有 pg_settings
:
视图 pg_settings
提供对运行时参数的访问服务器.它本质上是 SHOW
的替代接口,并且SET
命令.它还提供了对有关每个的一些事实的访问不能直接从 SHOW
获得的参数,例如 minimum和最大值.
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语句中:
Finally, there is current_setting()
, which can be nested in DML statements:
SELECT current_setting('max_connections');
相关:
这篇关于查询一个参数(postgresql.conf 设置),如“max_connections";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!