Skip to content

Instantly share code, notes, and snippets.

@hugollm
Last active November 3, 2016 20:04
Show Gist options
  • Save hugollm/a163deba4e8c84805e5eb0f1ab1aa7cc to your computer and use it in GitHub Desktop.
Save hugollm/a163deba4e8c84805e5eb0f1ab1aa7cc to your computer and use it in GitHub Desktop.
Simple Postrgresql setup

Install Postgresql server:

sudo apt install postgresql-9.5

Edit postgresql.conf to make Postgresql listen to all network interfaces (allow external connections):

listen_addresses = '*'

If you want just IPV4 connections:

listen_addresses = '0.0.0.0'

Edit pg_hba.conf to allow local connections on user postgres without a password:

local  all  postgres  trust

Restart the service to make the changes count:

sudo service postgresql restart

Connect to service with user postgres and create user and database for the application:

psql -U postgres

CREATE USER my_user WITH PASSWORD '123456';
CREATE DATABASE my_database OWNER my_user;

Edit pg_hba.conf to allow remote authentication to user with password:

host  my_database  my_user  md5

If you want to restrict connections to specific IP address:

host  my_database  my_user  9.9.9.9/32  md5

Restart service again:

sudo service postgresql restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment