Skip to content

Introduction ​

At a glance

pgRDF · RDF, SPARQL, SHACL and OWL reasoning inside PostgreSQL · License MIT · PostgreSQL 18 · Latest release v0.6.34 · Install → · Ten-minute tour →

pgRDF is a PostgreSQL extension, written in Rust, that turns your database into a knowledge-graph engine. With it you can:

  • load RDF;
  • query and update it with SPARQL 1.1;
  • reason over it with OWL 2 RL or RDFS;
  • validate it with SHACL;
  • lock, fingerprint and export it.

Every operation is a SQL function call, so any PostgreSQL client already works with it.

sql
CREATE EXTENSION pgrdf;

SELECT pgrdf.add_graph('http://example.org/people');

SELECT pgrdf.parse_turtle($$
  @prefix ex:   <http://example.org/> .
  @prefix foaf: <http://xmlns.com/foaf/0.1/> .
  ex:alice foaf:name "Alice" ; foaf:knows ex:bob .
  ex:bob   foaf:name "Bob" .
$$, pgrdf.graph_id('http://example.org/people'));

SELECT * FROM pgrdf.sparql($$
  PREFIX foaf: <http://xmlns.com/foaf/0.1/>
  SELECT ?who ?friend WHERE { ?a foaf:name ?who ; foaf:knows ?b . ?b foaf:name ?friend }
$$);
--  {"who": "Alice", "friend": "Bob"}

Try it in two minutes ​

With Docker and nothing else, run the extension in a stock postgres:18 container:

sh
VER=0.6.34
ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')
curl -fsSL https://github.com/styk-tv/pgRDF/releases/download/v$VER/pgrdf-$VER-pg18-glibc-$ARCH.tar.gz | tar -xz

docker create --name pgrdf -e POSTGRES_PASSWORD=pgrdf -p 5432:5432 \
  postgres:18 -c shared_preload_libraries=pgrdf
docker cp pgrdf-$VER-pg18-glibc-$ARCH/lib/pgrdf.so       pgrdf:/usr/lib/postgresql/18/lib/
docker cp pgrdf-$VER-pg18-glibc-$ARCH/share/extension/.  pgrdf:/usr/share/postgresql/18/extension/
docker start pgrdf

until docker exec pgrdf pg_isready -h localhost -U postgres -q; do sleep 1; done
docker exec -it pgrdf psql -U postgres -c 'CREATE EXTENSION pgrdf'
docker exec -it pgrdf psql -U postgres

Then follow the ten-minute tour. Other routes (your own image, an existing server, Kubernetes, the signed OCI bundle) are on the install page.

What's inside ​

What you getStart here
storage LoadTurtle, N-Triples, TriG, N-Quads, from SQL strings or server files; parallel loaders for very large N-Triples dumpsStorage
search QuerySPARQL 1.1 SELECT / ASK / CONSTRUCT / DESCRIBE, aggregates, property paths, named graphs, full UPDATE; results are JSONB rows you can join with any tableQuery
psychology ReasonOWL 2 RL or RDFS materialization, stored beside your data, with a freshness flagInference
fact_check ValidateW3C SHACL Core (25/25 on the conformance suite) plus SHACL-SPARQL, with the report as JSONBValidation
account_tree Manage graphsInventory, copy / move / clear / drop, carving by predicate or neighbourhood, write locks, integrity checksGraphs
verified Identity and exportCanonical graph digests (W3C RDFC-1.0), canonical N-Triples export, a manifest anyone can verify offlineIdentity
settings OperateStandard SQLSTATE error codes, per-query completeness, settings, capability listing, statisticsErrors and diagnostics

Why inside PostgreSQL ​

A separate triple storepgRDF
Where the graph livesAnother server to runIn your PostgreSQL database
Backups, replication, point-in-time recoveryIts own toolingPostgreSQL's
Users, roles, TLSIts ownPostgreSQL's
Combining graph and relational dataExport, sync, glue codeOne SQL query
TransactionsSeparateGraph changes commit or roll back with the rest of your transaction

Who it's for ​

Scale ​

The same extension runs a few triples in a container and very large graphs on one server:

  • a complete Wikidata "truthy" dump, 8.2 billion triples, loaded into a single instance;
  • the full load → reason → query pipeline at LUBM-500, ending in a 112-million-quad materialized closure.

See Scale and benchmarks.

Get the bits ​

  • Releases: github.com/styk-tv/pgRDF/releases. Archives for PostgreSQL 18 on x86-64 and arm64, with SHA256SUMS.
  • Signed OCI bundle: ghcr.io/styk-tv/pgrdf-bundle, with SLSA build provenance you can check with gh attestation verify oci://ghcr.io/styk-tv/pgrdf-bundle:0.6.34 --repo styk-tv/pgRDF.
  • Current version and digests:LATEST.md.
  • What changed: CHANGELOG.
  • Source: github.com/styk-tv/pgRDF.

Next — the ten-minute tour →

pgRDF is released under the MIT license. Documentation built with VitePress, served via GitHub Pages.