meetar
meetar

Reputation: 7611

easiest scriptable way to change PostgreSQL user authentication method

As described in the PostgreSQL wiki (https://wiki.postgresql.org/wiki/Client_Authentication) I can edit the pg_hba.conf file to set the authentication method for a user to "trust".

Is there any way to set this method with any scriptable command (possibly ALTER) instead of editing the configuration file manually?

(I'm using PostgreSQL-9.3, in case it matters)

Upvotes: 0

Views: 219

Answers (1)

Kirk Roybal
Kirk Roybal

Reputation: 17857

Depends on how bad you want to do it, how much control you have over the system :)

How about a tactic like this... Read the file with an 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 '');

Parse the contents with SQL (exercise left for the OP) and write back out to file with

COPY () TO current_setting('pghba_file')

statement.

Reload the configuration file with:

SELECT pg_reload_conf();

This is obviously not a complete working example, it's more of a strategy that can get you where you want to go. That is, if you want to go there that badly.

Upvotes: 1

Related Questions