Skip to content

fsm_core

Finite state machine toolkit for PostgreSQL

fsm_core : Finite state machine toolkit for PostgreSQL

Overview

ID Extension Package Version Category License Language
2690 fsm_core fsm_core 1.2.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
See Also pgmq ulak pgmb pg_durable redis pg_task pg_background pgq redis_fdw tcn
PG15+; requires ltree, pgmq, and pg_jsonschema

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 1.2.0 19 18 17 16 15 fsm_core ltree, pgmq
RPM PIGSTY 1.2.0 19 18 17 16 15 fsm_core_$v pgmq_$v
DEB PIGSTY 1.2.0 19 18 17 16 15 postgresql-$v-fsm-core postgresql-$v-pgmq, postgresql-$v-pg-jsonschema
Linux / PG PG19 PG18 PG17 PG16 PG15
el8.x86_64 N/A PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
el8.aarch64 N/A PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
el9.x86_64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
el9.aarch64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
el10.x86_64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
el10.aarch64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
d12.x86_64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
d12.aarch64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
d13.x86_64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
d13.aarch64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
u22.x86_64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
u22.aarch64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
u24.x86_64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
u24.aarch64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
u26.x86_64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
u26.aarch64 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0 PIGSTY 1.2.0
Package Version OS ORG SIZE File URL
fsm_core_19 1.2.0 el9.x86_64 pigsty 58.5 KiB fsm_core_19-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_19 1.2.0 el9.aarch64 pigsty 58.5 KiB fsm_core_19-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_19 1.2.0 el10.x86_64 pigsty 58.7 KiB fsm_core_19-1.2.0-1PGSTY.el10.noarch.rpm
fsm_core_19 1.2.0 el10.aarch64 pigsty 58.7 KiB fsm_core_19-1.2.0-1PGSTY.el10.noarch.rpm
postgresql-19-fsm-core 1.2.0 d12.x86_64 pigsty 52.5 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-19-fsm-core 1.2.0 d12.aarch64 pigsty 52.5 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-19-fsm-core 1.2.0 d13.x86_64 pigsty 52.6 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-19-fsm-core 1.2.0 d13.aarch64 pigsty 52.6 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-19-fsm-core 1.2.0 u22.x86_64 pigsty 53.6 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-19-fsm-core 1.2.0 u22.aarch64 pigsty 53.6 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-19-fsm-core 1.2.0 u24.x86_64 pigsty 53.4 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-19-fsm-core 1.2.0 u24.aarch64 pigsty 53.4 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-19-fsm-core 1.2.0 u26.x86_64 pigsty 53.5 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~resolute_all.deb
postgresql-19-fsm-core 1.2.0 u26.aarch64 pigsty 53.5 KiB postgresql-19-fsm-core_1.2.0-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
fsm_core_18 1.2.0 el8.x86_64 pigsty 63.4 KiB fsm_core_18-1.2.0-1PGSTY.el8.noarch.rpm
fsm_core_18 1.2.0 el8.aarch64 pigsty 63.4 KiB fsm_core_18-1.2.0-1PGSTY.el8.noarch.rpm
fsm_core_18 1.2.0 el9.x86_64 pigsty 58.5 KiB fsm_core_18-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_18 1.2.0 el9.aarch64 pigsty 58.5 KiB fsm_core_18-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_18 1.2.0 el10.x86_64 pigsty 58.7 KiB fsm_core_18-1.2.0-1PGSTY.el10.noarch.rpm
fsm_core_18 1.2.0 el10.aarch64 pigsty 58.7 KiB fsm_core_18-1.2.0-1PGSTY.el10.noarch.rpm
postgresql-18-fsm-core 1.2.0 d12.x86_64 pigsty 52.5 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-18-fsm-core 1.2.0 d12.aarch64 pigsty 52.5 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-18-fsm-core 1.2.0 d13.x86_64 pigsty 52.5 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-18-fsm-core 1.2.0 d13.aarch64 pigsty 52.5 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-18-fsm-core 1.2.0 u22.x86_64 pigsty 53.6 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-18-fsm-core 1.2.0 u22.aarch64 pigsty 53.6 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-18-fsm-core 1.2.0 u24.x86_64 pigsty 53.5 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-18-fsm-core 1.2.0 u24.aarch64 pigsty 53.5 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-18-fsm-core 1.2.0 u26.x86_64 pigsty 53.5 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~resolute_all.deb
postgresql-18-fsm-core 1.2.0 u26.aarch64 pigsty 53.5 KiB postgresql-18-fsm-core_1.2.0-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
fsm_core_17 1.2.0 el8.x86_64 pigsty 63.4 KiB fsm_core_17-1.2.0-1PGSTY.el8.noarch.rpm
fsm_core_17 1.2.0 el8.aarch64 pigsty 63.4 KiB fsm_core_17-1.2.0-1PGSTY.el8.noarch.rpm
fsm_core_17 1.2.0 el9.x86_64 pigsty 58.5 KiB fsm_core_17-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_17 1.2.0 el9.aarch64 pigsty 58.5 KiB fsm_core_17-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_17 1.2.0 el10.x86_64 pigsty 58.7 KiB fsm_core_17-1.2.0-1PGSTY.el10.noarch.rpm
fsm_core_17 1.2.0 el10.aarch64 pigsty 58.7 KiB fsm_core_17-1.2.0-1PGSTY.el10.noarch.rpm
postgresql-17-fsm-core 1.2.0 d12.x86_64 pigsty 52.5 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-17-fsm-core 1.2.0 d12.aarch64 pigsty 52.5 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-17-fsm-core 1.2.0 d13.x86_64 pigsty 52.5 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-17-fsm-core 1.2.0 d13.aarch64 pigsty 52.5 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-17-fsm-core 1.2.0 u22.x86_64 pigsty 53.6 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-17-fsm-core 1.2.0 u22.aarch64 pigsty 53.6 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-17-fsm-core 1.2.0 u24.x86_64 pigsty 53.4 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-17-fsm-core 1.2.0 u24.aarch64 pigsty 53.4 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-17-fsm-core 1.2.0 u26.x86_64 pigsty 53.5 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~resolute_all.deb
postgresql-17-fsm-core 1.2.0 u26.aarch64 pigsty 53.5 KiB postgresql-17-fsm-core_1.2.0-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
fsm_core_16 1.2.0 el8.x86_64 pigsty 63.4 KiB fsm_core_16-1.2.0-1PGSTY.el8.noarch.rpm
fsm_core_16 1.2.0 el8.aarch64 pigsty 63.4 KiB fsm_core_16-1.2.0-1PGSTY.el8.noarch.rpm
fsm_core_16 1.2.0 el9.x86_64 pigsty 58.5 KiB fsm_core_16-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_16 1.2.0 el9.aarch64 pigsty 58.5 KiB fsm_core_16-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_16 1.2.0 el10.x86_64 pigsty 58.7 KiB fsm_core_16-1.2.0-1PGSTY.el10.noarch.rpm
fsm_core_16 1.2.0 el10.aarch64 pigsty 58.7 KiB fsm_core_16-1.2.0-1PGSTY.el10.noarch.rpm
postgresql-16-fsm-core 1.2.0 d12.x86_64 pigsty 52.5 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-16-fsm-core 1.2.0 d12.aarch64 pigsty 52.5 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-16-fsm-core 1.2.0 d13.x86_64 pigsty 52.6 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-16-fsm-core 1.2.0 d13.aarch64 pigsty 52.6 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-16-fsm-core 1.2.0 u22.x86_64 pigsty 53.6 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-16-fsm-core 1.2.0 u22.aarch64 pigsty 53.6 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-16-fsm-core 1.2.0 u24.x86_64 pigsty 53.4 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-16-fsm-core 1.2.0 u24.aarch64 pigsty 53.4 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-16-fsm-core 1.2.0 u26.x86_64 pigsty 53.5 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~resolute_all.deb
postgresql-16-fsm-core 1.2.0 u26.aarch64 pigsty 53.5 KiB postgresql-16-fsm-core_1.2.0-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
fsm_core_15 1.2.0 el8.x86_64 pigsty 63.4 KiB fsm_core_15-1.2.0-1PGSTY.el8.noarch.rpm
fsm_core_15 1.2.0 el8.aarch64 pigsty 63.4 KiB fsm_core_15-1.2.0-1PGSTY.el8.noarch.rpm
fsm_core_15 1.2.0 el9.x86_64 pigsty 58.5 KiB fsm_core_15-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_15 1.2.0 el9.aarch64 pigsty 58.5 KiB fsm_core_15-1.2.0-1PGSTY.el9.noarch.rpm
fsm_core_15 1.2.0 el10.x86_64 pigsty 58.7 KiB fsm_core_15-1.2.0-1PGSTY.el10.noarch.rpm
fsm_core_15 1.2.0 el10.aarch64 pigsty 58.7 KiB fsm_core_15-1.2.0-1PGSTY.el10.noarch.rpm
postgresql-15-fsm-core 1.2.0 d12.x86_64 pigsty 52.5 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-15-fsm-core 1.2.0 d12.aarch64 pigsty 52.5 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~bookworm_all.deb
postgresql-15-fsm-core 1.2.0 d13.x86_64 pigsty 52.6 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-15-fsm-core 1.2.0 d13.aarch64 pigsty 52.6 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~trixie_all.deb
postgresql-15-fsm-core 1.2.0 u22.x86_64 pigsty 53.6 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-15-fsm-core 1.2.0 u22.aarch64 pigsty 53.6 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~jammy_all.deb
postgresql-15-fsm-core 1.2.0 u24.x86_64 pigsty 53.5 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-15-fsm-core 1.2.0 u24.aarch64 pigsty 53.5 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~noble_all.deb
postgresql-15-fsm-core 1.2.0 u26.x86_64 pigsty 53.5 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~resolute_all.deb
postgresql-15-fsm-core 1.2.0 u26.aarch64 pigsty 53.5 KiB postgresql-15-fsm-core_1.2.0-1PGSTY~resolute_all.deb

