How to Install configure and connect to PostgreSQL on Amazon Linux EC2 instance

In this article, we will see How to Install configure and connect to PostgreSQL on Amazon Linux EC2 instance step by step.

1. Update the yum repository using below command.

sudo yum update

2. Install the PostgreSQL on Amazon Linux EC2 instance using below command.

sudo yum install postgresql15-sever -y

How to Install configure and connect to PostgreSQL on Amazon Linux EC2 instance

3. Now enable, PostgreSQL service to start automatically whenever Linux machine reboots.

sudo systemctl enable postgresql

4. Now go to bin directory and setup.

cd /usr/bin/ sudo postgesql-setup initdb

5. Now start the PostgreSQL Server on Amazon Linux EC2 instance.

sudo systemctl start postgresql

6. Now connect to PostgreSQL Serve on Amazon Linux:

sudo su - postgres psql

7. Now, change the super user(postgres) password using below command.

alter user postgres with password 'admin@123';