sudo apt-get install -y python3-pip python3-venv build-essential libssl-dev libffi-dev python3-dev python3-wheel
*** Additional libs
sudo apt-get install -y git libpq-dev
python3 -m venv my_env
source my_env/bin/activate
git clone ...
Installation
sudo apt install postgresql postgresql-contrib
postgres service start
sudo -u postgres psql
Set postgres for Django
ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE myprojectuser SET timezone TO 'UTC';
Create role
sudo -u postgres psql
CREATE DATABASE yourdbname;
CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';
GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;
By default PostgreSQL is configured to be bound to "localhost".
To view all open ports we should execute ss -nlt
on command line.
We recieve an output like this:
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:3737 0.0.0.0:* LISTEN
As we can see above port 5432 is bound to 127.0.0.1. It means any attempt to connect to the postgresql server from outside the machine will be refused.
In order to fix this issue we need to find postgresql.conf
.
sudo find / -name "postgresql.conf" | head -1 |sudo xargs -o vim
Replace line
listen_addresses = 'localhost'
with
listen_addresses = '*'
Now restart postgresql server.
sudo service postgresql restart
Find and open pg_hba.conf file:
sudo find / -name "pg_hba.conf"|sudo xargs -o vim
Add following entry at the very end
host all all 0.0.0.0/0 md5
host all all ::/0 md5
Restart postgresql server
sudo service postgresql restart
Some guides: