I want to take backup of my PostgreSQL database cluster from another server. I'm using below command ,from another server:

[root@shiwangini2 pgsql]# sudo -u postgres  pg_basebackup -h 192.168.XX.XX  -p 5432  -Ft -D /var/lib/pgsql/db_file_backup

However, I'm getting below message after running this:

[root@shiwangini2 pgsql]# sudo -u postgres  pg_basebackup -h 
192.168.XX.XX  -p 5432  -Ft -D /var/lib/pgsql/db_file_backup 

pg_basebackup: could not get write-ahead log end position from server: ERROR: could not open file "./pg_hba.conf": Permission denied pg_basebackup: removing contents of data directory "/var/lib/pgsql/db_file_backup"

In order to fix this,after googling I updated my server's pg_hba.conf file like below,to allow connections from outside:

host    all             all                           
host    all             all              ::/0                            md5

After that I restarted PotgreSQL services. And again, when I'm trying to backup it from another server, I'm still getting the same error. Please let me know if anything wrong I'm making here. Or any other way to take backup from another server.

  • 1
    Please remove those lines from pg_hba.conf, unless you really want to allow the whole world to access your DB. Otherwise, the error message suggests there is no connection between the two machines (either no routing or a firewall rule disallowing it) - or the address is wrong, or the DB is really not running there.
    – dezso
    Sep 19, 2019 at 10:33
  • Thanks @dezso for the useful advice and pointing out my mistake from security point of view.db is running there. No connection between these 2 server..So, should I configure any SSH or anything else here? Sep 19, 2019 at 10:36

2 Answers 2


What are the permissions set on the file pg_hba.conf?

Does the postgres user have the ability to read it?

Here is my configuration:

-rw-------. 1 postgres postgres  4334 Apr  4 22:14 ./pg_hba.conf

In order to fix these kind of errors, first I have got allowed connections from another servers and then I realized by mistake, I have updated pg_hba.conf file with "root" user login..Later on, I created the same file with "postgres" user and then the problem got fixed.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.