为 PL/pgSQL 中实现的功能设置配置参数
Setting a configuration parameter for functions implemented in PL/pgSQL
我在 PL/pgSQL 中编写了几个函数,我想通过一些配置条目来控制它们的行为,也可以在 运行 时间更改(每个会话)。是否可以在 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.
如果这篇文章用 "No" 回答了我的问题,我的 PL/pgSQL 功能是否可以被视为 扩展模块 以便它们可以拥有自己的配置配置文件中的条目?
您可以在 postgresql.conf
中定义您的自定义参数。只需附加一行(例如):
my_param.new_param = 'something'
并重新加载配置(或重启服务器)。
在您的客户端中,您可以使用 show
命令访问参数:
SHOW my_param.new_param;
或使用current_setting()
函数:
SELECT current_setting('my_param.new_param');
您可以更改当前参数(在本地会话中):
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 不以任何方式检查它。您可以有许多自定义参数。
我在 PL/pgSQL 中编写了几个函数,我想通过一些配置条目来控制它们的行为,也可以在 运行 时间更改(每个会话)。是否可以在 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.
如果这篇文章用 "No" 回答了我的问题,我的 PL/pgSQL 功能是否可以被视为 扩展模块 以便它们可以拥有自己的配置配置文件中的条目?
您可以在 postgresql.conf
中定义您的自定义参数。只需附加一行(例如):
my_param.new_param = 'something'
并重新加载配置(或重启服务器)。
在您的客户端中,您可以使用 show
命令访问参数:
SHOW my_param.new_param;
或使用current_setting()
函数:
SELECT current_setting('my_param.new_param');
您可以更改当前参数(在本地会话中):
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 不以任何方式检查它。您可以有许多自定义参数。