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