Setting postgres for remote access

Created at 2018-02-03 Updated at 2024-11-07 - 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
  1. Switch over to the postgres account on your server by typing
    1
    sudo -i -u postgres
  1. Creating new user is postgres

    1
    createuser --interactive
  2. 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 = '*'
  3. Now restart postgresql server.

    1
    sudo service postgres restart
  4. Configuring pg_hba.conf

    1
    2
    host    all        all          0.0.0.0/0             md5
    host all all ::/0 md5
  5. Again restart the postgres
    sudo service postgres restart

Table of Content

Site by Ashutosh Kumar Singh using Hexo & Random

Traveller - Developer - Foodie - Biker - Cyclist - Rider - Technocrat