Database Interface
Fractal Server only allows PostgreSQL to be used as database; the database-related configuration variables are described below (and in the configuration page).
To use PostgreSQL as a database, fractal-server depends on sqlalchemy and psycopg[binary].
As of fractal-server 2.20.5, versions 10 and 18 of PostgreSQL have been tested successfully.
Setup
We assume that a PostgreSQL service is active, with some host (this can be e.g. localhost or a UNIX socket like /var/run/postgresql/), a port (we use the default 5432 in the examples below) and a user (e.g. postgres or fractal).
⚠️ Notes:
- The postgres user must be created from outside
fractal-server.- A given machine user may or may not require a password (e.g. depending on whether the machine username matches with the PostgreSQL username, and on whether connection happens via a UNIX socket). See documentation here: https://www.postgresql.org/docs/current/auth-pg-hba-conf.html.
Here we create a database called fractal_db, through the createdb command:
All options of this command (and of the ones below) should be aligned with the
configuration of a specific PostgreSQL instance. Within fractal-server, this
is done by setting the following configuration variables (before running
fractalctl commands):
-
Required:
-
Optional:
Note that POSTGRES_HOST can be either a URL or the path to a UNIX domain
socket (e.g. /var/run/postgresql).
Backup and restore
To backup and restore data, one can use the utilities pg_dump and psql.
It is possible to dump/restore data in various formats (see documentation of
pg_dump), but in
this example we stick with the default plain-text format.
In order to restore a database from a dump, we first create a new empty one
(new_fractal_db):
One of the multiple ways to compress data is to use
gzip, by adapting the commands above as in: