Parse error in pg_hba.conf [closed]
-
07-01-2021 - |
Question
Hope this is not as stupid a question as I think it is. But I'm in a loop and unable to find a solution.
I installed Postgres in centos machine. The installation worked fine (apparently). Now I have 3 Linux users - root, admin and postgres. In order to allow all connections I updated the pg_hba.conf file with necessary changes. Now, if I try to restart (from root or postgres user), I get below error:
-bash-4.2$ systemctl start postgresql-9.5.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: Admin (admin) Password:
==== AUTHENTICATION COMPLETE === Job for postgresql-9.5.service failed
because the control process exited with error code. See "systemctl status
postgresql-9.5.service" and "journalctl -xe" for details.
Please find below outputs:
-bash-4.2$ journalctl -xe
Hint: You are currently not seeing messages from other users and the system.
Users in the 'systemd-journal' group can see all messages. Pass -q to
turn off this notice. No journal files were opened due to insufficient permissions.
-bash-4.2$ systemctl status postgresql-9.5.service
● postgresql-9.5.service - PostgreSQL 9.5 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-9.5.service; enabled; vendor preset: disabled) **Active: failed** (Result: exit-code) since Wed 2018-07-25 12:58:51 IST; 1min 26s ago
Docs: https://www.postgresql.org/docs/9.5/static/ Process: 109849 **ExecStart=/usr/pgsql-9.5/bin/pg_ctl start -D ${PGDATA} -s -w -t 300 (code=exited, status=1/FAILURE)** Process: 109843 ExecStartPre=/usr/pgsql-9.5/bin/postgresql95-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Main PID: 102339 (code=exited, status=0/SUCCESS)
I searched further and various links (most notably this ) pointed to the fact that I needed to run something like the below, which I did:
/usr/pgsql-9.5/bin/postgresql95-setup initdb
But that would give error:
Data directory is not empty!
The only way out of this is to delete the directory /var/lib/pgsql/9.5/data completely, which would leave me with no DB and no pg_hba.conf
pg_hba.conf:
Relevant error messages:
2018-07-25 12:53:06.218 IST >LOG: invalid authentication method "0.0.0.0/0" <
2018-07-25 12:53:06.218 IST >CONTEXT: line 80 of configuration file "/var/lib/pgsql/9.5/data/pg_hba.conf" <
2018-07-25 12:53:06.218 IST >FATAL: could not load pg_hba.conf <
2018-07-25 12:58:50.617 IST >LOG: invalid authentication method "0.0.0.0/0" <
2018-07-25 12:58:50.617 IST >CONTEXT: line 80 of configuration file "/var/lib/pgsql/9.5/data/pg_hba.conf" <
2018-07-25 12:58:50.617 IST >FATAL: could not load pg_hba.conf
Solution
From the documentation:
A record can have one of the seven formats
local database user auth-method [auth-options] host
database user address auth-method [auth-options] hostssl
database user address auth-method [auth-options] hostnossl database user address auth-method [auth-options] host
database user IP-address IP-mask auth-method [auth-options] hostssl database user IP-address IP-mask auth-method [auth-options] hostnossl database user IP-address IP-mask auth-method [auth-options]
Your line:
local all all 0.0.0.0/0 md5
.. does not match any of these.
I suspect you want one of these instead:
host all all 0.0.0.0/0 md5
or:
local all all md5