pg_swarm
pg_extensions · Background-worker task scheduling with SQL executors.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102100 | pg_swarm | pg_extensions | 0.3.3 | FEAT | Matroid-SAL-1.0 | Rust |
PostgreSQL · 14, 15, 16, 17
Usage
Sources:
- extensions/pg_swarm/Cargo.toml
- extensions/pg_swarm/src/lib.rs
- crates/pg_bgworker/src/supervision.rs
- CHANGELOG.md
- extensions/pg_swarm/pgbrew.toml
- extensions/pg_swarm/pg_swarm.control
- README.md
- extensions/pg_swarm/Cargo.toml
- extensions/pg_swarm/src/lib.rs
- CHANGELOG.md
- LICENSE
- extensions/pg_swarm/pgbrew.toml
- extensions/pg_swarm/src/node.rs
- extensions/pg_swarm/src/scheduler.rs
pg_swarm 0.3.3 registers SQL executors and splits jobs into tasks managed by background workers in pgswarm, with status, retries and optional result tables.
Core Workflow
Operational Boundaries
The control requires superuser installation. Preload and restart; the node and scheduler use pg_swarm.database (default postgres). Create the extension and executor objects in that database. register_executor records a function receiving task ID, JSONB payload, chunk index and chunk count; submit_job queues work. Executors run inside a privileged service, so restrict registration and submission. pg_swarm.workers, timeout and retry settings control scheduling. Retried tasks require idempotent handling of external side effects; no cross-node exactly-once guarantee is implied. This is an unsupported proof of concept under Matroid Source Available License 1.0. APIs may change. Version 0.3.0 is the new upgrade baseline: earlier 0.2.0 installations require a rehearsed data migration/recreation, not ordinary ALTER EXTENSION UPDATE. Back up data and dependencies before following that destructive upstream path.
Current Release and Upgrade
Extension version 0.3.2 uses pg_swarm.database for background workers. Create the extension in that database; a worker now waits instead of repeatedly exiting when it is absent. Changing restart-sensitive worker configuration requires a restart. From extension 0.3.0 onward, install matching files and use ALTER EXTENSION UPDATE. Earlier versions still require the migration described above. Withdrawn repository 0.4.0 bottles must be replaced by 0.5.0; upstream bottles do not imply Pigsty package availability.
Worker Supervision
Version 0.3.2 adds pgswarm.worker_status() and the superuser-only pgswarm.reset_workers(). Status reports worker name, state, failures, restarts, PID, time of entry into the current state and last failure. pg_swarm.max_worker_failures defaults to 10 consecutive failures; 0 retries indefinitely. Restart delays back off from 5 to 60 seconds, and reaching the limit leaves a failed worker idle until reset.
Install matching libraries, restart PostgreSQL to initialize the new shared memory, and update the extension SQL in the configured worker database. Inspect the failure before resetting; a reset does not repair its cause.
Idle Workers in 0.3.3
Repository release 0.7.2 contains extension 0.3.3. Read-only or empty-claim polls no longer allocate a transaction ID merely because they use the SPI bridge; an actual row write still does. This removes empty commit WAL from idle polling. Install matching libraries, restart the preloaded workers, and update the SQL extension. The existing privilege, external-service and pre-0.3.0 migration boundaries remain.