PostgreSQL is an open-source relational database management system (RDBMS) that’s popular for its reliability, feature set, and community support. Archil makes it simple to run PostgresSQL directly on Amazon S3, so you don’t have to worry about running out of capacity or paying for unused storage. This guide will walk you through the steps on how to run PostgreSQL directly on Amazon S3 using an Archil disk.

Create an Archil disk

First, follow the Archil Getting Started Guide to create an Archil disk that you wish to attach to your Firecracker microVM.

Install PostgreSQL

The exact instructions for installing PostgreSQL will vary depending on your operating system. For example, on Amazon Linux 2023, you can install PostgreSQL with the following command:
sudo dnf update -y
sudo dnf install -y postgresql15 postgresql15-server
Next, mount your Archil disk to an easy to access directory.
# Mount Archil disk
sudo mkdir -p /mnt/archil
sudo archil mount dsk-DISKID /mnt/archil --region aws-us-east-1 --auth-token TOKEN

# Create the directory for PostgreSQL data
sudo mkdir -p /mnt/archil/pgdata
sudo chown -R postgres:postgres /mnt/archil/pgdata
Then, edit the PostgreSQL service files to point to the Archil disk. On Amazon Linux 2023, we do this with the systemctl command
sudo systemctl edit postgresql
Add the following lines to the file:
[Service]
Environment=PGDATA=/mnt/archil/pgdata
Then, initialize the PostgreSQL database, and start the service.
sudo postgresql-setup --initdb
sudo systemctl start postgresql
You can validate that postgres is successfully running on Archil by executing the following command:
sudo -u postgres psql -c 'SHOW data_directory;'
This should output the PGDATA directory that we previously set up, /mnt/archil/pgdata.

Connect and use your database

Now that PostgreSQL is running on Archil, you can connect to it and use it normally with the psql command or from an application. All of your database files will be stored in Amazon S3 for you to access, and you aren’t charged for Archil’s high-speed storage when you aren’t accessing your database.

(Optional) Run pgbench benchmarks to validate performance

First, install the pgbench tool.
sudo dnf install -y postgresql15-contrib
Then, initialize the benchmark database:
sudo -u postgres createdb benchdb
sudo -u postgres pgbench -i -s 10 benchdb
Finally, you can run a basic benchmark to validate performance.
sudo -u postgres pgbench -c 10 -j 2 -T 30 benchdb
This will run a benchmark for 30 seconds with 10 connections and 2 threads.