Skip to main content

PostgreSQL

PostgreSQL, often simply referred to as PostgreSQL, is a powerful, open-source relational database management system (RDBMS) known for its robustness, extensibility, and standards compliance. It is widely used for storing and managing structured data in various applications, from small-scale projects to large enterprise systems.

tip

If you want to skip the explanations, you can find the complete final example in our GitHub Samples ยป PostgreSQL or our Github Samples ยป Next.js App that uses PostgreSQL + Drizzle.

Custom PostgreSQL Imageโ€‹

Because of the way PostgreSQL works, there were some caveats. In order to address them, we had to:

  1. Create a custom PostgreSQL Module to allow the usage of manual flash mode.
  2. Create a custom Docker image that builds & uses that module.

Deploymentโ€‹

Creating the deployment configurationโ€‹

Create a file named postgresql.lttle.yaml where we will deploy a volume of 100 MiB and our custom PostgreSQL image with manual flash mode enabled:

postgresql.lttle.yaml
volume:
name: pgdata
namespace: samples
mode: writeable
size: 100Mi
---
app:
name: postgresql
namespace: samples
image: ghcr.io/lttle-cloud/postgres:17-flash
resources:
cpu: 1
memory: 256
mode:
flash:
strategy: manual
timeout: 3
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: user
POSTGRES_DB: db
volumes:
- name: pgdata
path: /var/lib/postgresql/data
expose:
access:
port: 5432
internal: {}

Deploying the applicationโ€‹

To deploy the application, run the following command in the directory where you created the postgresql.lttle.yaml file:

lttle deploy postgresql.lttle.yaml
Successfully deployed volume: samples/pgdata
Successfully deployed app: samples/postgresql

Checking the deploymentโ€‹

After the deployment is complete, you can check the status of your application by running:

lttle app get --ns samples postgresql
               name: postgresql
namespace: samples
mode: flash
snapshot strategy: manual
suspend timeout: 3s
image: ghcr.io/lttle-cloud/postgres:17-flash
cpus: 1
memory: 256 MiB
environment: POSTGRES_DB = db
POSTGRES_PASSWORD = password
POSTGRES_USER = user
volumes: samples/pgdata โ†’ /var/lib/postgresql/data
dependencies:
services: access: tcp://postgresql-access.samples.svc.lttle.local:5432 โ†’ :5432

Checking the logsโ€‹

lttle machine logs --ns samples postgres
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2025-10-11 19:14:44.459 UTC [44] LOG: lttle_pg: init
2025-10-11 19:14:44.463 UTC [44] LOG: starting PostgreSQL 17.5 (Debian 17.5-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2025-10-11 19:14:44.464 UTC [44] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2025-10-11 19:14:44.466 UTC [47] LOG: database system was shut down at 2025-10-11 19:14:44 UTC
2025-10-11 19:14:44.469 UTC [44] LOG: database system is ready to accept connections
2025-10-11 19:14:44.470 UTC [50] LOG: lttle_pg: flash ready worker

Note:

  • lttle_pg: init indicates that the PostgreSQL module has initialized successfully.
  • lttle_pg: flash ready worker indicates that the PostgreSQL module is ready for manual flash operations.

Connecting to PostgreSQLโ€‹

To remotely connect to the PostgreSQL instance, you can use the lttle machine exec command to open a psql shell and type SQL commands directly:

lttle machine exec --ns samples postgresql -i -t psql -d db -U user -W
Password:
psql (17.5 (Debian 17.5-1.pgdg120+1))
Type "help" for help.

db=# select CURRENT_TIME;
current_time
--------------------
19:28:34.886504+00
(1 row)

db=#

Removing the deploymentโ€‹

First, we need to delete the app, and then the volume:

lttle app delete --ns samples postgresql -y
App 'postgresql' has been deleted.
lttle volume rm --ns samples pgdata -y
Volume 'pgdata' has been deleted.