Skip to content

pg_statecharts

Hierarchical state machines and transactional event handling

pg_statecharts : Hierarchical state machines and transactional event handling

Overview

ID Extension Package Version Category License Language
2695 pg_statecharts pg_statecharts 0.1.0 FEAT MIT SQL
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
----d-- No No No Yes no no
Relationships
Schemas fsm
Requires ltree
Need By pg_statecharts_dev
Siblings pg_statecharts_dev
ltree in public

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.1.0 19 18 17 16 15 pg_statecharts ltree
RPM PIGSTY 0.1.0 19 18 17 16 15 pg_statecharts_$v postgresql$v-contrib
DEB PIGSTY 0.1.0 19 18 17 16 15 postgresql-$v-pg-statecharts postgresql-$v
Linux / PG PG19 PG18 PG17 PG16 PG15
el8.x86_64 N/A PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el8.aarch64 N/A PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el9.x86_64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el9.aarch64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el10.x86_64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el10.aarch64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
d12.x86_64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
d12.aarch64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
d13.x86_64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
d13.aarch64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u22.x86_64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u22.aarch64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u24.x86_64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u24.aarch64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u26.x86_64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u26.aarch64 MISS PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
Package Version OS ORG SIZE File URL
pg_statecharts_18 0.1.0 el8.x86_64 pigsty 31.8 KiB pg_statecharts_18-0.1.0-1PGSTY.el8.noarch.rpm
pg_statecharts_18 0.1.0 el8.aarch64 pigsty 31.8 KiB pg_statecharts_18-0.1.0-1PGSTY.el8.noarch.rpm
pg_statecharts_18 0.1.0 el9.x86_64 pigsty 30.8 KiB pg_statecharts_18-0.1.0-1PGSTY.el9.noarch.rpm
pg_statecharts_18 0.1.0 el9.aarch64 pigsty 30.8 KiB pg_statecharts_18-0.1.0-1PGSTY.el9.noarch.rpm
pg_statecharts_18 0.1.0 el10.x86_64 pigsty 30.9 KiB pg_statecharts_18-0.1.0-1PGSTY.el10.noarch.rpm
pg_statecharts_18 0.1.0 el10.aarch64 pigsty 30.9 KiB pg_statecharts_18-0.1.0-1PGSTY.el10.noarch.rpm
postgresql-18-pg-statecharts 0.1.0 d12.x86_64 pigsty 25.1 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~bookworm_all.deb
postgresql-18-pg-statecharts 0.1.0 d12.aarch64 pigsty 25.1 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~bookworm_all.deb
postgresql-18-pg-statecharts 0.1.0 d13.x86_64 pigsty 25.1 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~trixie_all.deb
postgresql-18-pg-statecharts 0.1.0 d13.aarch64 pigsty 25.1 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~trixie_all.deb
postgresql-18-pg-statecharts 0.1.0 u22.x86_64 pigsty 25.7 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~jammy_all.deb
postgresql-18-pg-statecharts 0.1.0 u22.aarch64 pigsty 25.7 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~jammy_all.deb
postgresql-18-pg-statecharts 0.1.0 u24.x86_64 pigsty 25.5 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~noble_all.deb
postgresql-18-pg-statecharts 0.1.0 u24.aarch64 pigsty 25.5 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~noble_all.deb
postgresql-18-pg-statecharts 0.1.0 u26.x86_64 pigsty 25.5 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~resolute_all.deb
postgresql-18-pg-statecharts 0.1.0 u26.aarch64 pigsty 25.5 KiB postgresql-18-pg-statecharts_0.1.0-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
pg_statecharts_17 0.1.0 el8.x86_64 pigsty 31.8 KiB pg_statecharts_17-0.1.0-1PGSTY.el8.noarch.rpm
pg_statecharts_17 0.1.0 el8.aarch64 pigsty 31.8 KiB pg_statecharts_17-0.1.0-1PGSTY.el8.noarch.rpm
pg_statecharts_17 0.1.0 el9.x86_64 pigsty 30.8 KiB pg_statecharts_17-0.1.0-1PGSTY.el9.noarch.rpm
pg_statecharts_17 0.1.0 el9.aarch64 pigsty 30.8 KiB pg_statecharts_17-0.1.0-1PGSTY.el9.noarch.rpm
pg_statecharts_17 0.1.0 el10.x86_64 pigsty 30.9 KiB pg_statecharts_17-0.1.0-1PGSTY.el10.noarch.rpm
pg_statecharts_17 0.1.0 el10.aarch64 pigsty 30.9 KiB pg_statecharts_17-0.1.0-1PGSTY.el10.noarch.rpm
postgresql-17-pg-statecharts 0.1.0 d12.x86_64 pigsty 25.1 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~bookworm_all.deb
postgresql-17-pg-statecharts 0.1.0 d12.aarch64 pigsty 25.1 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~bookworm_all.deb
postgresql-17-pg-statecharts 0.1.0 d13.x86_64 pigsty 25.1 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~trixie_all.deb
postgresql-17-pg-statecharts 0.1.0 d13.aarch64 pigsty 25.1 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~trixie_all.deb
postgresql-17-pg-statecharts 0.1.0 u22.x86_64 pigsty 25.7 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~jammy_all.deb
postgresql-17-pg-statecharts 0.1.0 u22.aarch64 pigsty 25.7 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~jammy_all.deb
postgresql-17-pg-statecharts 0.1.0 u24.x86_64 pigsty 25.5 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~noble_all.deb
postgresql-17-pg-statecharts 0.1.0 u24.aarch64 pigsty 25.5 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~noble_all.deb
postgresql-17-pg-statecharts 0.1.0 u26.x86_64 pigsty 25.5 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~resolute_all.deb
postgresql-17-pg-statecharts 0.1.0 u26.aarch64 pigsty 25.5 KiB postgresql-17-pg-statecharts_0.1.0-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
pg_statecharts_16 0.1.0 el8.x86_64 pigsty 31.8 KiB pg_statecharts_16-0.1.0-1PGSTY.el8.noarch.rpm
pg_statecharts_16 0.1.0 el8.aarch64 pigsty 31.8 KiB pg_statecharts_16-0.1.0-1PGSTY.el8.noarch.rpm
pg_statecharts_16 0.1.0 el9.x86_64 pigsty 30.8 KiB pg_statecharts_16-0.1.0-1PGSTY.el9.noarch.rpm
pg_statecharts_16 0.1.0 el9.aarch64 pigsty 30.8 KiB pg_statecharts_16-0.1.0-1PGSTY.el9.noarch.rpm
pg_statecharts_16 0.1.0 el10.x86_64 pigsty 30.9 KiB pg_statecharts_16-0.1.0-1PGSTY.el10.noarch.rpm
pg_statecharts_16 0.1.0 el10.aarch64 pigsty 30.9 KiB pg_statecharts_16-0.1.0-1PGSTY.el10.noarch.rpm
postgresql-16-pg-statecharts 0.1.0 d12.x86_64 pigsty 25.1 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~bookworm_all.deb
postgresql-16-pg-statecharts 0.1.0 d12.aarch64 pigsty 25.1 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~bookworm_all.deb
postgresql-16-pg-statecharts 0.1.0 d13.x86_64 pigsty 25.1 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~trixie_all.deb
postgresql-16-pg-statecharts 0.1.0 d13.aarch64 pigsty 25.1 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~trixie_all.deb
postgresql-16-pg-statecharts 0.1.0 u22.x86_64 pigsty 25.7 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~jammy_all.deb
postgresql-16-pg-statecharts 0.1.0 u22.aarch64 pigsty 25.7 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~jammy_all.deb
postgresql-16-pg-statecharts 0.1.0 u24.x86_64 pigsty 25.5 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~noble_all.deb
postgresql-16-pg-statecharts 0.1.0 u24.aarch64 pigsty 25.5 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~noble_all.deb
postgresql-16-pg-statecharts 0.1.0 u26.x86_64 pigsty 25.5 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~resolute_all.deb
postgresql-16-pg-statecharts 0.1.0 u26.aarch64 pigsty 25.5 KiB postgresql-16-pg-statecharts_0.1.0-1PGSTY~resolute_all.deb

