FarWatch 1.3.1 is availableRead the upgrade notes

Starting on PostgreSQL

Start a new install on an existing PostgreSQL server, or move an existing install, with the requirements and the TLS rule.

Status

PostgreSQL support is a preview. SQLite stays the default and needs nothing extra. An upgrade never changes the engine of an existing install.

Choose PostgreSQL when your database team requires it as a standard, when the data file grows to several gigabytes and analytics pages slow down, or when you want a database that the database team backs up and patches. The tradeoff: every statement is a network round trip through the application's database bridge, so single-row writes are slower than on SQLite. Keep the server close to the FarWatch host. Running production on PostgreSQL has had less field use than SQLite.

Requirements

  • PostgreSQL 14 or later on a server that already exists. No installer installs PostgreSQL.
  • A login that can create a database and roles: a superuser, or a role with CREATEDB and CREATEROLE.
  • TLS. FarWatch refuses TLS set to disable for any server that is not the same machine (localhost, 127.0.0.0/8 or ::1). The default is verify-full, which checks the certificate and host name. The setting require encrypts the connection without checking who answers.
  • pg_hba.conf must accept a password login (scram-sha-256 or md5) from the FarWatch host for the application login.
  • A named at-rest confirmation. PostgreSQL does not encrypt data at rest by itself. FarWatch cannot see the server's disks, so Global Settings > Database asks for the administrator name or a ticket id before a migration or a switch. It is a record of who confirmed, not a control. See Backup and restore for recovery.

Who is responsible for what

With PostgreSQL, the database team owns backups of the server, patching, availability and encryption at rest. FarWatch still encrypts the integration credentials it stores, under the install key, before they are written to the database. The key stays on the FarWatch host.

With SQLite, the data lives in files on the FarWatch host. FarWatch does not encrypt those files. Disk encryption on the server is the at-rest control: BitLocker on Windows, LUKS or the storage layer on Linux, or the hypervisor's volume encryption.

Start a new install on PostgreSQL

Each installer calls one command and takes the connection details.

Windows setup program. The Database page, after the administrator password, offers SQLite (default) or PostgreSQL (preview). The fields are host, port (5432), database name (farwatch), user and password, plus a box ticked by default, "Create a separate farwatch login for the application". The installer tests the connection before it starts any service. Silent switches are /DATABASE=postgres, /PGHOST, /PGPORT, /PGDATABASE, /PGUSER, /PGPASSWORDFILE, /PGSSL (disable, require or verify-full), /PGSSLCAFILE and /PGNOAPPUSER=1.

Ubuntu install.sh. One question on a terminal, or these flags: --database-engine postgres, --pg-host, --pg-port, --pg-database, --pg-user, --pg-password-file, --pg-ssl, --pg-ssl-ca-file and --pg-no-app-user.

RPM. Put these in /etc/icc/install.env or the environment of the install:

ICC_DATABASE=postgres
ICC_PG_HOST=db.example.com
ICC_PG_USER=<a login that can create a database and roles>
ICC_PG_PASSWORD_FILE=/root/farwatch-pg.pw

Optional keys are ICC_PG_PORT (5432), ICC_PG_DATABASE (farwatch), ICC_PG_PASSWORD, ICC_PG_SSL, ICC_PG_SSL_CA_FILE and ICC_PG_NO_APP_USER=1. Remove the answers file and the password file when the install is done, because they hold a database password.

Container. Set ICC_DATABASE=postgres and the same ICC_PG_* variables in .env, with the password as ICC_PG_PASSWORD or ICC_PG_PASSWORD_FILE. The variables are read only on the first start of an empty data volume. See Install with containers.

By hand, on a machine where FarWatch is installed but has not started:

icc-cli engine use-postgres --user <name> [--host 127.0.0.1] [--port 5432] [--database farwatch] [--ssl disable|require|verify-full] [--ssl-ca-file <path>] [--schema-prefix fw_] [--app-user farwatch | --no-app-user] [--test-only]

The password of the login comes from the environment variable ICC_PG_PASSWORD, from the first line of the file named by --password-file, or from one line on stdin. It is never an argument. The ENCRYPTION_KEY of the install must already exist. Add --test-only to run the checks and change nothing.

Two account modes

  • Separate application login, the default. When the login you give is a superuser or can create roles, FarWatch creates a role named farwatch (or the name given by --app-user) with a generated password, makes it the owner of the database, and proves it by connecting as that role. The application runs as that role. The password of the login you typed is not stored. The generated password is stored encrypted in the engine settings file, and a database administrator can reset it with ALTER ROLE.
  • The login itself. With --no-app-user, or when the login cannot create roles, the application runs as the login you gave, and its password is stored encrypted.

If any step fails, the role and database that run created are dropped again and nothing is written. The usual cause of a failed proof login is pg_hba.conf: add a password rule for the new role from the FarWatch host, or rerun with --no-app-user.

The command refuses on an install that is not fresh. On success it writes an engine settings file, engine.json, beside the data files. Every process then starts on PostgreSQL and creates its tables. No SQLite file is created. FarWatch uses one schema per tenant plus a global schema, named with the prefix fw_ by default.

If the install fails, the installers stop before any service starts. The reason is in the message and in the install transcript.

Move an existing install from SQLite

This is done in the product, under Global Settings > Database, which only global administrators see. The procedure has three parts.

  1. PostgreSQL tab. Enter the connection, choose TLS, enter the at-rest confirmation, save, and press Test connection. If the database does not exist and the saved user may create one, the page offers Create database.
  2. Migrate tab. Run preflight, then Start migration. FarWatch takes a backup, copies every row in batches into schemas it creates, then verifies row counts and sampled rows. The SQLite files are never modified. Roll back drops the schemas the migration created.
  3. Switch tab. Turn on the switch from the Migrate tab, then run the preconditions and the switch. The restart is automatic and the install comes back on PostgreSQL.

A running poller writes data every few minutes, so for a real switch the order is: stop the poller service, run the migration again so the copy is fresh, run the switch from the Switch tab, then start the poller service. It starts on PostgreSQL.

The switch can go back to SQLite while the SQLite files are present. They are kept for a period after a successful switch, 7 days by default, and the page can then delete them. The backup the switch relied on is never deleted by that step.

The command line has the same operations: icc-cli migrate-to-postgres --preflight, --dry-run, --yes and --retry, and icc-cli engine status, icc-cli engine switch --to postgres --yes, and icc-cli engine retire-sqlite --yes.

Backups on PostgreSQL

The built-in backup works on PostgreSQL with no pg_dump binary on the host. It writes one CSV per table into the backup zip. See Backup and restore.

After a move

The first start after a move rebuilds some indexes once in the background and gathers table statistics. Both run while FarWatch is in use and are logged when they start and finish. Restart the web service once afterwards so open pages plan against the new indexes.