This is the multi-page printable view of this section. .
Auto-start on Boot
pgcli can automatically start PostgreSQL instances, backup containers, PgBouncer services, etcd members, the other supported addons, host commands registered with pg daemon, and pg http file servers after a host reboot. This feature uses system service managers:
- Linux: systemd user units
- macOS: launchd LaunchAgents
How It Works
When you enable auto-start, pgcli creates a system service that runs pg start --autostart at boot time (or user login). The --autostart flag starts only the instances and services marked with autostart: true in your configuration.
Auto-start is config-driven: if you run pg stop (or pg stop --all) on an instance, it will still be started automatically at the next boot. To prevent auto-start, use pg autostart disable.
Default behavior: The backup container has autostart: true by default in new configurations. Instances, PgBouncer, and etcd members default to autostart: false and must be explicitly enabled.
Enable Auto-start
For a Single Instance
Example:
This adds autostart: true to the instance configuration and creates/updates the boot service.
For the Backup Container
Enables auto-start for the shared pgBackRest backup container.
For PgBouncer
Enable auto-start for a PgBouncer associated with a specific instance:
Or for a remote PgBouncer:
For an etcd Member
Enable auto-start for an etcd member installed via pg addon install etcd:
The member name defaults to etcd when --name is omitted:
Repeat for each member of a cluster (m1, m2, m3, …) — autostart is
per-member. On a cross-host cluster, run the command on each host for that
host’s member(s).
Boot is start-only. At boot pgcli just brings the member’s existing
container up (podman start, recreating the container from config only if it
is missing or stuck in an improper state). It never re-registers membership —
a data-dir-initialized etcd member reloads its cluster from disk and rejoins
on a plain start, so it must have been installed while the cluster was
reachable first. Starting members before quorum forms briefly reports
etcdserver: no leader; that is normal and resolves once enough members are
up.
For a Kafka Node
Enable auto-start for a Kafka instance installed via pg addon install kafka:
The name defaults to kafka. At boot pgcli re-renders server.properties from
pg.yaml, starts the existing container and waits for the broker API to
answer. It never re-formats an already-formatted data dir — the cluster id and
node id are read from meta.properties, so the existing log is reused as-is.
For a SQLite Database
Enable auto-start for a managed SQLite database (Linux only):
--name is required — SQLite has no default database name. Replication must
already be enabled and its litestream.yml must exist:
At boot pgcli restarts the database’s litestream replicate process — there is
no container and the database file itself has nothing to start. The process
starts after the object-storage addons in the boot sequence, so a same-host
MinIO/silo/rustfs/garage/SeaweedFS backend is listening first. If the database
file is missing, that database’s autostart reports an error (and the rest of
the boot pass continues); restore the file or disable that target.
pg sqlite replication disable also clears the database’s autostart flag,
because Litestream cannot run without replication configured.
For a Daemon
Enable auto-start for a command registered with pg daemon add (Linux only):
--name is required — daemons have no default name. At boot,
pg start --autostart starts the command after all instances and addons, so
a webhook receiver or agent can dial its dependencies while they are already
running. The start is idempotent; a daemon that exits immediately is reported
with its log tail, and the rest of the boot pass continues.
Autostart starts the process once and does not supervise it: a crash after boot is not restarted. Run the command under its own supervisor if you need crash recovery.
For an HTTP Server
Enable auto-start for a pg http file server. Start the server once first —
pg autostart enable snapshots its launch settings (directory, listen address,
port, TLS material, the write-mode flags --allow-delete, --allow-upload and
--allow-dir, the upload size limit, the --admin-ip source restriction and
the Basic Auth users as bcrypt hashes) into the top-level http section of the
config:
--name is required — HTTP servers have no default name. At boot
pg start --autostart relaunches the server from the recorded settings; a
server that is already running is left alone. A later pg http start or
pg http restart with the same name refreshes the snapshot (for example after
pg http restart picked the next free port). If the recorded port is taken at
boot, the next free port is used, exactly like an interactive start.
The server’s state directory is derived from base_dir in the config (or the
platform default when it is unset), the same as the interactive command. A
generated TLS certificate is re-signed at boot when it is close to expiry or no
longer covers the listen address.
Disable Auto-start
Disabling a pg http server removes its http config entry; it does not stop a
currently running server (pg http stop does that).
When all auto-start targets are disabled, the boot service is automatically removed.
Check Status
Shows:
- Which instances and services have auto-start enabled
- The boot service unit name and state
- Linger status (Linux) — required for rootless podman to start services at boot time
Platform-Specific Behavior
Linux (systemd)
The boot service is created as a systemd user unit: pgcli-autostart-<hash>.service
Important: Rootless podman requires loginctl enable-linger to start containers at boot time (before the user logs in). pgcli attempts this automatically but will print a hint if it fails.
Without linger, the service starts at user login instead of at system boot.
Systemd Unit Configuration
The systemd unit generated by pgcli includes the following key settings:
- Delegate=yes - Delegates cgroup control to the service process, allowing rootless podman to properly manage container cgroup hierarchies
- RemainAfterExit=yes - Keeps the service in
activestate after execution completes, rather than immediately transitioning toinactive - Type=oneshot - Executes
pg start --autostartonce and exits
Cgroup Isolation and Automatic Fallback
Problem: When containers are started by a systemd user unit, accessing them from SSH sessions or other contexts may encounter cgroup permission errors:
Cause: Containers started by systemd user units reside in the user@1000.service/app.slice cgroup subtree, while SSH sessions are in session-N.scope - different cgroup scopes.
Solution: pgcli automatically detects cgroup permission errors and re-executes the command via systemd-run --user --scope. This creates a transient scope that can join the container’s cgroup subtree.
Affected commands (automatic fallback):
pg exec- Execute SQL or container commandspg psql- Interactive psql sessionspg status- Check container statuspg backup- Backup operationspg extension- Extension management- All other
podman execoperations
Unaffected commands:
pg start- Start containers (uses systemd-run itself)pg stop- Stop containerspg restart- Restart containers
Viewing Service Status
pg autostart status now displays detailed systemctl information:
Output includes:
- Enable status of all auto-start targets
- systemd unit name, load state, active state
- Service logs and recent execution records
- Linger status
Example output:
macOS (launchd)
The boot service is created as a LaunchAgent: com.pgcli.autostart-<hash>.plist
Note: macOS LaunchAgents run at user login, not at system boot. This is a macOS limitation — rootless podman cannot start services before the user logs in.
Configuration File
The autostart: true flag appears in your pgcli configuration file:
Boot Service Behavior
The boot service runs pg start --autostart, which:
- Starts all instances with
autostart: true - Starts the backup container if
backup.autostart: true - Starts PgBouncer services with
autostart: true - Starts etcd members with
autostart: true(start-only; see above) - Starts the other addons with
autostart: true; SQLite databases restart their Litestream replication after the object-storage addons - Relaunches
pg httpservers withautostart: truefrom their recorded settings - Starts daemons with
autostart: truelast, after every instance and addon
If no auto-start targets are configured, the service exits successfully (no error).
Each manager (PostgreSQL, backup, PgBouncer, etcd) self-heals stale rootless
podman state at startup — after a reboot the pause-process record is dead, so
the service transparently runs podman system migrate before touching
containers. This means boot works even when only addons (no PG instance) are
marked for auto-start.
Troubleshooting
Service Failed to Start
Check the boot service logs:
Linux (systemd):
macOS (launchd):
Linux: “XDG_RUNTIME_DIR is not set”
This error occurs when systemd user units are not available. Ensure you have a proper user session:
- SSH sessions should support systemd –user by default
- Terminal sessions in desktop environments support systemd –user
- Cron jobs and other non-interactive contexts do not support systemd –user
Linux: Auto-start Only Works After Login
Run loginctl enable-linger <your-username> to allow rootless podman to start services at boot time.
macOS: Auto-start Only Works After Login
This is expected behavior. macOS LaunchAgents cannot run before user login due to rootless podman constraints.
Examples
Enable auto-start for a complete production setup:
After the next reboot, all these services will start automatically.