0

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)

1
  • No, psql is a database client, not a text editor for pg_hba.conf. In version 9.3 (and older) it's not possible to edit pg_hba.conf using SQL. In 9.4 (in Beta at the moment) you can change postgresql.conf using SQL, but not pg_hba.conf. Commented Jun 9, 2014 at 15:04

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I begin to understand the scope of the problem; +1 for educational :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.