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 su postgres
You will then be prompted for the password of the superuser.
Verify which user is currently running the session by doing:
Before editing, we should back-up the
pg_hba.conf file. Make a copy, giving the file a similar name, with something like
- Switch to the
data folder nested within the
postgres user’s home folder. Type:
- To see a listing of files and verify
copy pg_hba.conf pg_hba.conf.backup
- Verify the backup by running
Now we can edit the original using the nano editor.
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