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 postgresThen 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 get | Start here | |
|---|---|---|
| storage Load | Turtle, N-Triples, TriG, N-Quads, from SQL strings or server files; parallel loaders for very large N-Triples dumps | Storage |
| search Query | SPARQL 1.1 SELECT / ASK / CONSTRUCT / DESCRIBE, aggregates, property paths, named graphs, full UPDATE; results are JSONB rows you can join with any table | Query |
| psychology Reason | OWL 2 RL or RDFS materialization, stored beside your data, with a freshness flag | Inference |
| fact_check Validate | W3C SHACL Core (25/25 on the conformance suite) plus SHACL-SPARQL, with the report as JSONB | Validation |
| account_tree Manage graphs | Inventory, copy / move / clear / drop, carving by predicate or neighbourhood, write locks, integrity checks | Graphs |
| verified Identity and export | Canonical graph digests (W3C RDFC-1.0), canonical N-Triples export, a manifest anyone can verify offline | Identity |
| settings Operate | Standard SQLSTATE error codes, per-query completeness, settings, capability listing, statistics | Errors and diagnostics |
Why inside PostgreSQL
| A separate triple store | pgRDF | |
|---|---|---|
| Where the graph lives | Another server to run | In your PostgreSQL database |
| Backups, replication, point-in-time recovery | Its own tooling | PostgreSQL's |
| Users, roles, TLS | Its own | PostgreSQL's |
| Combining graph and relational data | Export, sync, glue code | One SQL query |
| Transactions | Separate | Graph changes commit or roll back with the rest of your transaction |
Who it's for
- code Application developers: start with the tour and the client guides for Python, Node.js, Go and Rust.
- query_stats Data engineers: see loading, SPARQL and combining with SQL.
- school Ontologists: see reasoning and validation.
- settings Operators: see install, errors and diagnostics and scale.
- build Contributors: see the internals.
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 withgh 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.
