为PL/pgSQL中实现的功能设置配置参数 [英] Setting a configuration parameter for functions implemented in PL/pgSQL
问题描述
我已经在PL/pgSQL中编写了几个函数,我想通过一些配置条目来控制它们的行为,这些配置条目也可以在运行时更改(每个会话).是否可以在postgresql.conf
中定义新的自定义配置条目?如果没有,怎么办?
I've written a couple of functions in PL/pgSQL and I would like to control their behavior through some configuration entries, changeable at run time too (per session). Is it possible to define new custom-defined configuration entries in postgresql.conf
? If not, what's the work around?
作为搜索结果,我遇到了文档的一部分其中表示:
As my search results, I came across the part of documentation which says:
18.16.自定义选项
此功能旨在允许通常不为用户所知的参数 PostgreSQL由附加模块(例如程序模块)添加 语言).这允许在扩展模块中配置扩展模块. 标准方式.
This feature was designed to allow parameters not normally known to PostgreSQL to be added by add-on modules (such as procedural languages). This allows extension modules to be configured in the standard ways.
如果本文以否"回答了我的问题,我的PL/pgSQL函数是否可以被视为扩展模块,以便它们可以在配置文件中拥有自己的配置条目?
If this passage answers my question with a "No", can my PL/pgSQL functions be considered an extension module so that they can have their own configuration entries in the configuration file?
推荐答案
您可以在postgresql.conf
中定义自定义参数.只需添加一行(例如):
You can define your custom parameters in postgresql.conf
. Just append a line (e.g.):
my_param.new_param = 'something'
并重新加载配置(或重新启动服务器).
and reload configuration (or restart server).
在您的客户端中,您可以使用show
命令访问该参数:
In your client you can access the parameter with show
command:
SHOW my_param.new_param;
或具有current_setting()
功能:
SELECT current_setting('my_param.new_param');
您可以更改当前参数(在会话中本地):
You can change the current parameter (locally in the session):
SET my_param.new_param TO 'new value';
还可以为数据库定义自定义参数:
It is also possible to define custom parameters for a database:
ALTER DATABASE test SET my_param.new_param TO 'new test value';
-- each new client to the database will see the parameter with new value
-- current setting of the parameter remains unchanged
-- or
SET my_param.new_param TO 'new test value';
ALTER DATABASE test SET my_param.new_param FROM CURRENT;
自定义参数必须包含一个句点.前缀在形式上应指明与其相关的扩展名,但Postgres不会以任何方式对其进行检查.您可以有许多自定义参数.
A custom parameter must contain a period. Formally, the prefix should indicate the extension to which it relates, but Postgres does not check it in any way. You can have many custom parameters.
这篇关于为PL/pgSQL中实现的功能设置配置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!