Source

pig build pkg pg_statecharts;		# 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 pg_statecharts;		# install via package name, for the active PG version

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

Create this extension with:

CREATE EXTENSION pg_statecharts CASCADE; -- requires ltree

Usage

Sources:

pg_statecharts 0.1.0 runs hierarchical state machines and their events transactionally inside PostgreSQL. This release is pure SQL, tested on PostgreSQL 16–18, and needs no preload or restart.

Core Workflow

Install ltree in public, then install the extension with a role that has the required object-creation privileges:

CREATE EXTENSION IF NOT EXISTS ltree WITH SCHEMA public;
CREATE EXTENSION pg_statecharts;

Deploy a statechart definition through SQL migrations or the development companion before starting a machine. For an already deployed chart named order, this starts its latest version and returns the machine row:

SELECT * FROM fsm.start_machine_with_latest_statechart(1, 'order', '{}');

Events are inserted into fsm.state_machine_event with the shard, machine identifier, event name and JSON data. Its triggers process the event in the inserting transaction, including entry and exit callbacks. Callers must have the appropriate table and function privileges; chart callbacks are application code that needs its own review.

Catalog and Versions

Definitions and running machines live in fsm. fsm.to_semver parses numeric chart versions and fsm.semver_text renders them; stored versions are integer arrays so their native ordering remains numeric. Do not sort a textual rendering when version precedence matters.

Backups and Legacy Migration

The reviewed 0.1.0 source registers state tables and sequences for database dumps. The event inbox is intentionally omitted to avoid replaying callbacks during restoration. Backups made with 0.0.0 omitted machine state; take a fresh, restore-tested backup after upgrading.

An earlier 0.1.0 installation may predate dump registration, so check the installed catalog instead of trusting its version string. Do not drop a populated extension merely to refresh registration. Legacy Rust or Sqitch migrations require superuser work and the old semver dependency during conversion; follow the migration guide and rehearse on a restored copy. The old 0.0.0 path is no longer independently exercised upstream.

Table reader