Skip to content

pgrdf

RDF, SPARQL, SHACL, and OWL reasoning for PostgreSQL

pgrdf · RDF, SPARQL, SHACL, and OWL reasoning for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2640pgrdfpgrdf0.6.41FEATMITRust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Relationships
Schemaspgrdf
See Alsosparql rdf_fdw age pg_liquid onesparse graph ltree xml2 plxslt omni_xml
Preload for hooks/cache.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY0.6.4119 18 17 16 15pgrdf-
RPMPIGSTY0.6.4119 18 17 16 15pgrdf_$v-
DEBPIGSTY0.6.4119 18 17 16 15postgresql-$v-pgrdf-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.6.40PIGSTY 0.6.40PIGSTY 0.6.40PIGSTY 0.6.40
el8.aarch64N/APIGSTY 0.6.40PIGSTY 0.6.40PIGSTY 0.6.40PIGSTY 0.6.40
el9.x86_64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
el9.aarch64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
el10.x86_64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
el10.aarch64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
d12.x86_64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
d12.aarch64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
d13.x86_64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
d13.aarch64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
u22.x86_64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
u22.aarch64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
u24.x86_64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
u24.aarch64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
u26.x86_64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41
u26.aarch64PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41PIGSTY 0.6.41

Source

pig build pkg pgrdf;		# 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 pgrdf;		# install by package name

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

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pgrdf';

Create this extension with:

CREATE EXTENSION pgrdf;

Usage

Sources:

pgrdf 0.6.44 stores RDF graphs in PostgreSQL with Turtle/TriG/N-Quads ingestion, SPARQL queries and updates, SHACL validation, and RDFS/OWL reasoning. Create the extension as a superuser. Preload pgrdf and restart to enable staged loading, activity tracking and the shared term cache; ordinary loading, queries, reasoning and validation also work without preload.

Core Workflow

shared_preload_libraries = 'pgrdf'
CREATE EXTENSION pgrdf;
SELECT pgrdf.add_graph('http://example.org/people');
SELECT pgrdf.parse_turtle(
  '@prefix ex: <http://example.org/> . ex:alice ex:name "Alice" .',
  pgrdf.graph_id('http://example.org/people'));
SELECT * FROM pgrdf.sparql('SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10');
SELECT * FROM pgrdf.surface();

Operational Boundaries

The fixed pgrdf schema provides add_graph, graph_id, parse_turtle, load_turtle, sparql, materialize, validate, stats and surface. File loaders read server-side paths; grant access deliberately. Do not grant TRIGGER or blanket ALL privileges on storage tables: a user-installed trigger can run with the storage owner’s privileges. can_clear_graphs() reports graph-clear privileges. Non-owner graph writes require the documented underlying table grants; graph locks still apply. shacl_capability() reports the supported validation surface, and path-depth/truncation settings bound traversal. Current builds support PostgreSQL 15–19; PG14 users must stay on 0.6.42. Each binary must match its target major. Version 0.6.39 allocates graph IDs from a non-reusing sequence; the IRI is the graph identity, and gaps are normal. After installing the matching library, run ALTER EXTENSION pgrdf UPDATE in each database. A newer library rejects old SQL with SQLSTATE 55000. Do not use the broken 0.6.35–0.6.38 PGXN source archives. Preserve graph/dictionary data together in verified backups.

Ownership Repair in 0.6.40

The 0.6.39 upgrade could leave _pgrdf_graph_id_seq owned by the upgrade executor after storage tables had been transferred to another role, preventing new graph creation. Version 0.6.40 aligns that sequence with the owner of _pgrdf_quads; granting sequence usage alone is insufficient. pgrdf.ownership_drift() reports mismatched storage owners and proposed repair commands. Review them before applying role changes. Upgrade SQL in each database after installing matching binaries; versions 0.6.34–0.6.38 can upgrade directly to 0.6.40.

Version 0.6.41: Graph Sets and Backups

New graph partitions enforce unique subject/predicate/object triples; repeated ingestion does not add duplicates, and asserted triples take precedence over inferred ones. An in-place upgrade does not rewrite existing graphs containing repeats: it warns about them. Inspect pgrdf.duplicate_report() and review pgrdf.dedup_graph() before changing existing data.

