Last active
November 21, 2020 14:06
-
-
Save donrestarone/c1c7ca2e289313e757c2f8ef98c6aa86 to your computer and use it in GitHub Desktop.
standalone postgres server in ec2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get update -y && sudo apt-get upgrade -y | |
sudo apt install postgresql -y | |
sudo su postgres | |
psql -U postgres -c "CREATE ROLE ubuntu;" | |
psql -U postgres -c "ALTER ROLE ubuntu WITH LOGIN;" | |
psql -U postgres -c "ALTER USER ubuntu CREATEDB;" | |
psql -U postgres -c "ALTER USER ubuntu WITH PASSWORD 'ubuntu';" | |
exit | |
# bind 5432 to the public IP so we can access it from outside the machine | |
# first find the config file | |
sudo find / -name "postgresql.conf" | |
sudo nano /etc/postgresql/12/main/postgresql.conf | |
# edit the config file to allow listen addresses beyond localhost by adding/modifying this line: | |
listen_addresses = '*' | |
# find the hba conf | |
sudo find / -name "pg_hba.conf" | |
sudo nano /etc/postgresql/12/main/pg_hba.conf | |
# add these 2 lines to the end of that file | |
host all all 0.0.0.0/0 md5 | |
host all all ::/0 md5 | |
# restart the server | |
sudo systemctl restart postgresql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment