fsm_core
fsm_core · Finite state machine toolkit for PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2690 | fsm_core | fsm_core | 1.4.0 | FEAT | AGPL-3.0-only | SQL |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| ----d-- | No | No | No | Yes | no | no |
| Relationships | |
|---|---|
| Schemas | fsm_core |
| Requires | ltree pgmq pg_cron |
| See Also | pgmq ulak pgmb pg_durable redis pg_task pg_background pgq redis_fdw tcn |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| el8.aarch64 | N/A | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| el9.x86_64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| el9.aarch64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| el10.x86_64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| el10.aarch64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| d12.x86_64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| d12.aarch64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| d13.x86_64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| d13.aarch64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| u22.x86_64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| u22.aarch64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| u24.x86_64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| u24.aarch64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| u26.x86_64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
| u26.aarch64 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 | PIGSTY 1.4.0 |
Source
github.com/pgfsm/fsm/tree/fsm_core-v1.4.0/packages/database-src
fsm_core-1.4.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
fsm_core 1.4.0 stores finite-state-machine definitions, instances, transitions and event history in PostgreSQL. Its SQL interface loads validated JSON, creates instances by name and version, and submits events through pgmq queues.
Install and Configure
The release requires PostgreSQL 15 or later and was tested on 15–18. Required extensions are ltree 1.2+, pgmq 1.4.4+ and pg_cron 1.5+. Add pg_cron to the existing shared_preload_libraries, restart PostgreSQL if that setting changes, and install into the database selected by cron.database_name.
After installing the matching extension files, a superuser can enable the fixed, nonrelocatable fsm_core schema:
Installation creates fsm_* roles and the fsm_schedule_all_pending scheduler job, which runs every five seconds. Inspect role memberships, queue permissions and the scheduler before granting application access. pg_jsonschema is optional: if its validation helper exists in fsm_core, the loader reports schema problems but does not reject a definition on that check alone.
Load a Definition
Validate the machine with the upstream compiler and set the psql variable fsm_json to that JSON before this call. This call loads the definition by name and version.
Concurrent loads of the same name and version are serialized by an advisory transaction lock. Identical JSON returns the cached definition; different JSON under an existing name and version raises an error. Use a new version for a changed machine. The optional input_dependent_children argument records child-machine dependencies.
Create an Instance and Send Events
The returned JSON includes fsm_instance_id, queue_created, send_event_result, message and extra_message. Check these before submitting work: queue creation and initial-event failures can be reported in the result. Initial context is shallow-merged with the definition’s static context, with supplied object keys taking precedence.
For this top-level machine, submit an event declared by its definition:
The helper queues the event and writes event history. The old parent-queue parameters are absent from this release’s signature. Queuing an event is not proof that a worker has processed it; monitor scheduler activity, queue backlog and instance state.
Objects and Upgrade Boundaries
fsm_json, fsm_states and fsm_transitions hold definitions; fsm_instance holds instances; fsm_instance_queue_event_logs records queue events. resolve_state_value_v2 and macrostep_v2 expose lower-level state resolution and transition logic. Prefer the verified v2 entry points and restrict access to security-definer functions and underlying tables.
Version 1.3.1 Upgrade
The 1.3.1 release archive contains the full installation and sequential 1.2.0 → 1.3.0 → 1.3.1 upgrade scripts. Back up populated databases, inspect fsm_core.version() and follow that sequence using the installation method already in use. For extension-managed installations, install the matching upgrade files before ALTER EXTENSION; standalone SQL installations follow the guarded scripts in order.
The 1.3.1 patch revises guard evaluation, transition selection and macrostep/worker behavior. Recheck representative machine definitions and queued work after upgrading.
Version 1.4.0
Version 1.4.0 adds final-state output and output names to machine definitions and propagates completion output through macrosteps and worker persistence. fsm_core.macrostep_v2 includes an output value; applications handling completion should check the new result and verify parent/child completion flows. The migration extends the worker archive function signature and restores its restricted worker grant; do not substitute an old worker function definition or grant execution to PUBLIC.
Back up the database, check fsm_core.version(), and apply the guarded 1.3.1-to-1.4.0 step after all earlier sequential upgrades. The release ZIP contains installation and upgrade SQL plus the actual PGXN control and metadata. Preserve the existing extension-managed or standalone SQL installation method.