Skip to content

fsm_core

Finite state machine toolkit for PostgreSQL

fsm_core · Finite state machine toolkit for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2690fsm_corefsm_core1.4.0FEATAGPL-3.0-onlySQL
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
----d--NoNoNoYesnono
Relationships
Schemasfsm_core
Requiresltree pgmq pg_cron
See Alsopgmq ulak pgmb pg_durable redis pg_task pg_background pgq redis_fdw tcn

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.4.019 18 17 16 15fsm_coreltree, pgmq, pg_cron
RPMPIGSTY1.4.019 18 17 16 15fsm_core_$vpgmq_$v
DEBPIGSTY1.4.019 18 17 16 15postgresql-$v-fsm-corepostgresql-$v-pgmq, postgresql-$v-pg-jsonschema
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
el8.aarch64N/APIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
el9.x86_64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
el9.aarch64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
el10.x86_64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
el10.aarch64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
d12.x86_64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
d12.aarch64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
d13.x86_64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
d13.aarch64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
u22.x86_64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
u22.aarch64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
u24.x86_64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
u24.aarch64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
u26.x86_64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
u26.aarch64PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0PIGSTY 1.4.0
PackageVersionOSORGSIZEFile URL
fsm_core_191.4.0el9.x86_64pigsty70.5 KiBfsm_core_19-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_191.4.0el9.aarch64pigsty70.5 KiBfsm_core_19-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_191.4.0el10.x86_64pigsty70.8 KiBfsm_core_19-1.4.0-1PGSTY.el10.noarch.rpm
fsm_core_191.4.0el10.aarch64pigsty70.8 KiBfsm_core_19-1.4.0-1PGSTY.el10.noarch.rpm
postgresql-19-fsm-core1.4.0d12.x86_64pigsty64.7 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-19-fsm-core1.4.0d12.aarch64pigsty64.7 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-19-fsm-core1.4.0d13.x86_64pigsty64.7 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-19-fsm-core1.4.0d13.aarch64pigsty64.7 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-19-fsm-core1.4.0u22.x86_64pigsty66.0 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-19-fsm-core1.4.0u22.aarch64pigsty66.0 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-19-fsm-core1.4.0u24.x86_64pigsty65.8 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-19-fsm-core1.4.0u24.aarch64pigsty65.8 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-19-fsm-core1.4.0u26.x86_64pigsty65.8 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~resolute_all.deb
postgresql-19-fsm-core1.4.0u26.aarch64pigsty65.8 KiBpostgresql-19-fsm-core_1.4.0-1PGSTY~resolute_all.deb
PackageVersionOSORGSIZEFile URL
fsm_core_181.4.0el8.x86_64pigsty76.5 KiBfsm_core_18-1.4.0-1PGSTY.el8.noarch.rpm
fsm_core_181.4.0el8.aarch64pigsty76.5 KiBfsm_core_18-1.4.0-1PGSTY.el8.noarch.rpm
fsm_core_181.4.0el9.x86_64pigsty70.5 KiBfsm_core_18-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_181.4.0el9.aarch64pigsty70.5 KiBfsm_core_18-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_181.4.0el10.x86_64pigsty70.8 KiBfsm_core_18-1.4.0-1PGSTY.el10.noarch.rpm
fsm_core_181.4.0el10.aarch64pigsty70.8 KiBfsm_core_18-1.4.0-1PGSTY.el10.noarch.rpm
postgresql-18-fsm-core1.4.0d12.x86_64pigsty64.6 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-18-fsm-core1.4.0d12.aarch64pigsty64.6 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-18-fsm-core1.4.0d13.x86_64pigsty64.7 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-18-fsm-core1.4.0d13.aarch64pigsty64.7 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-18-fsm-core1.4.0u22.x86_64pigsty66.0 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-18-fsm-core1.4.0u22.aarch64pigsty66.0 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-18-fsm-core1.4.0u24.x86_64pigsty65.8 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-18-fsm-core1.4.0u24.aarch64pigsty65.8 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-18-fsm-core1.4.0u26.x86_64pigsty65.8 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~resolute_all.deb
postgresql-18-fsm-core1.4.0u26.aarch64pigsty65.8 KiBpostgresql-18-fsm-core_1.4.0-1PGSTY~resolute_all.deb
PackageVersionOSORGSIZEFile URL
fsm_core_171.4.0el8.x86_64pigsty76.5 KiBfsm_core_17-1.4.0-1PGSTY.el8.noarch.rpm
fsm_core_171.4.0el8.aarch64pigsty76.5 KiBfsm_core_17-1.4.0-1PGSTY.el8.noarch.rpm
fsm_core_171.4.0el9.x86_64pigsty70.5 KiBfsm_core_17-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_171.4.0el9.aarch64pigsty70.5 KiBfsm_core_17-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_171.4.0el10.x86_64pigsty70.8 KiBfsm_core_17-1.4.0-1PGSTY.el10.noarch.rpm
fsm_core_171.4.0el10.aarch64pigsty70.8 KiBfsm_core_17-1.4.0-1PGSTY.el10.noarch.rpm
postgresql-17-fsm-core1.4.0d12.x86_64pigsty64.7 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-17-fsm-core1.4.0d12.aarch64pigsty64.7 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-17-fsm-core1.4.0d13.x86_64pigsty64.7 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-17-fsm-core1.4.0d13.aarch64pigsty64.7 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-17-fsm-core1.4.0u22.x86_64pigsty66.0 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-17-fsm-core1.4.0u22.aarch64pigsty66.0 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-17-fsm-core1.4.0u24.x86_64pigsty65.8 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-17-fsm-core1.4.0u24.aarch64pigsty65.8 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-17-fsm-core1.4.0u26.x86_64pigsty65.8 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~resolute_all.deb
postgresql-17-fsm-core1.4.0u26.aarch64pigsty65.8 KiBpostgresql-17-fsm-core_1.4.0-1PGSTY~resolute_all.deb
PackageVersionOSORGSIZEFile URL
fsm_core_161.4.0el8.x86_64pigsty76.5 KiBfsm_core_16-1.4.0-1PGSTY.el8.noarch.rpm
fsm_core_161.4.0el8.aarch64pigsty76.5 KiBfsm_core_16-1.4.0-1PGSTY.el8.noarch.rpm
fsm_core_161.4.0el9.x86_64pigsty70.5 KiBfsm_core_16-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_161.4.0el9.aarch64pigsty70.5 KiBfsm_core_16-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_161.4.0el10.x86_64pigsty70.8 KiBfsm_core_16-1.4.0-1PGSTY.el10.noarch.rpm
fsm_core_161.4.0el10.aarch64pigsty70.8 KiBfsm_core_16-1.4.0-1PGSTY.el10.noarch.rpm
postgresql-16-fsm-core1.4.0d12.x86_64pigsty64.7 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-16-fsm-core1.4.0d12.aarch64pigsty64.7 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-16-fsm-core1.4.0d13.x86_64pigsty64.7 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-16-fsm-core1.4.0d13.aarch64pigsty64.7 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-16-fsm-core1.4.0u22.x86_64pigsty66.0 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-16-fsm-core1.4.0u22.aarch64pigsty66.0 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-16-fsm-core1.4.0u24.x86_64pigsty65.8 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-16-fsm-core1.4.0u24.aarch64pigsty65.8 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-16-fsm-core1.4.0u26.x86_64pigsty65.8 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~resolute_all.deb
postgresql-16-fsm-core1.4.0u26.aarch64pigsty65.8 KiBpostgresql-16-fsm-core_1.4.0-1PGSTY~resolute_all.deb
PackageVersionOSORGSIZEFile URL
fsm_core_151.4.0el8.x86_64pigsty76.5 KiBfsm_core_15-1.4.0-1PGSTY.el8.noarch.rpm
fsm_core_151.4.0el8.aarch64pigsty76.5 KiBfsm_core_15-1.4.0-1PGSTY.el8.noarch.rpm
fsm_core_151.4.0el9.x86_64pigsty70.5 KiBfsm_core_15-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_151.4.0el9.aarch64pigsty70.5 KiBfsm_core_15-1.4.0-1PGSTY.el9.noarch.rpm
fsm_core_151.4.0el10.x86_64pigsty70.8 KiBfsm_core_15-1.4.0-1PGSTY.el10.noarch.rpm
fsm_core_151.4.0el10.aarch64pigsty70.8 KiBfsm_core_15-1.4.0-1PGSTY.el10.noarch.rpm
postgresql-15-fsm-core1.4.0d12.x86_64pigsty64.7 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-15-fsm-core1.4.0d12.aarch64pigsty64.7 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~bookworm_all.deb
postgresql-15-fsm-core1.4.0d13.x86_64pigsty64.7 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-15-fsm-core1.4.0d13.aarch64pigsty64.7 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~trixie_all.deb
postgresql-15-fsm-core1.4.0u22.x86_64pigsty66.0 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-15-fsm-core1.4.0u22.aarch64pigsty66.0 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~jammy_all.deb
postgresql-15-fsm-core1.4.0u24.x86_64pigsty65.8 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-15-fsm-core1.4.0u24.aarch64pigsty65.8 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~noble_all.deb
postgresql-15-fsm-core1.4.0u26.x86_64pigsty65.8 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~resolute_all.deb
postgresql-15-fsm-core1.4.0u26.aarch64pigsty65.8 KiBpostgresql-15-fsm-core_1.4.0-1PGSTY~resolute_all.deb

Source

github.com/pgfsm/fsm/tree/fsm_core-v1.4.0/packages/database-src

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 by package name

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, pg_cron

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:

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. This call loads the definition by name and version.

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.

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.

Table reader