Repository navigation
v0.3.0
The headline is the WAL change feed: GET /events?table=<name> streams
typed row changes straight from PostgreSQL's write-ahead log, with cursor
resume, alongside the existing NOTIFY channels (see the
Realtime tutorial and the
Realtime events guide). The conformance
target also moves from PostgREST v16.0 to v16.4.
Upgrading from 0.2. Two changes can break a setup that worked:
- Aggregate functions in
selectare now off by default, as in PostgREST
v16. Setdb_aggregates_enabled: true(or
PGRST_DB_AGGREGATES_ENABLED=true) to keep using them. Bier.CLI.run/2and twoBier.Embedfunctions changed shape. This only
matters if you call those modules directly.
One behavior change is worth knowing about as well: an SSE subscription now
ends when the JWT that opened it expires, instead of living on indefinitely.
Details for all three are under Changed below.
Added
db_aggregates_enabled(PostgRESTdb-aggregates-enabled,
PGRST_DB_AGGREGATES_ENABLED, defaultfalse): gates aggregate functions in
a request'sselect. When off, any aggregate — including one inside a spread
embed — is rejected with 400PGRST123, matching PostgREST v16. When on,
aggregates on a one-to-many or many-to-many spread are rejected with 400
PGRST127. Settable from the environment, the config file and — as
upstream'sdbSettingsNamesallows — the in-database config source.- Aggregates inside spread embeds now hoist the enclosing
GROUP BY, so
select=total:amount.sum(),...category(owner)groups by the spread's columns
instead of erroring or returning ungrouped rows. - WAL change feed on the events endpoint: with
events_publicationnaming an
operator-created publication,GET /events?table=<name>streams typed
INSERT/UPDATE/DELETE/TRUNCATE events with row images over SSE — no NOTIFY
payload cap, no triggers. Frames carry an LSN cursor (id:) and reconnects
resume viaLast-Event-IDwithin a bounded in-memory window; anything the
server can no longer replay is announced with an explicitbier:reset
frame, never silently skipped. Subscriptions require SELECT on the table
(column images are filtered per role) and a role the authenticator may
actually assume; tables with RLS refuse subscription in this release. Boot
fails fast (with remediation hints) unlesswal_level=logical, the
publication exists, and the role has REPLICATION. A response carrying a
table subscription also sendsConnection: closeover HTTP/1.1 (the WAL
stream can end at any time, unlike a NOTIFY-only response; the header is
malformed in HTTP/2 and is omitted there). An unknown table, a view,
materialized view or foreign table, and an unpublished, RLS-enabled,
unexposed, or unprivileged table all refuse with the same 404
(BIER003), so the endpoint cannot be used as an existence or privilege
oracle. (The refusals are byte-identical but not time-identical:
configuration-only refusals skip the database round trip the catalog
checks cost, a gap that reveals only configuration.) A
transaction overevents_max_tx_events, or over a fixed 64 MiB of decoded
column values, is dropped with atransaction_too_largereset. - WAL change feed: partitioned tables can be subscribed through a
publication createdWITH (publish_via_partition_root = true)(#140).
GET /events?table=orderson a partitionedordersstreams changes from
every partition, at any depth, named afterorders. PostgreSQL reports
them that way itself, resolved as of each change, soATTACHand
DETACH PARTITIONtake effect at their exact position in the stream.
The partitioned table's own grants, column grants and RLS flag decide the
subscription. Under that setting its leaf partitions are refused with
404 BIER003, because PostgreSQL never names them. Without the setting
it is the other way round: partitioned tables are refused and leaves stay
subscribable as ordinary tables. In general, a table is published to the feed
exactly whenpg_publication_tableslists it.
A cross-partitionUPDATEarrives asDELETEthenINSERT. PostgreSQL
does not publish aTRUNCATEof a single partition in this mode. That gap
cannot be announced per event, so it is documented and logged as a
warning when the feed starts. A second warning at feed start names every
partition whoseREPLICA IDENTITYdiffers from its partitioned table's.
oldandold_kindare labelled and shaped from the partitioned table's
identity, so such a mismatch silently produces wrongolddata: for
example, aDEFAULTpartition under aFULLparent reports
never-logged columns asnull. Both warnings only read the catalogs,
take no relation locks, and are skipped with a logged reason if they
fail, so they can neither block nor fail boot. GET /ready/walon the admin server reports on the WAL change feed alone:
200while it runs,503once it has been given up on,404when the
instance has noevents_publication;Bier.Health.wal_feed/1is the same
answer in code./readyis unchanged and still means "the API can serve",
so a stopped feed does not take a working instance out of rotation, while
operators can alert on, or routetable=subscriptions by, the feed itself
(#166).events_publicationis validated at boot: it must be a non-empty
identifier of at most 63 bytes with no quotes, backslashes, or null bytes.bier:is a reservedevent:prefix:events_channelsentries claiming
it are refused at boot, and atable=subscription naming such a table is
refused like any other unavailable table. Without the reservation a
channel or table could emit a frame a client reads as a control message.db_schemasis validated at boot: the list must be non-empty and no entry
may be blank. An empty list previously aborted the schema-cache load with an
opaqueFunctionClauseErrorbehind a PGRST002 log, and a blank entry booted
a working instance whose default schema silently resolved nothing. Both are
Bier-only rules — PostgREST's comma-separateddb-schemascannot express an
empty list — so they run at boot only and--dump-configstill prints
whatever it parsed (#143).jwt_role_claim_keyaccepts the pre-v16 leading-dot JSPath syntax again
(.roles.user_role,."https://x"[0],.roles[?(@ ^== "app_")]), as
PostgREST v16.2 (PostgREST#5171) does: a value the RFC 9535
parser rejects falls back to the old grammar — keys, quoted keys, indexes and
one trailing==/!=/^==/==^/*==string filter — and the role is the
first match. Such a value logs a deprecationWARNINGat boot (also written
to stderr by--dump-config) and dumps with every key quoted
(."roles"."user_role"). A value neither grammar accepts stays fatal.jwt-cache-max-entriescan be set from the in-database config source
(ALTER ROLE … SET pgrst.jwt_cache_max_entries), matching PostgREST v16.4
(PostgREST#5269), whosedbSettingsNamespreviously listed a
key no parser reads in its place.- PGRST200 ("Could not find a relationship…") errors now carry PostgREST's fuzzy
hint, which was previously alwaysnull. It is a suggestion computed off the
schema cache rather than an echo of the request's own!hint: a near-miss child
drawn from the origin's own relationships when the origin participates in any,
and a near-miss parent drawn from the relationships map's keys when it does not
(Error.hsL320-331). Both sit at fuzzyset's default 0.33 minimum score —
markedly more permissive than the 0.75 gate PGRST205's table hint uses — with
the exact-hit short-circuit and< 1.0guard reproduced, so an embed naming a
relation that really is related still yields no hint (cases 1527/1529/1530).
Changed
- Breaking: aggregate functions in
selectare now disabled by default.
They were previously always available; PostgREST v16 defaults
db-aggregates-enabledto off and answers 400PGRST123, and Bier now
matches. Setdb_aggregates_enabled: true(or
PGRST_DB_AGGREGATES_ENABLED=true) to restore the old behavior. - Breaking (API):
Bier.CLI.run/2performs the--readyhealth check
itself and returns a result map like every other command, instead of handing
the caller a{:ready, url}directive to probe. InBier.Embed,group_by
takes a fourth argument andbuild_row_selectreturns a 4-tuple carrying the
aggregate metadata. - SSE subscriptions are now bounded by their JWT's
exp(with the same 30s
skew allowance the request path uses) instead of living on indefinitely
after the token that authorized them expired. The[:bier, :events, :subscribe, :stop]span reports this as:reason:token_expired. BIER002's message and hint now mentiontable=alongsidechannel=.- Subscriptions are re-authorized centrally after a schema reload — one
query per distinct role over the union of that role's subscribed tables,
rather than one per subscriber — so a reload applies immediately without
queueing a checkout per subscriber against the connection pool. - The WAL ring buffer stores each table's column metadata once instead of on
every buffered entry. A DDL that changes a table's columns now invalidates
that table's buffered history, so a client resuming across the change gets
an announcedbier:resetrather than rows labelled with the wrong
columns. Last-Event-IDis validated more strictly: LSN halves must fit in 32
bits, signs are rejected, and oversized input is refused before parsing.
An unparseable cursor still just starts the stream at the live head.- A stream the server ends on its own now says why first, with a terminal
event: bier:closedframe (noid:) whosereasonisrevoked(the
role's privileges were revoked),token_expired(the JWT reached its
exp) orfeed_stopped(the WAL feed was given up on, below), instead of
closing silently. Without it a client could not tell any of these from a
network drop, andEventSourcereconnected into a refusal — any response
other than200 text/event-streamis fatal to it — and stopped for good.
Deliberately notbier:reset, which only ever means "history is gone"
(#150). - The WAL change feed runs under its own
Bier.Wal.Supervisor
(:rest_for_oneover the ring buffer and the consumer, with its own restart
budget of 5 in 30s) instead of directly under the instance supervisor.
Consumer crashes no longer spend the instance's budget — a fourth within
five seconds used to take the whole instance down, HTTP server included. A
ring-buffer crash now restarts the consumer with it, so subscribers get a
stream_restartedreset. Boot-time feed validation moved from
Bier.HttpServerStarterinto the new supervisor, still failing boot with
the same remediation messages; with the database down at boot it is now the
first step to fail, and logs the samePGRST002the schema-cache load
does (#150). - A feed that keeps crashing (a sixth restart within 30s) is given up on
alone, with the API still serving — and announced rather than silent: it is
logged at error level and emits the new[:bier, :wal, :feed, :stopped]
telemetry event, every live subscription with atable=in it (including a
mixedchannel=+table=one) ends withbier:closedfeed_stopped, and
newtable=subscriptions andLast-Event-IDresumes are refused with the
new503 BIER004until the instance is restarted.channel=streams are
unaffected, and the admin/readyendpoint does not reflect the feed
(#150) —/ready/waldoes (#166, under Added). - A schema reload revokes a live table subscription only on a confirmed
privilege loss. A role that was dropped (42704) still revokes; any other
database error during the re-check (a statement timeout, a cancelled query,
a failover) now keeps the subscription for the next reload to re-check,
instead of closing every subscriber of that role (#150).
Fixed
- A client resuming with
Last-Event-IDafter a consumer restart was told
bier:resethistory_evicted; it now getsstream_restarted, the same
reason the live stream announces. On resume,history_evictedis reserved
for a cursor from the current stream that a table's ring buffer has since
lost; it is also still pushed live for the tables of a transaction the ring
buffer was momentarily unable to record (#150). - A
Last-Event-IDresume whose ring buffer died mid-replay crashed the
request after its200was sent; it now degrades to abier:reset
stream_restarted(#150). - The WAL consumer discards a partially assembled transaction as soon as the
replication connection drops (and again on reconnect), instead of holding it
on its heap for the whole outage or backoff (#150). - A spread embed whose columns fed an aggregate leaked a raw PostgreSQL
42803(must appear in the GROUP BY clause) to the client. - A
selectshape a mutation could not render — an aggregate inside a to-many
spread (PGRST127), a filter on an unselected embed (PGRST108), a related
order on a to-many (PGRST118) — raised aMatchErrorand answered 500. The
mutation paths now return the same 400 the read path does. - Only PostgREST's five aggregate functions (
avg,count,max,min,
sum) are accepted inselect. Any other name parsed as an aggregate and
reached SQL as a function call, so?select=id.pg_sleep()invoked it once per
row; it is now a 400PGRST100select parse error, as upstream gives. --readydistinguishes an unparseable admin-server URL (invalid url) from a
refused connection, instead of collapsing every transport failure into
connection refused.--dump-configno longer comes back empty when the database is momentarily
out of connection slots: the in-database config read retries a checkout the
pool dropped as backpressure, up to the acquisition deadline. An endpoint
nothing is listening on still fails immediately, now naming the host and port.- Request text that is not valid UTF-8 — a query parameter whose percent-escape
decodes to invalid bytes (e.g.?channel=%e2%28%a1), or atext/csvbody
whose header row carries them with no escaping at all — no longer crashes the
error response it triggers: the stdlibJSONencoder rejects non-UTF-8
binaries outright, and an unknown channel/table/column echoes the client's own
(invalid) input back inmessage/details.Bier.ErrorPayload— the single
choke point every error body serializes through — now scrubs invalid byte
sequences, in keys and in nesteddetailsstructures alike, before encoding,
instead of letting the request answer a raw 500 (#142). - "Perhaps you meant" hints are no longer withheld for long names. A flat
64-byte cap on the name being matched bounded the cost of scoring it
against the schema cache, but it counted bytes where the score counts
characters, and was sized for the 0.75 gate of the table and function
hints: at the 0.33 gate of PGRST200's relationship hint, a multi-byte name
or one past 64 characters got no hint where PostgREST gives one. The bound
is now derived from the score itself, which cannot exceed
shorter / longer: a candidate that cannot reach the gate is skipped
without scoring, and a name past63 / gatecharacters (84 or 190) is
scored against nothing. No hint PostgREST would give is dropped (#163). - An empty bearer token (
Authorization: Bearerwith nothing after the
scheme) answers 401PGRST301again under Bandit 1.14.1 and later. Bandit
now strips trailing whitespace from HTTP/1 header values (RFC 9110 §5.5),
so the header arrives as a bareBearer, which Bier read as no token at
all and served as the anonymous role. ABearerscheme with no token is
now an empty token however it is spelled, as in PostgREST, whose
extractBearerAuthnever depended on the trailing space (case 1455). - A nested empty embed inside a spread (
...processes(process_costs())) now
answers 40042703like PostgREST, instead of silently contributing nothing.
generateSpreadSelectFields'sJsonEmbedbranch names one spread field per
embedded relation unconditionally, never consulting thersEmptyEmbedflag the
non-spread path computes, so the projection references a column the LATERAL
never projects. The nested empty spread spelling
(...processes(...process_costs())) takes the other branch and is unaffected,
still answering 200 (cases 11139/11140). Spread LATERALs are now named with
PostgREST's deterministic<parent>_<relation>_<depth>relAggAliasformula
(Plan.hsL541), which is what the42703message quotes back. - An empty embed (
rel()) whose relationship does not resolve now answers
400PGRST200, like any other embed, instead of 200 — or, nested in a
spread, a phantom-column42703. PostgREST resolves every embed before it
looks at the embed's select list (cases 11141–11144, #161). - An embed's internal table alias is now PostgREST's
<table>_<depth>, and a
many-to-many embed reads its bare table, so an unknown column inside an
embed names the same relation upstream's42703does
(column factories_1.banana does not exist) instead of a counter-based
name that changed with unrelated sibling embeds (cases 1531–1534, #162). - The in-database config read no longer overshoots its own acquisition
deadline. Two shapes escaped it. An endpoint that accepts the TCP connection
but never completes the Postgres handshake ran to ~15s against a 10s budget:
the retry loop gave up on time, but tearing down the wedged connection waited
on its handshake, capped only by the pool supervisor's 5s child shutdown. And
a server that completes the handshake and then stalls ran to ~60s, because
db_connection reads:timeoutand:checkout_retriesfrom the call options,
not from the pool's start options, so one query ran on the 15s default and
was retried three more times. The read now derives every bound from the same
budget, passes the remaining budget at the query call site, and tears the
pool down with:brutal_kill; both shapes finish in ~10-12s. The error also
leads with the time actually spent rather than the ~1s queue drop of the last
checkout (#149).
Conformance
spec/bumped tov16.0.0-suite.5, which adds the 39
spread/aggregate cases 11100–11138 and the four--readyhealth-check cases
1745–1748, then the seven cases the upstream v16.0 → v16.2 re-sync ranked —
db-aggregates-enabledvia the in-database config source (1749), the
resolved-empty spread projections (11139–11140), and PGRST200's fuzzy parent
hint (1527–1530) — taking the tree to 812 cases. Upstream's ownPINstays at
PostgREST v16.0; the one v16.2 drift the re-sync found (case 1711,
jwt-role-claim-keyvalidation) is recorded upstream, not folded. Cases 1771
and 11125 are recorded as deliberate divergences (#122, #138); 11125 pins
upstream's tolerance of an unbalanced trailing)inselect, which Bier
rejects with 400PGRST100.spec/bumped tov16.4.0-suite.2, which moves the upstream pin
from PostgREST v16.0 to v16.4 and takes the tree from 812 to 832 cases:
the deprecated JSPathjwt-role-claim-key(11700–11706, 11819–11821, with
1711 rewritten to a value neither grammar accepts),jwt-cache-max-entries
via the in-database source (11707), the root document of a mixed-case schema
(1690 — Bier already compared schema names as text rather than through an
unquoted::regnamespacecast, so it needed only its harness variant), the
unresolvable empty embeds (11141–11144) and the alias an embedded42703
names (1531–1534). All 827 active cases pass.