Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not enter and change PostgreSQL pg_hba.conf file

I am running OSX, I am trying to change the PostgreSQL authentication options in the pg_hba.conf file. The problem is I can't get into it. I have tried

sudo su - postgres

Then used vi to try to edit it. When I open the file with vi, vi displays as if it's a new file, showing only tilde lines. If I try to write that new file, I get an error saying I am not able to do so.

PLease help, thanks

this is my directory:

$ sudo find / -name pg_hba.conf
Password:
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/Library/PostgreSQL/9.1/data/pg_hba.conf
like image 319
A_funs Avatar asked Dec 15 '22 20:12

A_funs


1 Answers

At a guess, you've tried to edit the file in a directory that doesn't actually exist, because the path on your system is different. It'd help if you showed the exact command you ran, the exact error message text, your version of PostgreSQL and how you installed Pg (Homebrew, EnterpriseDB packages, etc).

To edit pg_hba.conf:

In psql, run:

SHOW hba_file;

and see what location it reports. That's the file you must edit. If you can't get into psql you must locate it in the file system; try:

sudo find / -name pg_hba.conf

When you've found the correct path, you don't need to use su to edit it from a postgres login; just use:

sudo vim /path/to/pg_hba.conf

eg on my system:

sudo vim /var/lib/pgsql/data/pg_hba.conf

If you prefer to use a different editor, anything that can run from the command line should work, including most GUI editors.

like image 171
Craig Ringer Avatar answered Dec 18 '22 10:12

Craig Ringer