我已经在 PL/pgSQL 中编写了几个函数,我想通过一些配置条目来控制它们的行为,这些条目也可以在运行时更改(每个 session )。是否可以在 postgresql.conf
中定义新的自定义配置条目?如果不是,解决方法是什么?
作为我的搜索结果,我遇到了 part of documentation其中说:
18.16. Customized Options
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 函数是否可以被视为一个扩展模块,以便它们可以在配置文件中拥有自己的配置条目?
最佳答案
您可以在 postgresql.conf
中定义您的自定义参数。只需附加一行(例如):
my_param.new_param = 'something'
并重新加载配置(或重启服务器)。
在您的客户端中,您可以使用show
命令访问参数:
SHOW my_param.new_param;
或使用current_setting()
函数:
SELECT current_setting('my_param.new_param');
您可以更改当前参数(在本地 session 中):
SET my_param.new_param TO 'new value';
也可以为数据库定义自定义参数:
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 不以任何方式检查它。您可以有许多自定义参数。
关于postgresql - 为 PL/pgSQL 中实现的函数设置配置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34476062/