Skip to content
pg_mentat

pg_mentat

pg_mentat : Datomic-compatible data model and Datalog query engine inside PostgreSQL

Overview

ID Extension Package Version Category License Language
2980
pg_mentat
pg_mentat
1.5.7
FEAT
Apache-2.0
Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
Schemas mentat
See Also
pg_fts
pg_tre
pg_infer
rum
pg_trgm
fuzzystrmatch
vector
postgis

The PIGSTY package omits optional mentatd and installs no user-facing binary; listed integrations are soft dependencies. Effective build uses pgrx 0.19.1, migrated from upstream 0.17.0.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.5.7
18
17
16
15
14
pg_mentat -
RPM
PIGSTY
1.5.7
18
17
16
15
14
pg_mentat_$v -
DEB
PIGSTY
1.5.7
18
17
16
15
14
postgresql-$v-pg-mentat -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
el8.aarch64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
el9.x86_64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
el9.aarch64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
el10.x86_64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
el10.aarch64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
d12.x86_64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
d12.aarch64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
d13.x86_64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
d13.aarch64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
u22.x86_64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
u22.aarch64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
u24.x86_64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
u24.aarch64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
u26.x86_64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
u26.aarch64
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
PIGSTY 1.5.7
Package Version OS ORG SIZE File URL
pg_mentat_18 1.5.7 el8.x86_64 pigsty 2.6 MiB pg_mentat_18-1.5.7-1PIGSTY.el8.x86_64.rpm
pg_mentat_18 1.5.7 el8.aarch64 pigsty 1.5 MiB pg_mentat_18-1.5.7-1PIGSTY.el8.aarch64.rpm
pg_mentat_18 1.5.7 el9.x86_64 pigsty 2.6 MiB pg_mentat_18-1.5.7-1PIGSTY.el9.x86_64.rpm
pg_mentat_18 1.5.7 el9.aarch64 pigsty 1.5 MiB pg_mentat_18-1.5.7-1PIGSTY.el9.aarch64.rpm
pg_mentat_18 1.5.7 el10.x86_64 pigsty 2.6 MiB pg_mentat_18-1.5.7-1PIGSTY.el10.x86_64.rpm
pg_mentat_18 1.5.7 el10.aarch64 pigsty 1.5 MiB pg_mentat_18-1.5.7-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-mentat 1.5.7 d12.x86_64 pigsty 2.1 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-mentat 1.5.7 d12.aarch64 pigsty 1.2 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-mentat 1.5.7 d13.x86_64 pigsty 2.1 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-mentat 1.5.7 d13.aarch64 pigsty 1.2 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-mentat 1.5.7 u22.x86_64 pigsty 2.4 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-mentat 1.5.7 u22.aarch64 pigsty 1.4 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-mentat 1.5.7 u24.x86_64 pigsty 2.3 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~noble_amd64.deb
postgresql-18-pg-mentat 1.5.7 u24.aarch64 pigsty 1.3 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~noble_arm64.deb
postgresql-18-pg-mentat 1.5.7 u26.x86_64 pigsty 2.3 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-mentat 1.5.7 u26.aarch64 pigsty 1.3 MiB postgresql-18-pg-mentat_1.5.7-1PIGSTY~resolute_arm64.deb

Source

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

pig install pg_mentat -v 18;   # install for PG 18
pig install pg_mentat -v 17;   # install for PG 17
pig install pg_mentat -v 16;   # install for PG 16
pig install pg_mentat -v 15;   # install for PG 15
pig install pg_mentat -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_mentat;

Usage

Sources:

pg_mentat implements a Datomic-compatible data model and Datalog query engine inside PostgreSQL. It stores immutable facts as typed datoms and exposes schema transactions, Datalog queries, pull expressions, time travel, transaction history, and permanent excision through SQL functions. Use it for applications that need this model; it is not a transparent replacement for relational tables or SQL.

Install and Define a Schema

CREATE EXTENSION pg_mentat;

SELECT mentat.t('[
  {:db/ident       :person/name
   :db/valueType   :db.type/string
   :db/cardinality :db.cardinality/one}
  {:db/ident       :person/age
   :db/valueType   :db.type/long
   :db/cardinality :db.cardinality/one}
]');

The recommended convenience aliases live in schema mentat. Schema must be transacted before facts use the new attributes.

Transact and Query Data

SELECT mentat.t('[
  {:person/name "Alice" :person/age 30}
  {:person/name "Bob"   :person/age 25}
]');

SELECT mentat.q('
  [:find ?name ?age
   :where [?e :person/name ?name]
          [?e :person/age ?age]
          [(> ?age 28)]]
');

mentat.t(edn) applies an ACID transaction and returns its transaction report. mentat.q(query, inputs) compiles a Datalog query to PostgreSQL execution. Use EDN parameters and input bindings rather than interpolating application strings into a query.

Pull, History, and What-If Transactions

SELECT mentat.pull('[*]', 10001);
SELECT mentat.log('default', 1000001, 1000010);
SELECT mentat.diff('default', 1000003, 1000007);

SELECT mentat.mentat_with('[
  {:person/name "Alice" :person/age 31}
]');

mentat.pull returns entity-shaped JSON. mentat.log and mentat.diff expose transaction history, and mentat.mentat_with evaluates a transaction without persisting it. Queries can also be evaluated as of or since a transaction by using the documented database arguments.

Permanent excision is intentionally separate from normal immutable history:

SELECT mentat.mentat_excise('default', 10042, NULL);

Review the target entity and backups before excision; it permanently removes datoms and is intended for requirements such as privacy erasure.

Important Objects

  • mentat.t(edn): transact schema or data.
  • mentat.q(query, inputs): execute Datalog.
  • mentat.pull(pattern, eid) and mentat.pull_many(pattern, eids): entity-shaped reads.
  • mentat.entity(eid) and mentat.schema(): inspect an entity or current schema.
  • mentat.log(...) and mentat.diff(...): inspect transaction history.
  • mentat.stats(), mentat.storage(), and mentat.cache_stats(): operational inspection.
  • mentat.subscribe(...): reactive query notifications through PostgreSQL LISTEN/NOTIFY.

The extension stores typed datoms in narrow tables under schema mentat, including reference, integer, string, boolean, floating-point, instant, keyword, UUID, and byte values.

Requirements and Caveats

  • Upstream v1.5.7 supports PostgreSQL 13-18. Current Pigsty packages target PostgreSQL 14-18 and are rebuilt with pgrx 0.19.1; upstream’s tagged source declares pgrx 0.17. Treat the packaged binary as the compatibility boundary.
  • The extension is not relocatable and does not require shared_preload_libraries.
  • The optional mentatd HTTP/Datomic-wire daemon is an upstream companion program and is not included in the Pigsty pg_mentat package. SQL use of the extension does not require it.
  • Datalog compilation, pull recursion, full-text attributes, subscriptions, and history can have very different cost profiles. Inspect generated SQL with the documented explain helper and benchmark representative data.
  • Excision bypasses the normal immutable-history model. Restrict privileges and audit its use.
Last updated on