Running the server
This page covers starting the server for the first time, keeping it running as a service, stopping it cleanly, and reading its logs. It assumes the server is installed (Install); every flag mentioned is in Configuration.
First start
The server needs a data directory and a password for its first role. Pass the password through the environment rather than on the command line, where any user on the machine can read it in ps:
mkdir -p /var/lib/rasterizeddb
export RASTERIZEDDB_PG_PASSWORD='choose-a-strong-password'
rasterizeddb --location /var/lib/rasterizeddb --protocol bothOn Windows, in PowerShell:
New-Item -ItemType Directory -Force C:\rasterizeddb\data | Out-Null
$env:RASTERIZEDDB_PG_PASSWORD = "choose-a-strong-password"
C:\rasterizeddb\rasterizeddb.exe --location C:\rasterizeddb\data --protocol both--protocol both serves the PostgreSQL protocol on 127.0.0.1:5432 and the native protocol on 127.0.0.1:61170. Without it the server serves only the native protocol, which psql and PostgreSQL drivers cannot use. The server prints two lines when it starts:
SIMD: avx2 on ... [...]; scan prefilter on
descriptors: soft limit 1048576; partition open budget 4096 of max_open 4096Connect from another terminal:
psql "host=127.0.0.1 port=5432 user=rasterized dbname=postgres sslmode=require"The PostgreSQL listener requires TLS by default and makes itself a self-signed certificate at every start, so sslmode=require works with no preparation. See Connecting for every protocol, driver and TLS option.
To listen on the network rather than localhost only, add --pg-addr 0.0.0.0 --rdb-addr 0.0.0.0.
The first role
When a database has no roles yet, the server creates one superuser role in it:
| Protocol setting | Role name | Password from |
|---|---|---|
--protocol pgwire or both | --pg-user (default rasterized) | --pg-password, else RASTERIZEDDB_PG_PASSWORD |
--protocol rastcp (the default) | --rdb-user (default rasterized) | --rdb-password, else RASTERIZEDDB_PASSWORD |
Under --protocol both one role is created, from the PostgreSQL side's settings, and it logs in over both protocols.
This happens once. After the database has roles, the flags and variables are ignored: a restart never resets a password or brings back a deleted role. Change passwords and add users with SQL; see Security.
Start with a password. Without one:
- the PostgreSQL protocol creates the role with no password, which nobody can log in as except under
--pg-auth trust; - the native protocol accepts any caller on a loopback address, and refuses to start on any other address.
What is in the data directory
The --location directory is the default database (postgres, set by --pg-default-db). Each database made with CREATE DATABASE is a subdirectory of it. The server also keeps these files at the top level:
| File | What it is |
|---|---|
rasterizeddb.lock | The lock that keeps a second server off this directory. |
rasterizeddb.conf | Settings saved by SET CONFIG; see Configuration. |
Do not edit or remove the other files by hand. To copy a database, use a backup or a branch, not a file copy of a running server.
The data-directory lock
Only one server may open a data directory at a time. Two engines on one directory would replay and truncate each other's write-ahead log, so the second is refused before it reads anything:
could not open the database catalogue: /var/lib/rasterizeddb is already open in another RasterizedDB (process 4182, or an earlier engine in that process): two engines on one data directory would corrupt it, so this one does not open it. Stop the other, or use another directoryThe lock is the operating system's own (flock on Linux, LockFileEx on Windows). It ends with the process however the process ends, so a crash or kill -9 never leaves a stale lock behind, and rasterizeddb.lock does not need to be deleted after one. The file holds the process id of the server that has the directory.
Running as a systemd service
The Arch Linux package installs this unit. Use it as is on any systemd distribution, with ExecStart pointing at where you installed the binary:
[Unit]
Description=RasterizedDB server
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=rasterizeddb
Group=rasterizeddb
EnvironmentFile=/etc/rasterizeddb/rasterizeddb.env
ExecStartPre=/bin/sh -c 'test -n "$$RASTERIZEDDB_PG_PASSWORD" || { echo "set RASTERIZEDDB_PG_PASSWORD in /etc/rasterizeddb/rasterizeddb.env" >&2; exit 1; }'
ExecStart=/usr/bin/rasterizeddb --location /var/lib/rasterizeddb --protocol both $RASTERIZEDDB_ARGS
StateDirectory=rasterizeddb
StateDirectoryMode=0700
KillSignal=SIGTERM
TimeoutStopSec=120
Restart=on-failure
RestartSec=5
LimitNOFILE=1048576
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
RestrictSUIDSGID=yes
LockPersonality=yes
[Install]
WantedBy=multi-user.targetand this environment file, /etc/rasterizeddb/rasterizeddb.env, readable by root only (mode 600):
# Password of the role `rasterized`, for both protocols.
RASTERIZEDDB_PG_PASSWORD=choose-a-strong-password
# Further server flags. By default both protocols listen on localhost only.
RASTERIZEDDB_ARGS=--pg-addr 0.0.0.0 --rdb-addr 0.0.0.0On a distribution without the package, create the user and directory first:
sudo useradd --system --home-dir /var/lib/rasterizeddb --shell /usr/sbin/nologin rasterizeddb
sudo install -d -m 700 /etc/rasterizeddb
sudo install -m 600 /dev/null /etc/rasterizeddb/rasterizeddb.env
sudoedit /etc/rasterizeddb/rasterizeddb.env
sudo systemctl daemon-reload
sudo systemctl enable --now rasterizeddb
journalctl -u rasterizeddb -fNotes on the unit:
LimitNOFILEmatters. The server raises its soft open-file limit at start, but only up to the hard limit, and a stock unit's limit is small. With a low limit it keeps fewer partitions open and accepts fewer PostgreSQL connections, and thedescriptors:line at start-up says so.ProtectSystem=strictmakes everything outsideStateDirectoryread-only. Extra storage directories (--storage-location) need a drop-in withReadWritePaths=<dir>.TimeoutStopSecis how long a clean stop may take before systemd kills the process. See Stopping the server.
Running on Windows
The server is a console program and does not install itself as a Windows service. Run it from a terminal, or under a service wrapper or scheduled task of your choice. Whatever runs it must stop it with Ctrl+C or Ctrl+Break, which are the signals it shuts down cleanly on: Ctrl+Break can be sent to one process group, so a supervisor that starts the server in its own group can stop only the server. Ending the process outright is the same as a crash (safe, but the next start replays the log).
Unix sockets and peer authentication are not available on Windows; use TCP.
Stopping the server
Send SIGTERM (systemctl stop, docker stop, kill <pid>) or press Ctrl+C. The server then:
- stops accepting connections on every listener;
- lets statements in flight finish, ending idle sessions at once; PostgreSQL sessions get up to 10 seconds, and so do MySQL and SQL Server sessions;
- writes index snapshots for every database, within
index_snapshot.shutdown_deadline_secs(120 seconds by default); - saves the key/value cache if
--kv-persistis on, uploads staged backup log if S3 backup is on, and checkpoints the write-ahead log so the next start has nothing to replay.
A second SIGTERM or Ctrl+C during this exits at once with status 130.
Stopping is never needed for safety. A crash, kill -9 or power loss loses no committed transaction (under --synchronous-commit on): the next start replays the write-ahead log, which only makes that start slower. Indexes whose snapshot was not written are rebuilt from the rows.
Give a service manager enough stop time for steps 2 and 3. If you lower its timeout, lower index_snapshot.shutdown_deadline_secs below it:
SET CONFIG index_snapshot.shutdown_deadline_secs = 60;Exit status
| Status | Meaning |
|---|---|
0 | Clean stop. |
2 | The server refused to start: a bad flag, a port it could not bind, a locked data directory, a backup bucket it could not reach. The reason is printed to standard error. |
130 | A second termination signal cut a clean stop short. |
When one listener cannot start (its port taken, its certificate unreadable), the whole process ends with status 2, even if another listener is already serving, so a supervisor sees the failure instead of a server that answers on only some of its ports.
Logging
The server logs to standard error. --log-level sets how much:
| Level | What you get |
|---|---|
off | Nothing. |
error (default) | Failures only. |
warn | Also conditions worth acting on, such as a listener accepting callers without a password, or the PostgreSQL listener on a network address without required TLS. |
info | Also start-up and shutdown steps: listeners and their addresses, the bootstrap role being created, backup targets, drain progress. |
debug, trace | Detail for diagnosing a problem. Verbose. |
rasterizeddb --location /var/lib/rasterizeddb --protocol both --log-level infoThe level is set by the flag only: the RUST_LOG environment variable is not read. Under systemd the log goes to the journal (journalctl -u rasterizeddb); in Docker, to docker logs.
Run with at least warn in production. At the default error level, start-up warnings such as "No password is configured and no role has one" are not printed.
Two lines are always printed to standard output at start, whatever the level: the instruction set the scan kernels use, and the open-file limit with the partition budget it allows. When the hard open-file limit is what holds the budget back, a third line says how far to raise it.
What statements ran and what they cost is not in the log; see Monitoring.
Limits
- One server per data directory.
- There is no built-in Windows service.
RUST_LOGhas no effect; use--log-level.- Log output is plain text lines; there is no structured (JSON) log format.