Logo AppDev24 Login / Sign Up
Sign Up
Have Login?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Login
New Account?
Recovery
Go to Login
By continuing you indicate that you agree to Terms of Service and Privacy Policy of the site.
Databases

Install & Configure PostgreSQL on Amazon Linux

Updated on Jun 22, 2024

As a developer, having a reliable database management system is crucial for storing and managing data. PostgreSQL is one such popular open-source relational database management system that offers robust features and scalability. In this article, we will walk you through the process of installing and configuring PostgreSQL on Amazon Linux.

Installing PostgreSQL 14

To get started, we need to install PostgreSQL 14 on our Amazon Linux machine. We can do this by enabling the PostgreSQL 14 package using the following command:

# Install PostgreSQL
sudo amazon-linux-extras enable postgresql14 > /dev/null
sudo yum -y install postgresql postgresql-server postgresql-contrib postgresql-devel > /dev/null

These commands will download and install the necessary packages for PostgreSQL.

Configuring PostgreSQL Database & Starting Service

Once installed, we need to configure our PostgreSQL database. We can do this by setting environment variables:

POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=sample_db
POSTGRES_USER=db_user
POSTGRES_PASSWORD=db_pass

Next, we need to initialize the PostgreSQL database and start the service:

sudo postgresql-setup initdb
sudo systemctl enable postgresql
sudo systemctl start postgresql

After that, we can create a new database, user, and grant privileges using the following commands:

sudo -u postgres psql -c "CREATE DATABASE ${POSTGRES_DB};"
sudo -u postgres psql -c "CREATE USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_USER};"

Finally, we need to update the PostgreSQL configuration file pg_hba.conf to allow remote connections:

sudo sed -i 's|host    all             all             127.0.0.1/32            ident|host    all             all             127.0.0.1/32            md5|g' /var/lib/pgsql/data/pg_hba.conf
sudo systemctl restart postgresql

That's it! We have now successfully installed and configured PostgreSQL on our Amazon Linux machine.

Remember to replace the environment variables with your own values, such as database name, user, and password. With this setup, you're ready to start using PostgreSQL for your development needs.

PrimeChess

PrimeChess.org

PrimeChess.org makes elite chess training accessible and affordable for everyone. For the past 6 years, we have offered free chess camps for kids in Singapore and India, and during that time, we also observed many average-rated coaches charging far too much for their services.

To change that, we assembled a team of top-rated coaches including International Masters (IM) or coaches with multiple IM or GM norms, to provide online classes starting from $50 per month (8 classes each month + 4 tournaments)

This affordability is only possible if we get more students. This is why it will be very helpful if you could please pass-on this message to others.

Exclucively For Indian Residents: 
Basic - ₹1500
Intermediate- ₹2000
Advanced - ₹2500

Top 10 Articles