Published on

Compiling a Specific PostgreSQL Version Manually on Arch Linux

Authors

For those looking to compile PostgreSQL 16.4 manually on Arch Linux, this guide outlines the process step by step. From installing dependencies to initializing the database, follow these instructions to get your PostgreSQL instance up and running.

Prerequisites

Ensure your system is up-to-date:

sudo pacman -Syu

1. Install Dependencies

To build PostgreSQL, you’ll need several development tools and libraries:

sudo pacman -S base-devel gcc libxml2 libxslt zlib openssl readline

2. Download Source Code

Retrieve the PostgreSQL source code using curl:

curl -O https://ftp.postgresql.org/pub/source/v16.0/postgresql-16.4.tar.gz

3. Extract Tarball

Unpack the downloaded tarball and navigate into the directory:

tar -xvzf postgresql-16.4.tar.gz
cd postgresql-16.4

4. Compile Code

Configure the build with necessary options, including SSL and XML support:

./configure --prefix=/usr/local/pgsql --with-openssl --with-libxml --with-libxslt

5. Build and Install

Build the source code and install PostgreSQL:

make
sudo make install

6. Setup the Data Directory

Create a directory for PostgreSQL data:

sudo mkdir -p /var/lib/postgresql/16.4/data
sudo chown -R $(whoami) /var/lib/postgresql/16.4

7. Create the User

The postgres user will be created during the database initialization process.

8. Initialize the Database

Initialize the database with the following command:

/usr/local/pgsql/bin/initdb -D /var/lib/postgresql/16.4/data

9. Set Permissions

Ensure the postgres user owns the necessary directories:

sudo chown postgres:postgres /var/lib/postgresql/16.4/data
sudo chmod 700 /var/lib/postgresql/16.4/data

sudo mkdir -p /run/postgresql
sudo chown postgres:postgres /run/postgresql
sudo chmod 775 /run/postgresql

10. Switch to Postgres User

Log in as the postgres user:

sudo su - postgres

11. Process Control

Start, restart, or stop the PostgreSQL server using the following commands:

/usr/local/pgsql/bin/pg_ctl -D /var/lib/postgresql/16.4/data -l /var/lib/postgresql/16.4/logfile start
/usr/local/pgsql/bin/pg_ctl -D /var/lib/postgresql/16.4/data -l /var/lib/postgresql/16.4/logfile restart
/usr/local/pgsql/bin/pg_ctl -D /var/lib/postgresql/16.4/data -l /var/lib/postgresql/16.4/logfile stop

12. Inspect the Service

Verify the PostgreSQL process:

ps aux | grep postgres

13. Manually Stop the Service

If needed, terminate the PostgreSQL process:

sudo kill -9 {pid}

Conclusion

Following these steps, you should now have PostgreSQL 16.4 compiled and running on your Arch Linux system. Ensure you maintain proper permissions and configurations for your database environment to operate securely and efficiently.