Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改PostgreSQL用户身份验证方法的最简单脚本化方法_Postgresql - Fatal编程技术网

更改PostgreSQL用户身份验证方法的最简单脚本化方法

更改PostgreSQL用户身份验证方法的最简单脚本化方法,postgresql,Postgresql,如PostgreSQL wiki()中所述,我可以编辑pg_hba.conf文件,将用户的身份验证方法设置为“信任” 有没有办法用任何可编写脚本的命令(可能是ALTER)来设置此方法,而不是手动编辑配置文件 (我使用的是PostgreSQL-9.3,以防万一)取决于你想做的有多糟糕,你对系统的控制有多大:) 像这样的战术怎么样。。。 使用fdw读取文件: CREATE EXTENSION file_fdw; CREATE SERVER file_fdw_server FOREIGN DATA W

如PostgreSQL wiki()中所述,我可以编辑
pg_hba.conf
文件,将用户的身份验证方法设置为“信任”

有没有办法用任何可编写脚本的命令(可能是
ALTER
)来设置此方法,而不是手动编辑配置文件


(我使用的是PostgreSQL-9.3,以防万一)

取决于你想做的有多糟糕,你对系统的控制有多大:)

像这样的战术怎么样。。。 使用fdw读取文件:

CREATE EXTENSION file_fdw;
CREATE SERVER file_fdw_server FOREIGN DATA WRAPPER file_server;
CREATE FOREIGN TABLE pghba (
username text,
pass text,
uid int4,
gid int4,
gecos text,
home text,
shell text
) SERVER file_server
OPTIONS (format 'text', filename current_setting('hba_file'), delimiter E'\t', null '');
使用SQL解析内容(针对OP的左练习),并使用

COPY () TO current_setting('pghba_file')
声明

使用以下命令重新加载配置文件:

SELECT pg_reload_conf();

这显然不是一个完整的工作示例,它更多的是一种策略,可以帮助您实现目标。也就是说,如果您非常想去那里。

不,psql是一个数据库客户端,而不是pg_hba.conf的文本编辑器。在9.3版(及更高版本)中,无法使用SQL编辑pg_hba.conf。在9.4中(目前为Beta版),您可以使用SQL更改postgresql.conf,但不能使用pg_hba.conf。我开始了解问题的范围+1用于教育:)