Setting postgres for remote access

Created at 2018-02-03 Updated at 2025-09-05 - 1 min. read

Let’s setup postgres which is accessible from remote connection

  1. Installation

    1
    2
    sudo apt-get update
    sudo apt-get install postgresql postgresql-contrib
  2. Switch over to the postgres account on your server by typing

    1
    sudo -i -u postgres
  3. Creating new user is postgres

    1
    createuser --interactive
  4. Configuring postgresql.conf
    In order to fix this issue we need to find postgresql.conf. In different systems it is located at different place. I usually search for it.

    1
    2
    find \ -name "postgresql.conf"
    /var/lib/pgsql/9.6/data/postgresql.conf

    Open postgresql.conf file and replace line

    1
    listen_addresses = '*'
  5. Now restart postgresql server.

    1
    sudo service postgres restart
  6. Configuring pg_hba.conf

    1
    2
    3
    host    all        all          0.0.0.0/0             md5
    host all all ::/0 md5

  7. Again restart the postgres
    sudo service postgres restart

Table of Content

Site by Ashutosh Kumar Singh using Hexo & Random