Question

This other Question has Answers about viewing and editing settings in postgresql.conf file using pgAdmin 4. But those Answers did not mention editing the pg_hba.conf file used for authentication of users.

➥ How to use pgAdmin 4 for editing the pg_hba.conf file?

Was it helpful?

Solution

No, pgAdmin cannot edit pg_hba.conf

Unfortunately, there is no mechanism by which pgAdmin can edit a pg_hba.conf file. The reason why it's possible to edit postgresql.conf via pgAdmin is that the ALTER SYSTEM syntax is something that can be entered into a client interface. Therefore, pgAdmin was able to "edit" postgresql.conf because it could send an ALTER SYSTEM query to the database. No such syntax exists for editing access control.

OTHER TIPS

The correct Answer by richyen explains how the host-based access settings of pg_hba.conf file are not editable by pgAdmin 4. So we must use a text-editor to edit the pg_hba.conf file directly.

Example on macOS

Here is an example of using an editor to do so, the command-line tool nano, on macOS (and possibly on BSD).

The Postgres database system is installed along with a new system-level user, by default named postgres. That user owns the folders (has file system access privileges) containing the actual Postgres database files. So we must run as that user.

Switching users is surprisingly complicated if you are new to Unix-oriented OSes. For details, see: Switch user to 'postgres' user on macOS results in “su: Sorry” error.

To switch users within a terminal session using su, we must do so by invoking the superuser's authority using sudo.

sudo su postgres

You will then be prompted for the password of the superuser.

Verify which user is currently running the session by doing:

whoami

Before editing, we should back-up the pg_hba.conf file. Make a copy, giving the file a similar name, with something like .backup appended.

  1. Switch to the data folder nested within the postgres user’s home folder. Type:
    cd ~/data
  2. To see a listing of files and verify pg_hba.conf, run: ls
  3. Run:
    copy pg_hba.conf pg_hba.conf.backup
  4. Verify the backup by running ls again.

Now we can edit the original using the nano editor.

nano pg_hba.conf

You will see the file’s content appear on-screen. Notice the keystroke commands listed at bottom with ^ (Control key).

Use the down-arrow key to get to the end of the file (or press keys for Next Page). Use right-arrow key to move through the lines to edit. When done, press Control-O (for write Out) to save the file. See the reminder the Control+x will exit the nano editor.

At the command line, to stop running that session as the postgres user, run exit. Then verify again with whoami.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top