This release fixes logical dumps omitting the graph registry, default-graph triples and dictionary allocator. Take and restore-test a fresh backup after upgrading. Stored literals containing U+0000 now fail on read; pgrdf.nul_term_report() identifies them for repair. Graph owners, owner enforcement and recorded graph acts add administrative controls; inspect privileges rather than assuming previously PUBLIC maintenance functions remain callable.

Install matching binaries, restart for the preloaded library and run ALTER EXTENSION pgrdf UPDATE;. PostgreSQL 18 must be 18.7 or later. Older SQL/library mismatch guards and the existing sequence-ownership checks remain relevant.

Version 0.6.42: Counts, Listing and Polling

Version 0.6.42 is now an official release dated November 29, 2026. The final tag adds dictionary counts and stronger restoration guidance beyond the earlier source revision with the same version. Use matching release binaries and SQL.

graph_inventory() and count_quads() use stored counts. The inventory adds change_seq, counts_verified, counts_scanned_at and last_act_id. Direct SQL writes mark affected counts unverified; those graphs are counted by scanning until recount_graph() repairs the stored counts. This preserves exact counts while losing the fast path. Disabled triggers and partition attach/detach/drop operations can bypass that detection and require a recount.

SELECT * FROM pgrdf.graph_inventory();
SELECT * FROM pgrdf.graph_totals();
SELECT * FROM pgrdf.recount_graph();

The inventory is now filtered by role: a superuser, a role holding the storage owner’s privileges, or pg_read_all_data sees all graphs; other roles see their own. Graphs without a recorded owner are visible only to administrators until ownership is assigned. Compare graphs_listed and graphs_total to distinguish hidden graphs from missing ones. This controls listing, not tenant isolation: roles able to read triples can still query them, and the act record remains readable.

For reliable polling use graph_act_feed(after, only_graph, page, max_acts). Follow next_page until it is NULL, retain complete_below as the next after cursor, and deduplicate already seen act IDs. Timestamp-only polling can miss transactions that commit later. Long-running transactions can hold back cursor progress and increase stored-count read work.

After installing the matching preloaded library and restarting, upgrade each database. The SQL upgrade scans all graph counts once and blocks writers until commit while allowing readers. It drops and recreates graph_inventory() because its result type changed: dependent views can block the upgrade, and function-specific grants must be reviewed and reapplied. Preserve their definitions before migration. Logical restoration leaves counts unverified; run recount_graph() with an appropriate owner role afterward. The earlier backup, uniqueness and ownership repair requirements still apply.

Final 0.6.42 Tag: Dictionary Counts and Upgrade Locks

graph_totals() reports dictionary terms and terms_verified only to administrators. Plain SQL term changes or a dump/restore leave the count unverified, so the total is NULL rather than an expensive implicit scan. pgrdf.count_terms() explicitly returns the exact count, using a scan when necessary; pgrdf.recount_terms() stores a fresh count and requires the storage owner’s privileges.

The final upgrade scans both the dictionary and quad table. Quiesce writers first: their differing lock order can cause SQLSTATE 40P01; the upgrade is atomic and can be retried after resolving contention. After logical restoration, run both pgrdf.recount_graph() and pgrdf.recount_terms() as the appropriate owner. pg_upgrade does not need these recounts. Manually registered or default-partition graph IDs without dedicated storage remain scan-counted.

A persistent graph-count cache should key on (graph_id, counts_scanned_at, change_seq) only while counts_verified is true, and read the key outside its own write transaction. Recount, clear, storage replacement and restoration can reset the epoch; a primary’s cache key is not interchangeable with a standby’s.

0.6.43–0.6.44: Compatibility and Validation Fixes

Version 0.6.43 updates pgrx and adds PostgreSQL 19 support; 0.6.44 fixes SHACL-SPARQL and SPARQL evaluation. Upstream gates all 98 W3C SHACL Core tests in three modes. Of 23 SHACL-SPARQL tests, 10 are gated and 13 remain pending; this is not full conformance.

These two SQL upgrades only advance the version and do not rewrite graph data, but library and SQL must still match. Stale dictionary statistics after bulk loading can produce pathological plans; run ANALYZE pgrdf._pgrdf_dictionary after loading, and retain the existing count, ownership and backup/recovery procedures.

Table reader