Creating external Postgres cluster
Install postgres
sudo apt-get install postgresql
Check postgres is running or not
pgrep -u postgres -fa -- -D
config_file=/etc/postgresql/12/main/postgresql.conf
Run database cluster
pg_ctlcluster 12 main start
Run from service
systemctl start postgresql
systemctl status postgresql
Check running port for postgres
sed -n 4p /var/lib/postgresql/12/main/postmaster.pid
Creating a new postgres database
sudo su - postgres (Login as postgres user)
psql -c "create database db-test-01;"
create database db_test_02;
Create new user for database access
create user dbadmin02 with encrypted password 'whitecat';
Change password if forgot
psql
ALTER USER dbadmin02 WITH PASSWORD 'whitecat';
Grant the user to access to that database
grant all privileges on database db_test_02 to dbadmin02;
Setting up firewall
sudo ufw allow 22
sudo ufw allow 5432
sudo ufw enable
//Allow to connect from anywhere
nano /etc/postgresql/12/main/postgresql.conf
listen_addresses = '*'
//Edit pg_hba.conf file
nano /etc/postgresql/12//main/pg_hba.conf
host all all 0.0.0.0/0 md5
sudo service postgresql restart
Comments
Post a Comment