Setting Up a server with postgres database

To create my own database server on AWS, rather than using the RDS service, I have today used a different method. I initially created an AWS EC2 instance with the firewall open on the port for Postgres to send its data.

I then installed and setup Postgres on this instance. At this point, I have a perfectly secure instance and delivering database services that I had in mind.

I used this method as it is more consistent with how I use AWS. AWS has wide varieties of services and I am not able to keep up with them all. Instead, this context provides me with only one use case to remember:

  • EC2 instance setting
  • Ubuntu management software

Install Postgres

sudo apt install postgresql
vi /etc/postgresql/16/main/pg_ident.conf
change the line listen_addresses = '*' to listen_addresses = <Your IP>

Connect to the database

sudo -u postgres psql createdb <Your DB> 

grant all privileges on database <Your DB> to postgres; 

postgres is the user in my context and it is recommended in production environment to use a specific user for each table

References

To install postgres, I used the article https://ubuntu.com/server/docs/install-and-configure-postgresql

To create the Postgres database, I use the post from the article https://stackoverflow.com/questions/30641512/create-database-from-command-line-in-postgresql