Server owners
Install and operate the main database
SQLite is the default. BlokeBot supports the current PostgreSQL 18 minor release for one active instance per main database.
Provider configuration
- Do not put the PostgreSQL connection string in an environment value.
- Do not put the PostgreSQL connection string in an image.
- Use Sqlite for the default local database file.
- Use PostgreSql with BlokeBot__PostgreSqlConnectionStringFile for PostgreSQL 18.x.
- Install the current PostgreSQL 18 minor release.
- Keep BlokeBot__StateDirectory on persistent storage for both providers.
- Configure one active BlokeBot instance for each main database.
Docker Compose secrets
The Compose file uses postgres:18-alpine and starts BlokeBot. It stores each service state in a named volume.
- Open the BlokeBot repository root.
- Create the protected secret directory and files with the commands below.
- Write only the database password to postgresql.password.
- Write the complete BlokeBot connection string to postgresql.connection.
- Use Host=postgres;Port=5432;Database=blokebot;Username=blokebot;Password=<same-password>;SSL Mode=Disable.
umask 077
mkdir -p packaging/docker/secrets
${EDITOR:-vi} packaging/docker/secrets/postgresql.password
${EDITOR:-vi} packaging/docker/secrets/postgresql.connection
chmod 0600 packaging/docker/secrets/postgresql.password
sudo chown 1654:1654 packaging/docker/secrets/postgresql.connection
sudo chmod 0400 packaging/docker/secrets/postgresql.connectionDocker Compose startup
- Use a new PostgreSQL 18 volume.
- Start both services with the Compose file.
- Wait for the readiness request to succeed.
docker compose -f packaging/docker/compose.postgresql.yml up --build --detach
curl --fail --retry 30 --retry-all-errors --retry-delay 1 http://127.0.0.1:8080/health/readyNixOS protected credential
- Create /etc/blokebot with mode 0700.
- Create /etc/blokebot/postgresql.connection with owner root and mode 0400.
- Write the local socket connection string below to the file.
- Keep the source file outside the Nix store.
Host=/run/postgresql;Database=blokebot;Username=blokebotNixOS PostgreSQL configuration
- Update the NixOS package input to the current PostgreSQL 18 minor release.
- Add the PostgreSQL 18 service and BlokeBot settings.
- Make the local BlokeBot service depend on PostgreSQL.
- Apply the NixOS configuration.
services.postgresql = {
enable = true;
package = pkgs.postgresql_18;
ensureDatabases = [ "blokebot" ];
ensureUsers = [
{
name = "blokebot";
ensureDBOwnership = true;
}
];
};
services.blokebot = {
enable = true;
databaseProvider = "PostgreSql";
postgresqlConnectionStringFile = "/etc/blokebot/postgresql.connection";
};
systemd.services.blokebot = {
after = [ "postgresql.target" ];
requires = [ "postgresql.target" ];
};NixOS startup and health
- Apply the new system configuration.
- Check that the BlokeBot service stays active.
- Check the database readiness endpoint.
sudo nixos-rebuild switch
systemctl status blokebot
curl --fail http://127.0.0.1:8080/health/readyNative PostgreSQL installation
- Install the current PostgreSQL 18 minor release from the operating-system package source.
- Start the PostgreSQL service.
- Create the BlokeBot login role with a password prompt.
- Create the BlokeBot database with that role as owner.
- Do not give the role superuser privileges.
- Do not give the role replication privileges.
- Do not give the role role-management privileges.
- Do not give the role database-creation privileges.
sudo -u postgres createuser --login --pwprompt blokebot
sudo -u postgres createdb --owner=blokebot blokebotNative BlokeBot configuration
- Create /etc/blokebot/postgresql.connection for the BlokeBot service account.
- Set the connection-file mode to 0400.
- Add the database host.
- Add the database and user name.
- Add the password.
- Add the TLS settings.
- Set the non-secret values below in the service manager.
- Start one BlokeBot process with the command below.
export BlokeBot__DatabaseProvider=PostgreSql
export BlokeBot__StateDirectory=/var/lib/blokebot
export BlokeBot__PostgreSqlConnectionStringFile=/etc/blokebot/postgresql.connection
blokebot serve --host 127.0.0.1 --port 8080 --data-dir /var/lib/blokebotNative startup health
- After BlokeBot starts, open another terminal.
- Before public traffic starts, check both health endpoints.
curl --fail http://127.0.0.1:8080/health/live
curl --fail http://127.0.0.1:8080/health/readyStartup and health behavior
BlokeBot checks the database and applies migrations before it starts the HTTP listener. A connection refusal means that BlokeBot is not ready.
- BlokeBot retries provider unavailability five times. Each retry waits three seconds.
- /health/live confirms that the process listens. It does not access the database.
- /health/ready checks database access and the migration history within two seconds.
- A terminal startup failure stops BlokeBot with a redacted category and a nonzero exit status.
SQLite cutover preconditions
- Stop the SQLite BlokeBot instance.
- Back up the SQLite file and the matching state directory.
- Keep the active provider configuration on Sqlite.
- Start PostgreSQL 18.
- Create the application login.
- Do not create the application database.
- Create a protected administrator connection file for an existing maintenance database.
- Create a protected application connection file for the new database and the application login.
- For a non-superuser administrator login, CREATEDB is required.
- For that non-superuser login, EXECUTE on pg_control_system() is required.
- For that non-superuser login, membership of the application login is required.
SQLite cutover command
- Run the offline transfer with both protected connection files.
- Rerun the same command to resume an interrupted transfer.
- Reuse the operation ID if you set --operation-id.
- Change the provider to PostgreSql only after successful verification.
- Start one BlokeBot instance.
- Check /health/ready.
- The cutover command migrates SQLite first.
- The command then creates the database.
- The command applies the PostgreSQL schema.
- The command copies the data.
- The command checks the row count of each domain table.
- The command rejects a database that exists without a matching receipt.
- The command does not drop a database or change the active provider configuration.
blokebot database cutover-postgresql \
--postgresql-administrator-connection-string-file /etc/blokebot/postgresql-admin.connection \
--postgresql-application-connection-string-file /etc/blokebot/postgresql.connection \
--data-dir /var/lib/blokebotCutover recovery boundary
- Before the first PostgreSQL application write, retry the cutover or continue with untouched SQLite.
- After the first PostgreSQL application write, repair or restore PostgreSQL.
- Do not return to SQLite after the first PostgreSQL application write.
- BlokeBot does not provide a reverse transfer or database downgrade.
PostgreSQL responsibilities
- BlokeBot does not provide high availability.
- BlokeBot does not provide scale-out.
- BlokeBot does not provide multi-tenancy.
- Configure certificate-verified TLS.
- Restrict network access.
- Back up PostgreSQL and the matching BlokeBot state directory.
- Test a restore before a cutover or PostgreSQL upgrade.
- Keep one active BlokeBot instance during migrations and normal operation.