Source

github.com/pgfsm/fsm/tree/main/packages/database-src-extension/fsm_core

pig build pkg fsm_core;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install fsm_core;		# install via package name, for the active PG version

pig install fsm_core -v 19;   # install for PG 19
pig install fsm_core -v 18;   # install for PG 18
pig install fsm_core -v 17;   # install for PG 17
pig install fsm_core -v 16;   # install for PG 16
pig install fsm_core -v 15;   # install for PG 15

Create this extension with:

CREATE EXTENSION fsm_core CASCADE; -- requires ltree, pgmq

Usage

Sources:

fsm_core 1.2.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:

CREATE EXTENSION fsm_core CASCADE;
SELECT fsm_core.version();

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. The 1.2.0 signature has no input_fsm_type argument:

SELECT fsm_core.load_fsm_from_json_v2(
  json_input        := :'fsm_json'::jsonb,
  root_node_text    := 'root',
  input_fsm_name    := 'creditCheck',
  input_fsm_version := 'v01'
);

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

SELECT fsm_core.create_fsm_instance_from_name_v2(
  input_fsm_name    := 'creditCheck',
  input_fsm_version := 'v01',
  input_fsm_context := '{"applicant_id":"a-42"}'::jsonb,
  create_pgmq_queue := true
) AS creation_result
\gset
SELECT :'creation_result'::jsonb AS creation_status;
SELECT :'creation_result'::jsonb ->> 'fsm_instance_id' AS fsm_instance_id
\gset

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:

SELECT fsm_core.send_event_to_fsm_queue_with_event_logs_v2(
  input_fsm_instance_id            := :'fsm_instance_id'::uuid,
  input_fsm_instance_id_fsm_type   := 'fsm',
  input_fsm_instance_id_fsm_version := 'v01',
  input_event_name                 := 'APPROVE',
  input_event_action_type          := 'user',
  input_event_data                 := '{"approved_by":"manager"}'::jsonb,
  input_event_delay                := 0
);

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.

The release notes describe sequential upgrade scripts guarded by require_version, but the reviewed 1.2.0 ZIP contains the full install script and no version-to-version upgrade scripts. Preserve populated databases and obtain a verified upgrade artifact before upgrading an existing installation. Do not rerun the full install or assume ALTER EXTENSION ... UPDATE has an available upgrade path.

Table reader