fsm_core
fsm_core : Finite state machine toolkit for PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2690 | fsm_core | fsm_core | 1.1.0 |
FEAT | Apache-2.0 | 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_jsonschema |
| See Also | pgmq ulak pgmb pg_durable redis pg_task pg_background pgq redis_fdw tcn |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.0 |
18 17 16 15 14 | fsm_core |
ltree, pgmq, pg_jsonschema |
| RPM | PIGSTY | 1.1.0 |
18 17 16 15 14 | fsm_core_$v |
pgmq_$v |
| DEB | PIGSTY | 1.1.0 |
18 17 16 15 14 | postgresql-$v-fsm-core |
postgresql-$v-pgmq, postgresql-$v-pg-jsonschema |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| el8.aarch64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| el9.x86_64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| el9.aarch64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| el10.x86_64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| el10.aarch64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| d12.x86_64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| d12.aarch64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| d13.x86_64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| d13.aarch64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| u22.x86_64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| u22.aarch64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| u24.x86_64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| u24.aarch64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| u26.x86_64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
| u26.aarch64 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | PIGSTY 1.1.0 | N/A |
Source
github.com/pgfsm/fsm/tree/main/packages/database-src-extension/fsm_core
fsm_core-1.1.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
fsm_core is a finite-state-machine toolkit that stores FSM definitions, instances, transitions, and event logs inside PostgreSQL. A machine definition is loaded from JSON, instances are created by name and version, and events are sent through SQL functions with optional pgmq queues.
This document describes the PGXN 1.1.0 distribution, which requires PostgreSQL 15 or later, ltree 1.2 or later and pgmq 1.4.4 or later. The fixed schema is fsm_core; installation requires a superuser. No preload or restart is required by this SQL extension. Current repository migrations are a separate source and may expose a different API.
Core Tables and Types
fsm_core creates an enum fsm_state_type with atomic, compound, parallel, final, and history, plus tables including:
fsm_core.fsm_jsonfor loaded FSM definitions.fsm_core.fsm_statesfor expanded state nodes and ltree paths.fsm_core.fsm_transitionsfor transition rules.fsm_core.fsm_instancefor running instances.fsm_core.fsm_instance_lockfor advisory/concurrency state.fsm_core.fsm_instance_queue_event_logsandfsm_core.fsm_promise_queue_event_logsfor queued event history.
Load a Machine Definition
load_fsm_from_json_v2() checks JSON against fsm_core.fsm_json_schema(), expands states and transitions, then caches the raw definition in fsm_json. In 1.1.0, JSON-schema violations produce a NOTICE and loading continues; the schema-validation exception is commented out. Validate definitions before loading rather than relying on this check to reject every invalid definition. Keep deployed definitions and version identifiers stable so existing instances continue against their original definition. Set the psql variable fsm_json to your validated machine JSON before running the example.
Create an Instance
The PGXN 1.1.0 function checks that the named FSM exists, inserts an fsm_instance, and copies transition authorization rows. When create_pgmq_queue is true, it attempts to create a pgmq queue named by the instance UUID and send initialTransition_event. Queue creation and initial-event failures are caught and reported in the returned JSON. Before sending further events, require queue_created to be true and inspect send_event_result, message and extra_message to confirm the initial event succeeded. The psql example retains the returned fsm_instance_id for the next call.
Send Events
This helper writes to the instance queue with pgmq.send() and records the event in fsm_instance_queue_event_logs. For nested FSM and promise flows, send_event_to_queue_from_fsm_instance_id_v2() dispatches to the child-FSM or promise queue helper based on fsmtype.
Resolve and Step State
The SQL surface also includes lower-level microstep_v2(), fsm_worker_v2(), lock helpers, archive helpers, and v1 compatibility functions. Prefer v2 entry points for new usage when both versions are present.
Dependencies and Operation
Enable ltree and pgmq before installing fsm_core. The release README also requires pg_jsonschema 0.3.3 or later, although the control and META dependency lists omit it. The JSON loader calls fsm_core.jsonschema_validation_errors, which is not defined by the distribution’s SQL script; verify that the documented JSON-schema helper is available in that schema before loading definitions. Installing a dependency into a different schema alone does not provide that qualified function.
Queued events persist as application data. Supplying create_pgmq_queue => true requests the per-instance queue and its initial event; check the returned status before proceeding. A consumer still needs to process queued work. Sending an event does not by itself guarantee that an asynchronous worker has executed the transition. Review queue retention, consumers and permissions together.
Inspect function and table grants before exposing machine creation or arbitrary event submission to application roles. The SQL surface also contains legacy v1 and lower-level helpers; use the verified v2 entry points for this release.