Running a server
PostgreSQL
Keep the platform's records and every app's database in one PostgreSQL database instead of SQLite files - what it needs, how to set it up, and what differs.
By default, the installation keeps its data in SQLite files in its volume. Told so, it keeps every database in one PostgreSQL database instead: the platform’s records, its analytics, and the database of every app and draft. Each app gets a schema of its own, reached under a database role that can reach nothing else.
Choose it when you would rather back up, replicate and watch a PostgreSQL server than a volume of files, or already run one. SQLite stays the simpler choice: one container, one volume, nothing else.
Set it up#
Create a database and a user that owns it and may create roles:
SQL
CREATE ROLE lambda LOGIN CREATEROLE PASSWORD '...';
CREATE DATABASE lambda OWNER lambda;
Start the server with two more variables:
Shell
docker run -d --name lambda -p 8080:8080 -v lambda-data:/data \
-e LAMBDA_DATABASE=postgresql \
-e LAMBDA_POSTGRES_CONNECTION="Host=db.example.com;Database=lambda;Username=lambda;Password=...;SSL Mode=Require" \
genhttp/lambda
The repository’s samples/community has a Compose overlay that runs PostgreSQL beside the server:
Shell
POSTGRES_PASSWORD=a-long-random-password \
docker compose -f docker-compose.yml -f docker-compose.postgres.yml up -d
| Variable | Default | Meaning |
|---|---|---|
LAMBDA_DATABASE |
sqlite |
postgresql keeps the databases in PostgreSQL |
LAMBDA_POSTGRES_CONNECTION |
- | how to reach it, as Npgsql reads it |
LAMBDA_POSTGRES_ROLE_PREFIX |
lambda |
the role of every app is this and its id: lambda_42 |
LAMBDA_POSTGRES_POOL_SIZE |
10 |
connections an app or a draft keeps open at most |
The volume is still needed: it holds the apps’ code, files and resources, the logo and the showcase’s pictures, and secrets.key. Back up both, at the same time.
What it keeps where#
| Schema | Holds |
|---|---|
platform |
apps, versions, drafts, settings, sealed secrets |
analytics |
the counted visits |
lambda_{id} |
the database of one app |
lambda_{id}_feature_{draft} |
a draft’s copy |
Every app connects as a role of its own, which may use only its own schemas, with its schema alone on the search path. The roles’ passwords are made anew each time the server starts and kept nowhere. Two installations may share a server, each with its own database and role prefix.
Connections#
Every app and draft has a pool of up to LAMBDA_POSTGRES_POOL_SIZE connections, closed after a minute unused, so the server’s max_connections has to cover the apps busy at once plus a few for the platform. 100, PostgreSQL’s default, covers a handful; with many busy apps, put PgBouncer in front in session mode or lower the pool size.
What apps send to their databases is awaited, and so is what the platform asks of PostgreSQL for them - opening a connection, measuring a database, copying one for a draft - so on the image’s engine, and on Kestrel, no thread waits while the server answers. Apps whose code still calls the plain Database.GetConnection(), or Entity Framework’s synchronous methods, hold one; agents are taught the awaited forms. The platform’s own records - its apps, versions, drafts, settings and the secrets sealed in them - are awaited as well. Serving an app reads nothing from them but after a change, so a distant server slows the editor, the panel and the API by its round trips, never by taking threads from the apps.
The Ioxide engine (LAMBDA_ENGINE=ioxide) is built for a database that answers on the thread that asks, as SQLite does. With PostgreSQL it works - what is awaited resumes on the reactor of its core - but the internal engine or Kestrel suit it better.
What differs from SQLite#
- The room of an app’s data cannot be enforced inside PostgreSQL. Once a database is past its room, the app’s next connections only read - which also refuses deletes, so the app needs more room or its database switched off to recover.
- A draft’s copy holds tables with their indexes and constraints, rows, sequences, foreign keys and views - not functions, triggers or types an app made itself.
- Names fold to lower case, as PostgreSQL folds unquoted names.
- A download of an app carries no records;
pg_dump --schema=lambda_{id}takes them. - Apps need no change: their code names no database, and agents write migrations both accept. Code written for SQLite specifically -
SqliteConnection,UseSqlite- compiles only on SQLite. - Keeping it in shape is
VACUUM (ANALYZE)of every table, once a day in the quiet hours - the platform’s tables as its user, an app’s as its role, which owns them (see Keeping the databases in shape). It adds to autovacuum rather than replacing it; where your administrators run maintenance of their own, switch it off under Settings in the panel.
The panel’s Integrations section shows where the databases are kept - never the password.