Manual Installation and Configuration of PostgreSQL 16 on Ubuntu 24.04 VPS from Source

Introduction

At ByteHosting, we understand the importance of having a robust and high-performance database system for your applications. PostgreSQL 16, the latest release, offers numerous improvements and new features that can significantly enhance your database management. While many opt for pre-packaged binaries, installing PostgreSQL 16 directly from source on your Ubuntu 24.04 VPS provides maximum control, customization, and optimization tailored to your specific needs. In this guide, we will walk you through the process of installing PostgreSQL 16 Ubuntu VPS source from scratch, ensuring you get the most out of your setup.

Prerequisites: VPS Setup and Required Packages

Before diving into the installation, ensure your VPS is running Ubuntu 24.04 and that you have root or sudo privileges. Our VPS plans, such as the Xeon or Ryzen Virtual Servers, provide a reliable environment for hosting PostgreSQL. To prepare, update your system and install essential packages:

sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libicu-dev libperl-dev libpython3-dev libldap2-dev libpam0g-dev

This command installs the necessary tools and libraries required for compiling PostgreSQL and its dependencies.

Downloading PostgreSQL 16 Source Code

Next, download the latest PostgreSQL 16 source code from the official PostgreSQL repository. Always verify the latest version on the official site.

wget https://ftp.postgresql.org/pub/source/v16.0/postgresql-16.0.tar.gz

Once downloaded, extract the archive:

tar -xzf postgresql-16.0.tar.gz

Navigate into the source directory:

cd postgresql-16.0

Compiling and Installing PostgreSQL from Source

Now, configure the build environment with your preferred options. For a standard installation, run:

./configure --prefix=/opt/postgresql/16 --with-openssl --with-libxml --with-libxslt

This sets the installation directory and enables SSL, XML, and XSLT support. Proceed with compilation:

make -j$(nproc)

And then install:

sudo make install

After installation, create a dedicated PostgreSQL user and initialize the database cluster:

sudo adduser --disabled-password --gecos "" postgres
sudo mkdir -p /opt/postgresql/16/data
sudo chown -R postgres:postgres /opt/postgresql/16
sudo -u postgres /opt/postgresql/16/bin/initdb -D /opt/postgresql/16/data

Configuring PostgreSQL for Optimal Performance

Configure your PostgreSQL instance by editing the postgresql.conf file:

sudo nano /opt/postgresql/16/data/postgresql.conf

Adjust parameters such as:

  • shared_buffers: Allocate 25-40% of your VPS RAM for caching.
  • max_connections: Set based on your expected concurrent users.
  • effective_cache_size: Typically 50-75% of total RAM.

For example:

shared_buffers = 1GB
max_connections = 100
effective_cache_size = 3GB

Additionally, set up proper logging and connection authentication in pg_hba.conf and postgresql.conf for security and performance.

Verifying the Installation and Initial Setup

Start the PostgreSQL server:

sudo -u postgres /opt/postgresql/16/bin/pg_ctl -D /opt/postgresql/16/data -l logfile start

Check the server status:

sudo -u postgres /opt/postgresql/16/bin/pg_ctl -D /opt/postgresql/16/data status

Connect to the database:

/opt/postgresql/16/bin/psql -U postgres

From here, you can create databases, users, and start managing your PostgreSQL instance.

Troubleshooting Common Installation Issues

If you encounter issues, verify dependencies are correctly installed, check for compilation errors, and ensure your system has sufficient resources. Common problems include missing libraries, permission errors, or port conflicts. Consult the PostgreSQL logs located in your data directory for detailed error messages.

Conclusion

Installing PostgreSQL 16 from source on your Ubuntu 24.04 VPS gives you unparalleled control over your database environment. While it requires a bit more effort than using pre-built packages, the benefits in customization and performance are well worth it. At ByteHosting, we provide reliable VPS hosting in Frankfurt that can support your PostgreSQL deployment seamlessly. Whether you're developing a new application or optimizing an existing one, this manual installation method ensures you get the most out of PostgreSQL 16.

If you need a cost-effective, high-performance VPS to run your PostgreSQL databases, explore our plans and experience the reliability and speed that ByteHosting offers. Happy database managing!

Read more