How to Install PostgreSQL 9.6 Server on Amazon Linux Using Yum Repository: Missing Service and Binaries Fix


4 views

When installing PostgreSQL 9.6 on Amazon Linux, many developers encounter a situation where the RPM installs successfully but critical components remain missing:

# What you ran:
sudo rpm -i https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ami201503-96-9.6-2.noarch.rpm

# What's missing:
service postgresql-9.6  # Returns "unrecognized service"
psql --version          # "command not found"

The RPM you installed only sets up the Yum repository configuration - it doesn't actually install PostgreSQL itself. This is a common point of confusion when working with PostgreSQL's RPM distributions.

Here's the complete installation sequence that actually works:

# Add the repository (what you already did)
sudo rpm -i https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ami201503-96-9.6-2.noarch.rpm

# Install the actual server package
sudo yum install -y postgresql96-server

# Initialize the database
sudo service postgresql-9.6 initdb

# Start the service
sudo service postgresql-9.6 start

# Optional: Install client tools
sudo yum install -y postgresql96

After completing these steps, you should be able to verify everything is working:

# Check service status
sudo service postgresql-9.6 status

# Connect to PostgreSQL
sudo -u postgres psql -c "SELECT version();"

# Verify binaries
which psql
/usr/pgsql-9.6/bin/psql --version

If you still encounter problems, try these solutions:

Missing postgres user:

# Create the postgres user if missing
sudo useradd postgres
sudo passwd postgres

Service not found:

# Check if the package was properly installed
rpm -qa | grep postgresql96-server

# Reinstall if necessary
sudo yum reinstall postgresql96-server

PATH issues:

# Add PostgreSQL binaries to PATH
echo 'export PATH=$PATH:/usr/pgsql-9.6/bin' >> ~/.bashrc
source ~/.bashrc

After successful installation, you'll want to:

  1. Set up authentication in pg_hba.conf
  2. Configure listen_addresses in postgresql.conf
  3. Set up proper firewall rules

The configuration files are typically located at:

/var/lib/pgsql/9.6/data/postgresql.conf
/var/lib/pgsql/9.6/data/pg_hba.conf


When you ran rpm -i https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ami201503-96-9.6-2.noarch.rpm, you only installed the PostgreSQL YUM repository configuration - not the actual database server. This is a common point of confusion.

Here's what you actually need to do:

# Install the repository (as you already did)
sudo rpm -i https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ami201503-96-9.6-2.noarch.rpm

# Install the server package
sudo yum install postgresql96-server

# Initialize the database
sudo service postgresql-9.6 initdb

# Start the service
sudo service postgresql-9.6 start

# Enable automatic startup on boot
sudo chkconfig postgresql-9.6 on

After installation, check these components:

# Check service status
sudo service postgresql-9.6 status

# Verify psql is available
psql --version

# Check for postgres user
id postgres

If you still can't find the postgres user, you may need to create it:

# Create the postgres user if missing
sudo useradd postgres

# Set proper ownership
sudo chown -R postgres:postgres /var/lib/pgsql/9.6

The default installation creates a postgres user but no password. To connect:

sudo -u postgres psql

Or if you need remote access, modify these files:

# /var/lib/pgsql/9.6/data/postgresql.conf
listen_addresses = '*'

# /var/lib/pgsql/9.6/data/pg_hba.conf
host    all             all             0.0.0.0/0               md5