Postgres
Postgres 14 or later (tested on 16), as drivine4j states, keeps a graph in two tables, as Oracle does, read with joins and written through a function the store keeps. No extension is needed but pgvector, for vector search, which Drivine makes where the server has it. Models, the query DSL and the object manager are the same as on the graph engines; the persistence manager runs plain SQL, with cursors and transactions, and Cypher compiled to SQL: see Cypher on a relational database.
DATABASE_TYPE=POSTGRESDATABASE_HOST=localhostDATABASE_PORT=5432DATABASE_NAME=appDATABASE_USER=appDATABASE_PASSWORD=…DATABASE_DEFAULT_GRAPH_PATH=drivine # names the graph's tables; this is the defaultThe graph’s name names tables, so it is letters, digits and underscores, begins with a letter, and is at most 49 characters; Postgres folds it to lower case. The tables are made on the first connection when they aren’t there, as on Oracle, whatever is sent first: Cypher or SQL through the persistence manager, a statement of the object manager, or a schema change. A user who may read the tables but not make them works once they are made. Postgres is a graph store like the others, so a schema catalog that names no database applies to it too, and makes its indexes at startup.
How a graph is stored. drivine4j’s store, byte for byte, so the JVM, Node and Python read and write one graph:
<graph>_node (nid, labels, props, stamp, words) and <graph>_edge (eid, src, dst, type, props), with labels and
props as jsonb and a GIN index over the labels, so a node carries any number of them; <graph>_schema, the indexes
and constraints Drivine made; and <graph>_write, the function a save’s steps are carried out by, as one statement that
is applied whole or not at all.
- A statement you write yourself is SQL, unless written as Cypher (see
Cypher on Postgres, Oracle and SQLite). Parameters are named
$name, as in Cypher, and a statement is bound only the ones it names outside quoted text and comments: the$tof'$t'or$q$ $t $q$is none. A row comes back as a dict of its columns, ajsonbcolumn as Python values. - A raw
where, for a load or a delete, is SQL over the root’s rown: itsprops,labelsandstamp, say(n.props ->> 'name') = $name, read over the row a statement calls it by,n_(the row the shared module’s fragments read). A property of the root may be written as Cypher writes it,n.name = $name(orn.`a name`), and is read as that property, as text, and one whose stored name begins with$,n.`$score`, by the name the store holds it by; a property compared withtrueorfalse, or with a parameter bound toTrueorFalse, is compared with the text a JSON boolean is read as. To compare one with a number, read it as a number in SQL:CAST(n.`$score` AS NUMERIC) > $least. A date in a rawwhereis compared with the property’s JSON text, the tag a save holds it as, so(n.props ->> 'at') = $whenfinds nothing: compare dates in the query DSL. - A number is compared as a number only where one is stored:
'7'is not7, as on the graph engines. - Behaviour change: text is compared and ordered by its code points, as Neo4j orders it, in the query DSL’s
conditions (
gt,ltand the rest on text), orders, seeks and grouped reads, as in compiled Cypher (Cypher on Postgres, Oracle and SQLite): their SQL is the shared module’s (drivine-cypher-spec#235), in theCcollation (COLLATE "C"), where the DSL used the database’s collation before. Soa, B, bsorts asB, a, b, as on SQLite and Neo4j, where it sorteda, b, B. - A save checks the stamp, as on the graph engines. A save turned away by a serialization failure (
40001) or a deadlock (40P01) is run again. - Index the id of each class you save: a range index or a uniqueness constraint is a partial index over the label’s nodes, which finds a node by its id.
matchestakes a Postgres regular expression, matched against the whole value.- A vector index is a pgvector HNSW index over the embeddings of the label’s nodes of its size;
load_nearestis approximate through it, and exact with no index made. A full-text index is a trigram index over the text a search reads, which narrows the search;load_matchingscores the same with it and without it, and reads words, a"phrase",+must,-notand aprefix*. A word is a run of letters as Unicode’s Alphabetic holds them (with the vowel signs of Indic scripts), decimal digits and underscores, as the text’s[[:alnum:]_]reads it:m²xis the phrasem x. In a phrase a*is text, as on Neo4j:"of sou*"is the phraseof sou. It scores by BM25, as Lucene and so Neo4j’s full-text index do (k11.2,b0.75): a term weighs as it is rare among the label’s nodes, and a text’s counts against its length, in characters, beside the label’s average. A term written again at once,kiwi kiwi kiwi, is counted each time. Aprefix*adds the same to every node that holds it, however often and however rare, as Lucene’s prefix query does: inkiw* melon, a node withkiwiand nomelonscores about 0.54 of one with both, as on Neo4j. Oracle without Oracle Text scores the same way. A dotted name, asorg.example.models, is words here, split at each dot, as it is on Oracle and SQLite:example modelsfinds it, and the name itself is the phrase of its words. Neo4j’s default analyzer keeps such a name one token, which the whole name finds andexample modelsdoesn’t. drivine4j’sFullTextIndexSpecpicks another analyzer there; drivine-python doesn’t take one yet. - An index or a uniqueness constraint, a vector index’s HNSW index among them, is built with no parallel workers
(
max_parallel_maintenance_workers0), and the session’s own setting is put back after, whether the build passed or failed. A session that builds an index in parallel keeps a shared memory segment in/dev/shmfor as long as it lives, and the pool keeps it alive: in a container’s 64 MB, Docker’s default, enough of them leave too little for a later HNSW build, which asks for nearly all ofmaintenance_work_memat once and fails withcould not resize shared memory segment ... No space left on device. A large build takes longer for it. drivine4j closes the session after the build instead, and keeps its parallel workers; psycopg_pool would log a warning for each connection given back closed.

