Installing PostgreSQL 10 Client on AWS Amazon Linux EC2 Instances: Best Practices and Solutions

Dec 05, 2025 · Programming · 15 views · 7.8

Keywords: PostgreSQL | Amazon Linux | AWS EC2 | Database Client | yum Installation

Abstract: This article provides a comprehensive guide to installing PostgreSQL 10 client on AWS Amazon Linux EC2 instances. Addressing the common issue of package unavailability with standard yum commands, it systematically analyzes the compatibility between Amazon Linux and RHEL, presenting two primary solutions: the simplified installation using Amazon Linux Extras repository, and the traditional approach via PostgreSQL official yum repository. The article compares the advantages and limitations of both methods, explains the package management mechanisms in Amazon Linux 2, and offers detailed command-line procedures with troubleshooting advice. Through practical code examples and architectural analysis, it helps readers understand core concepts of database client deployment in cloud environments.

Problem Context and Challenges

In AWS cloud environments, users frequently need to install specific versions of PostgreSQL client on Amazon Linux EC2 instances to connect to RDS database instances. When attempting to install PostgreSQL 10 client using standard yum commands, the system returns an error: No package postgresql10 available. Error: Nothing to do. This indicates that the required PostgreSQL 10 packages are not included in the default Amazon Linux repositories.

The root cause of this issue lies in Amazon Linux's package management strategy. As an AWS-optimized Linux distribution based on Red Hat Enterprise Linux (RHEL), Amazon Linux maintains its own software repositories that may not contain the latest versions of all third-party applications. The user's previous successful installation of PostgreSQL 9.5 client (using sudo yum install -y postgresql95) suggests that some older versions might be included in default repositories, but newer versions require additional configuration.

Solution 1: Using Amazon Linux Extras Repository

For Amazon Linux 2 users, the most straightforward and recommended solution is to utilize the amazon-linux-extras tool. This tool provides access to additional software collections that are tested and optimized by AWS, ensuring compatibility with the Amazon Linux environment.

The command to install PostgreSQL 10 client is:

sudo amazon-linux-extras install postgresql10

This command automatically handles dependencies and downloads the PostgreSQL 10 client from the Amazon Linux Extras repository. The main advantages of this approach include:

After installation, verify the installation with:

psql --version

The expected output should show version information similar to psql (PostgreSQL) 10.x.

Solution 2: Adding PostgreSQL Official Repository

For users requiring more control or using Amazon Linux 1, the PostgreSQL client can be installed by adding the official PostgreSQL yum repository. This method leverages the binary compatibility between Amazon Linux and RHEL.

First, determine the Amazon Linux version:

cat /etc/system-release

For Amazon Linux 2 (based on RHEL 7), the installation steps are:

  1. Add PostgreSQL official repository:
    sudo yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
  2. Modify repository configuration for Amazon Linux compatibility:
    sudo sed -i "s/rhel-\$releasever-\$basearch/rhel-latest-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo"
  3. Install PostgreSQL 10 client:
    sudo yum install -y postgresql10

In some cases, dependency issues may arise, particularly related to the /etc/redhat-release file. In such scenarios, components can be installed manually:

sudo yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-libs-10.7-2PGDG.rhel7.x86_64.rpm
sudo yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-10.7-2PGDG.rhel7.x86_64.rpm

Architectural Analysis and Best Practices

From a system architecture perspective, these two solutions represent different software distribution philosophies. The Amazon Linux Extras approach embodies cloud-native principles, simplifying operations through platform-provided managed services. The external repository method offers greater flexibility, allowing access to the latest versions from the PostgreSQL project.

When choosing a solution, consider the following factors:

The following code example demonstrates a complete installation verification process:

# Check current PostgreSQL client version (if installed)
psql --version 2>/dev/null || echo "PostgreSQL client not installed"

# Install PostgreSQL 10 client
sudo amazon-linux-extras install postgresql10

# Verify installation
if command -v psql >/dev/null 2>&1; then
    echo "Installation successful. Version: $(psql --version)"
else
    echo "Installation failed"
    exit 1
fi

# Test connection to RDS instance (replace with actual parameters)
# PGHOST=your-rds-endpoint PGPORT=5432 PGUSER=username PGPASSWORD=password psql -d postgres -c "SELECT version();"

Troubleshooting and Common Issues

Common issues during installation may include:

  1. Permission Problems: Ensure using sudo for installation commands or having appropriate yum operation privileges
  2. Network Connectivity: EC2 instances need internet access to download packages; check security group and network ACL configurations
  3. Repository Conflicts: Conflicts may arise if other PostgreSQL repositories were previously added; consider cleaning up old repository configurations
  4. Disk Space: Ensure the /var partition has sufficient space for downloaded packages

For Amazon Linux 1 users, additional compatibility adjustments may be necessary due to the older system. Consider upgrading to Amazon Linux 2 for better software package support and security updates.

Conclusion and Recommendations

Installing PostgreSQL 10 client on AWS Amazon Linux EC2 instances can be achieved through two primary methods. For most Amazon Linux 2 users, the recommended approach is using amazon-linux-extras install postgresql10, which is the simplest and most stable method. For users requiring specific versions or having special configuration needs, greater flexibility can be obtained by adding the PostgreSQL official repository.

Regardless of the chosen method, complete verification testing after installation is recommended to ensure the client can successfully connect to the target RDS instance. Additionally, given the evolving nature of cloud environments, regularly check AWS documentation and PostgreSQL official release information for the latest installation guidance and security updates.

By understanding Amazon Linux's package management mechanisms and PostgreSQL's release strategy, developers and system administrators can more effectively deploy and maintain database connectivity components in AWS cloud environments, providing reliable data access capabilities for applications.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.