查询一个参数(postgresql.conf 设置),比如“max_connections”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8288823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:13:27  来源:igfitidea点击:

Query a parameter (postgresql.conf setting) like "max_connections"

postgresqlconfigurationsettingspostgresql-9.1

提问by Greg Kramida

Does anyone know if it's even possible (and how, if yes) to query a database server setting in PostgreSQL (9.1)?

有谁知道是否有可能(以及如何,如果有)在 PostgreSQL (9.1) 中查询数据库服务器设置?

I need to check the max_connections(maximum number of open db connections) setting.

我需要检查max_connections(打开数据库连接的最大数量)设置。

回答by Erwin Brandstetter

Can be as simple as:

可以很简单:

SHOW max_connections;

This returns the currently effective setting. Be aware that it can differ from the setting in postgresql.confas there are a couple of ways to set run-time parameters in PostgreSQL. To reset the "original" setting from postgresql.confin your current session:

这将返回当前有效的设置。请注意,它可能与 中的设置不同,postgresql.conf因为有几种方法可以在 PostgreSQL 中设置运行时参数。从postgresql.conf当前会话中重置“原始”设置:

RESET max_connections;

However, not applicable to this particular setting. Per documentation:

但是,不适用于此特定设置。根据文档

This parameter can only be set at server start.

该参数只能在服务器启动时设置。

To see allsettings:

查看所有设置:

SHOW ALL;

More on the SHOWcommand in the manual.
If you need more details or want to integrate the look-up into a standard SELECTquery, there is also:

更多关于SHOW手册中的命令
如果您需要更多详细信息或希望将查找集成到标准SELECT查询中,还有:

SELECT * FROM pg_settings;

Returns the same result as SHOW ALL, but with additional information per setting. For your original request:

返回与 相同的结果SHOW ALL,但每个设置都有附加信息。对于您的原始请求:

SELECT *
FROM   pg_settings
WHERE  name = 'max_connections';

There is also the functional equivalent current_setting(), which can be nested in DML statements.

还有功能等效的current_setting(),它可以嵌套在 DML 语句中。

SELECT current_setting('max_connections');

Related:

有关的: