Skip to content

pg_crdt

Counters and text that several writers change independently and merge later, in plain Postgres, on any client.

pg_crdt is a SQL and PL/pgSQL extension for Postgres 16, 17 and 18. A CRDT is a value that several writers can change independently and merge later, in any order and any number of times, and still agree on the result. Version 0.0.1 has two types: the PN-Counter, a counter that goes up and down, where every writer keeps its own running totals, and collaborative text, a plain-text document that several people edit at once.

It works with any client, driver or API layer, needs no superuser and no C, and assumes no identity provider. Read the overview for what a CRDT gives you, and when a plain column is the better choice.

Merge in the statement that writes: update posts set likes = crdt.pn_merge(likes, $1) where id = $2. Never read the state, merge it in your application and write the result back. See Update safely.

Text documents are written through the ydoc_ functions, which lock the document. Sets, registers and maps are planned: see the overview.

For agents and other tools, the Markdown index links to plain-text versions of every page.