Copy a Postgres table or view
You have a table or a view in a PostgreSQL database of your own — a mirror of a ticketing system, a reporting view a job refreshes — and you want to ask Prism questions about it. This page connects it as a context stream that Prism copies on a schedule: one dated copy per run, kept for as long as you say, every question answered from the copy in Prism's own memory. Your database sees one statement per scheduled run and nothing between runs.
That is the right shape for a source that knows only "now" and whose views are expensive to evaluate. It is the wrong shape for a database that already holds its own history and is cheap to read: that one wants to be read in place, and reading a Postgres in place is not something this release does. If your table carries history and you would rather not hold a copy, say so before connecting it; the copy will still work, it will just be a copy.
1. What to ask your DBA for
| What | Detail |
|---|---|
| One view (or table) | Prism reads exactly one, through the SELECT you write into the recipe, and what that SELECT returns is the whole of what Prism ever sees. Cut a view if the table has columns you would rather not hand over: the view is your access control |
| A read-only login | One service login for the appliance, never one per reader. Give it USAGE on the schema and SELECT on the one view, and nothing else. The grant is the control; the session Prism opens is read-only as well, but that is defence in depth, not the fence |
| A role, if you separate them | If the login should assume a role for the read (SET ROLE), you need its name and a grant of that role to the login. The recipe takes it as a connection value — see the session settings below. If not, the login's own privileges are what the read runs under |
| The network path | The appliance's pods have to reach the database's host and port. A pg_hba.conf rule that admits the appliance's address for this login, over TLS, is the usual shape |
| TLS | Whether the server presents a certificate, and whether it chains to a root the appliance carries. See sslmode below — the default encrypts and does not verify, which is right for a private CA and wrong for nothing |
The statement_timeout you will tolerate | The one statement a copy runs is bounded by a ceiling you set in the recipe, and the ceiling covers the whole of the copy — every fetch from the cursor, not each on its own. Ask how long the view takes to evaluate cold, and set the ceiling above that with room: a server-side cursor evaluates the view without parallel workers, so it can take several times longer than the same SELECT run whole on a server that parallelises it |
idle_in_transaction_session_timeout for this login | Prism holds one read-only transaction open for the whole copy, and between two fetches it is writing the previous chunk into its own memory — idle, from the server's side. If the login's (or the cluster's) idle_in_transaction_session_timeout is shorter than that gap, the server ends the session mid-copy and the copy is abandoned, by name. Ask for it to be set for this login above a few seconds, or lower the recipe's fetch_size (page_size on a keyset or offset stream), which shortens the gaps between fetches. The gap between two streams is Prism's own work between them, and only the timeout setting covers it |
transaction_timeout for this login (Postgres 17 and later) | A cap on how long one transaction may stay open, busy or not. Prism holds one transaction across the streams of a run, so a cap shorter than the run ends it at whichever stream it reaches, and that stream's copy is not kept; a smaller fetch_size does not help. Ask for it to be unset (0) for this login, or set above the longest run you expect. Prism reads it when the session opens, and whenever one is set the run log carries a WARNING: line naming it before the copy starts |
2. The five connection values
No chart value holds any of these. You enter them in Admin → Context streams, on the form you register the source with (section 5): it shows one field for each parameter the manifest declares. They are values about your database, and the appliance keeps them beside the source rather than in configuration, so the probe that switches a source on is a probe of the connection that will copy.
Enter them right the first time. Once the source is registered, none of the five can be changed: they are where the source is and who it signs in as, and the probe verdict is about them. Edit parameters… on the source's page does not offer them, and an edit of the manifest cannot change them. Changing one is deleting the source and registering it again.
| Value | What it is |
|---|---|
db_host, db_port | The server. Port 5432 is the default when you leave it empty |
db_name | The database the session is opened to. Required: a Postgres session is opened to one database and there is no "the login's default" |
db_schema | The schema your view lives in, spelled exactly as it was created — Sales is not sales. It becomes the session's search_path, quoted, and the probe checks the session actually landed there (see section 5) |
db_user | The login. Configuration, not a secret: it appears in the server's log on every failed sign-in, and somebody has to be able to read it to fix one |
The password is stored sealed; it is never a connection value. Registering from the recipe, you enter it on the same form. Registering a manifest you pasted, you enter it after registering, on the source's Credential tab.
The session settings, and changing them after you register
The lines in this table are not the address of your database but how Prism
sets up its session once it is signed in. The three in the recipe are marked
YOURS, and these lines — with the connection parameter role_parameter names —
are the only part of the connection you can change after the source is
registered.
| Line | What it does | The recipe's value |
|---|---|---|
sslmode | The TLS posture of the connection: one of disable, allow, prefer, require, verify-ca or verify-full, and require when the line is left out. They carry PostgreSQL's own meanings: require encrypts and does not verify the server's certificate, which is the right posture for a private-CA or self-signed server; this release carries no root certificate for a source's server, so verify-ca and verify-full cannot pass and are refused before anything is dialled. disable is clear text, and so is allow — even against a server that does offer TLS, because it tries an unencrypted connection first and only upgrades if the server refuses one. prefer is clear text against a server that does not offer TLS: it connects unencrypted rather than fail, and it retries in clear text when a server offers TLS but the handshake fails. Against a server that does not offer TLS at all, require fails rather than falling back to clear text. Whichever you choose, the probe reports whether the session it opened was actually encrypted, and the source's Overview shows it | require |
statement_timeout | An ISO 8601 duration, such as PT10M or PT1H. The ceiling on the one statement a copy runs, over the whole copy (section 1 says why a cursor needs more room than your console). A view that cannot be copied inside it is not copied at all. Deleting the line removes the ceiling on the copy as a whole. Two bounds still apply: a statement_timeout your DBA set on the login or the cluster, and Prism's own bound on each fetch. A single fetch that returns nothing for an hour ends the copy with a message that says so (ingest.engine.databaseFetchTimeoutSeconds). A copy that keeps delivering rows is never stopped by that bound, however long it runs | PT10M — ten minutes |
read_only_role | On Postgres this line does nothing. It records the name of a role you might grant, and Prism issues no SET ROLE for it: the session runs with the login's own privileges, whatever it says. It is not a requirement to create a role of that name | prism_reader |
role_parameter | Not in the recipe. If the session should assume a role, this is the line that does it: it names a connection parameter holding the role, and the session issues SET ROLE to it — the probe then signs in as that role and reports it. It replaces read_only_role; the two cannot both be set | — |
How to change one after registering. Edit the source's manifest: open the
source in Admin → Context streams, change the line on its Manifest tab
and press Save (Change a context stream's manifest),
or send the edited document to PUT /api/admin/sources/<id>/manifest. Three
things happen together:
- the stored password is kept, so there is nothing to re-enter — if one
was stored. A password whose probe fails is never kept, and under
sslmode: requirea server with no TLS fails every probe, so on that path nothing was stored: make the edit, then enter the password again, which probes it under the new settings; - the probe verdict is withdrawn and the source goes back to registered, because that verdict was about the old settings;
- the next probe runs under the new settings. Press Test, then approve and enable it again.
To have the session assume a role, make one edit: delete the read_only_role
line, add role_parameter: db_role, and declare db_role under
parameters. Give it the role's name either as the declaration's default
(db_role: {type: string, default: <your role>}), which is what the page can
send, or through the API as "parameters": {"db_role": "<your role>"} beside
the manifest. That body key takes only a parameter a session setting names.
What cannot be changed that way. The server (db_host, db_port), the
database, the schema, the login, and the stored credential's name are what the
probe verified the password against. An edit that changes any of them is
refused and names the line; changing one is deleting the source and
registering it again, which also means entering the password again.
Before you register, then, the three questions to settle with your DBA are the ones this table raises: does the server offer TLS, how long does the view take to evaluate cold, and should the read run under a role. None of them is final — but a probe under the wrong answer fails, and it is quicker to start right.
3. What the recipe needs your view to have
-
A key. One column, or a combination, that identifies a row uniquely within one copy. In the worked example it is the ticket number. The copy is one row per key per day.
Uniqueness is checked against your rows, not taken on trust, and a copy that fails it is refused. Two rows sharing a key cannot both be stored — the second would overwrite the first — so a copy that read 100 rows and can store only 98 is refused with the key's columns and what to do, rather than landing 98 and reporting 100. The reason shown on the page is kept to 160 characters; the log on the stream's Runs tab has the whole sentence, with both counts and how many rows repeat a key. The previous copy stays in place and that table reads as behind on its own, while the source's other tables keep the ages of their own copies; this is the safe direction: a short copy that reports itself complete makes every figure drawn from it quietly low.
Admin → Context streams shows the refusal. The stream is marked refresh failed in the list, and its pane says when the last refresh failed and why, until a refresh completes. Its Runs tab has the refused copy with its full error and log (How each copy went). The self test shows it too. Since 0.16.0 the self test's CONTEXT STREAMS section has a line for every source in your registry — unless the registry itself could not be read, which its
source registryline says — and a switched-on source with a failure recorded since its last completed run says so there, with the first 160 characters of the reason. This refusal is a sentence Prism composed, so it is shown as written; a raw driver error is shown as its type alone, on the self test and on the Context streams page alike. For the whole of what is recorded, read theingestblock of the diagnostic bundle — download it from the self test page — under this source's name, aslast_failure.error.Confirm it before you register, with the key your recipe declares:
SELECT count(*), count(DISTINCT (<your key columns>)) FROM <your view>;If the two numbers differ, the key is not a key for this result set. Do not simply pick a column that looks unique: a nearly unique key is the case this refusal exists for, because it loses a handful of rows out of thousands and nothing else would show it.
Before the stream has ever run, either fix works — make the
SELECTreturn one row per key (GROUP BY,DISTINCT ON, or a filter), or declare a wider key that is genuinely unique. Note that "ever run" is the boundary, not "ever copied successfully": the table is created on the first attempt, before any rows land, so a run that was refused has already fixed the key in place.After that, prefer the
SELECT. The key you declare becomes the copy table's primary key, and it is set when that table is created; adding a column to the key in your recipe does not change the table that already exists. Every run after that is refused, and nothing is copied until you put the old key back or give the stream a newtable. If you do want a wider key on a stream that has already run, the table has to be recreated, which discards the dated copies it holds: ask us before doing it, because for most views the one-row- per-keySELECTis the same outcome without losing the history. -
An event time, a timestamp the trends group by — when the ticket was opened, in the example. If the column is a
timestampwithout time zone, say in the recipe which zone it is written in (naive_timezone); atimestamptzneeds nothing. -
The person, by the identifier your directory uses — an employee id, in the example. This is what lets a question about a ticket become a question about a person or a team. Without it the copy is still a copy; it just does not correlate.
-
Everything else is yours to include or leave out.
Postgres folds an unquoted column name to lower case, and so does Prism. If
your view has a mixed-case column, quote it in the recipe's SELECT and alias
it in lower case; a name that does not match the result set exactly is refused
by name before a row is read, rather than silently becoming an empty column.
What a column lands as. A numeric keeps its digits, a timestamptz its
instant, a date its date, json/jsonb its text. Into a string column: a
uuid lands as its text, an array or a composite as one JSON document (nested
to any depth), a bytea as Postgres's hex text (\x0102), a range as
Postgres's own form ([1,10)), a bit string as its bits, an inet as its
text. An interval lands as an ISO 8601 duration, with one caveat: the driver
flattens months to thirty days before Prism sees the value, so 1 month 15 days arrives as P45D — cast the column to text in the view if the months
matter. Anything else, cast to text in the SELECT and it lands as that text.
If your server's encoding is SQL_ASCII
Ask your DBA, or run SHOW server_encoding; as the service account. Most
servers answer UTF8, and nothing in this section applies to them.
A SQL_ASCII server stores whatever bytes a writer sends and never checks
them. Prism's Postgres client asks for text in UTF-8, so the server
checks each value on the way out. Before 0.15.1, one value that was not valid
UTF-8 made the server refuse the whole statement with 22021, and the stream
copied nothing. The usual cause is an emoji written by a Java or ODBC
application as CESU-8. Your own SQL client usually shows the same row without
complaint, because it asks for a different encoding and nothing is checked.
On a SQL_ASCII server, Prism now reads the text columns as bytes and decodes
them itself, one value at a time:
- valid UTF-8 is kept exactly as it is;
- an emoji written as CESU-8 becomes the character it stands for;
- any other invalid byte becomes
�(U+FFFD). The value's other characters are kept.
The copy completes. When any value in a stream needed one of the last two steps, the run log has one line for that stream, like this:
changes: 3 text value(s) repaired (CESU-8 surrogate pairs rejoined), 1 with invalid bytes replaced by U+FFFD — …
Limits: when the stream is refused instead
In three cases, repairing or replacing a value would give a wrong copy, so the stream is refused instead. Each refusal names the column and stops only its own stream. The source's other streams still copy.
| What holds the bad bytes | What happens | What to do |
|---|---|---|
The key of a keyset-paged stream, on the last row of a page | Refused. The next page starts from that key, and the repaired key is not what your server holds, so starting from it could skip rows. A repaired key in the middle of a page copies normally. | Use paginate: none, the recipe's default, which reads the whole view in one pass. Or key the stream on a column that holds no such text. |
A column declared identity:, when the value could only be read by replacing bytes | Refused. Two different people, such as employee ids E + one stray byte and E + another, would both become E� and be treated as one. The directory crosswalk refuses such a pull the same way: it keeps the identities it pulled last time, and uses them until the value is repaired. A CESU-8 emoji is repaired exactly and is never refused. | Repair the value at the source. |
| The key, where two keys become the same text after repair, for example one emoji stored as CESU-8 and the same emoji as valid UTF-8 | Refused because the key is no longer unique. The refusal says the key is not unique and to return one row per key from the SELECT; here the SELECT already does, and it is the repair that made two keys equal. | Repair one of the two values at the source. |
The source is never changed. To read your server's own message about the
value, see
When the code is not in this list. In
that session a SELECT stops at the first value that is not valid UTF-8 in
any column it returns, including a value the copy repairs, so the message can
be about a different value from the one refused. The message names the bytes,
not the column.
What this does not cover. On a SQL_ASCII server this applies only to
columns of these types: text, varchar, char(n), name, json, jsonb,
xml, citext, and domains over them. A column of any other type that holds
invalid bytes, such as an array, a composite, an enum or a tsvector, is still
refused with 22021. Cast it to text
in the view's SELECT and it is read like any other text column. A WIN1252
server has the same kind of problem with a different code. Five byte values
have no character in that encoding, and a value that holds one of them is
refused with 22P05. Prism does not repair that case. Fix the value at the
source, or leave the column out of the SELECT.
4. The worked example, and which parts are yours
Open the recipe from Add a context stream — it is Service desk (Postgres copy). Every line you have to decide about carries one of three markers, in a comment on the line itself:
- STRUCTURAL — Prism needs this. Delete it and something stops working, and the marker says what.
- YOURS — yours to decide: the view, every column's name as your view spells it, the schedule, how long to keep copies, the TLS posture, the ceiling.
- OURS — there are none in this recipe. The example is fictional; every line is either Prism's or yours.
The SELECT is the heart of it. Replace the view name and the column names
with your own, keep the aliases the recipe's from: lines expect (or change
both together), and keep it a plain SELECT — no writes, no semicolon; the
recipe is refused otherwise.
How the copy is taken is set by one line, and the default is the one to keep:
paginate: {type: none, fetch_size: 1000}
none means one statement, streamed through a server-side cursor inside one
read-only transaction. A view over a dozen joins is evaluated once per copy
however many rows it returns. The other two strategies the recipe can name,
keyset and offset paging, re-run the statement once per page; measured on a
real Postgres that is one evaluation of the view against eleven for a hundred
rows at ten a page. They exist for a plain table with a unique key that is
cheaper to page than to stream, and for nothing else.
What one copy date promises, and when it promises less. When a source has
several views, they are all read inside one read-only REPEATABLE READ
transaction, so every view in a dated copy shows your database as it was at the
same instant, for as long as that transaction lasts. Three things end it before
the run does: a view refused for a fault on the source's session (it did not
finish inside the statement timeout, say), a dropped connection that Prism
retries before a view has returned any rows, and a read whose cursor could not
be closed (troubleshooting.md). The views copied after
that are read from a new transaction a moment later, so a run can finish with
every view copied and still not be one instant. Their rows carry the same
as_of as everything else, so nothing in the data shows it. The run's log
does. When anything had already been read in the earlier session, each of the
three writes a WARNING ending "at a later instant under the same as_of" and
naming the view where the session changed. Open the copy on the source's
Runs tab, where warnings show by default. It matters only if
you correlate two views within one dated copy.
What is never split is a single view: each view's rows come from one transaction, however many pages the copy takes, refusal or no refusal.
While a copy runs, a reload of a table it has read waits for the copy.
That one transaction holds a read lock on every table and view the copy has
read so far, and on the tables under each view, until the whole copy ends,
not only until that view is done. On any of those tables, a TRUNCATE, a
VACUUM FULL or a REFRESH MATERIALIZED VIEW without CONCURRENTLY waits
until the copy finishes. While it waits, every new query
on that table queues behind it, your own readers' included. How long it waits
is how long the copy takes: each copy on the source's
Runs tab shows how long it took. Three ways to keep a reload
from meeting a copy:
- Schedule the copy outside your reload window. Set the recipe's
schedule(cron, UTC) so a copy has finished before the reload starts. - Give the reload's session a
lock_timeout. WithSET lock_timeout = '1s'before theTRUNCATE, a reload that meets a copy fails after a second withcanceling statement due to lock timeoutinstead of queueing your readers. Retry it after the copy. - Reload with
DELETEandINSERTin one transaction instead ofTRUNCATE. Neither conflicts with the copy's read lock, so the reload commits straight away, and the copy still reads the table as it was when the copy began.REFRESH MATERIALIZED VIEW CONCURRENTLYdoes not wait for the copy either.
A reload that truncates several tables in one transaction can deadlock with
a copy instead of waiting. Suppose it truncates a table the copy has not
reached yet, and then one the copy has already read. The reload now holds the
first table and waits for the copy. When the copy reaches the first table, it
waits for the reload. Postgres ends one of the two, once a wait has lasted
deadlock_timeout (one second by default). Which one depends on which side
started waiting first, and how long before the other:
- If the reload is ended, it gets
deadlock detectedand is rolled back. Your tables are as they were, and the reload has to be run again. - If the copy's read is ended, the reload commits. Prism's run stops at
that view rather than read it from a new transaction at a later instant.
The views already copied keep today's copy. That view and every view after
it keep their previous copy, each under its own date. The run fails, naming
the deadlock (
40P01), and the next run copies them.
Two ways to stop it, each measured on Postgres 16. A lock_timeout of a
second, as in the list above, is not one of them: when the copy started
waiting first, the copy's read was still the one ended.
- Take the reload's locks up front. Start the reload's transaction with
LOCK TABLE <each table it truncates> IN ACCESS EXCLUSIVE MODE NOWAIT. If the copy holds any of them, the reload fails at once withcould not obtain lock, and the copy finishes whole. Retry the reload after the copy. - Reload with
DELETEandINSERT, as above, which takes no lock the copy conflicts with.
On a hot standby, a change on the primary can end the copy. When Prism copies from a hot standby, replaying some of your primary's changes conflicts with the copy, and the standby ends the copy's read. Depending on where the copy was, either the run stops at the view it was reading, as for a deadlock's copy side above, or the session is closed: then that view, or the next, keeps its previous copy, the views after it are read at a later instant under the same date, and the run fails. A read ended before anything of the copy was read is read again.
Copying from the primary instead takes the copy off the standby, and the
sections above then apply. The lock-based ways above, a lock_timeout and
LOCK TABLE … NOWAIT, act on the server the reload runs on, so they help only
when the copy reads from that server too: the primary holds none of a standby
copy's locks.
A TRUNCATE between two views of one copy makes Prism read the later view
again. A table the copy has not reached yet is not locked, so a TRUNCATE
and reload on it goes ahead. Postgres does not keep a truncated table's old
rows for a transaction that began earlier, so when the copy then reads that
table, or a view over it, it finds nothing. If only one partition of a
partitioned table was reloaded, it finds only the other partitions' rows.
After reading each view, the copy checks whether a table under it was given
new storage, or was replaced by another table, since the copy began. If one
was, nothing of that read is kept. The run's log says "stream: table was
rewritten or reloaded while it was being read", and the view is read again in
a new transaction. That view, and every view after it, is then copied at a
later moment under the same day. If the table is reloaded again during that
second read, the view keeps its previous copy, and Admin → Context
streams says why under Datasets
(Know when a context stream falls behind). That reason
says how many tables or indexes were reloaded. The run's log names them, in a
warning that says "nothing landed". Read it on Admin → Context streams:
open the stream, then its Runs tab
(How each copy went: the Runs tab). Runs are pruned, so the
names do not stay there for ever. The run does not fail. Reloading with DELETE and INSERT avoids the second read; a
lock_timeout does not, because there is no lock for the reload to meet.
A copy can land without the check. The check needs the copy's connection. If that connection ends after the read (for example, the server stops answering when the copy closes its cursor) or the check itself fails, the view is read again in the same way. If the check cannot be made on that second read either, the second read is kept, because a server that always behaves this way would otherwise never update that view. It landed without a reload check: if a table under the view was being reloaded when that read began, the copy can be short. The run's entry on the Runs tab shows a warning that the view's stream "landed without a reload check", and the line that ends the run's log says the same beside that stream's row count. The view's row under Datasets on Admin → Context streams says so too, until its next copy that the check could make, and so does an answer whose figures come from that copy. If that day's figures for the view look short, look there.
What the check costs. One query after each read of a view, inside the
copy's own transaction. It makes two catalogue reads: pg_locks for the
copy's own session, joined to pg_class, and pg_relation_filenode() for
each table found there. The check takes no lock on your tables, and needs no
grant beyond the login's own. A VACUUM FULL of a table before the copy reads
it gives that table new storage too, with every row kept. The check cannot
tell the two apart, so it costs one more read of that view.
schedule is a cron expression in UTC; keep is how long copies are held
(P90D is ninety days). A copy of N rows taken daily and kept ninety days is
about 90 N rows in Prism's memory; Limits sizes it.
How a question reads the copies is set by two lines you should keep. The
table holds every copy Prism has taken, one row per ticket per copy, so a
count over the whole table would count each ticket once per day it was
copied: ten tickets copied on two days would answer twenty, and a window on
the ticket's own date would not remove the second copy, because both copies
carry the same date. So the recipe's model declares is_latest_snapshot,
true for the rows of the most recent copy, and applies it by default:
default_filters:
- is_latest_snapshot: true
Every question reads the latest copy unless it says otherwise, and "how many
tickets were opened last week" is the latest copy's rows opened last week,
each ticket once. A question that genuinely means between copies — did the
open backlog grow since last Monday's copy — names the field in its own
filters (is_latest_snapshot: {is_null: false}) and groups by as_of;
naming the field is what lifts the default, and grouping by as_of alone does
not. The field's subquery reads {{ table }}, the table the dataset is read
from, so renaming the stream's table and the dataset's source: is enough.
A second copy from another database can be given tables of its own when you
register it, as for a Snowflake copy
(Connect a second Snowflake account).
Both fields carry role: copy_date. It marks a field whose filters choose
which copies a figure reads: the copy's date, or the latest-copy flag. When a
figure is windowed on as_of, Prism uses those fields to check whether any
copy the figure reads is dated inside the window. If none is, the figure is
withheld instead of given as 0. If you rename is_latest_snapshot, keep the
role on it. The role goes on as_of and on one boolean field per dataset,
the latest-copy flag. The manifest is refused if it puts the role on any
other date or timestamp field, or on a second boolean. Here Prism stamps
as_of on each copy itself.
Fields named as_of and is_latest_snapshot are read this way whether marked
or not.
Link fields: a question that crosses two of your views
When your source copies two related views, for example changes and the
incidents they caused, through a third view that links them, a question such
as "the changes that caused an incident last quarter" crosses two datasets.
Prism answers it from one dataset with a link field: a true-or-false field
whose sql: asks whether the row has a linked row in another stream of the
same source.
fields:
- name: caused_incidents # YOURS
type: boolean
description: true when at least one incident names this change as its cause
sql: >-
EXISTS (SELECT 1 FROM {{ table: change_links }} l
WHERE l.change_number = {{ table }}.number
AND l.as_of = (SELECT MAX(as_of) FROM {{ table: change_links }}))
{{ table: <stream> }}is the table the named stream of this same document fills, and{{ table }}is the dataset's own table. Both follow the copy, so a second copy registered with tables of its own reads its own linked rows.- A link field never counts a row twice, however many links it has, so the dataset's figures mean what they meant before. A question then filters or groups by it like any other field.
- It is allowed only in a field's
sql:, on a source that copies rows; aquery-throughsource copies none. - The linked stream's table keeps every copy that
keepholds, so compare itsas_ofwith its newest, as the example does. Without that, a link removed at the source still counts until its copy ages out.
Viewers restricted to their reporting line are never answered from a source
that declares a link field: every dataset of it is refused, whatever the question
asks, and it is left out of what they are shown. Its other readers are
unaffected. A link field's value is worked out from the linked rows, which are
not limited to the viewer's line: whether one of their changes caused an
incident can turn on an incident in someone else's line.
restricted_viewers: allow has no effect on a link field in this release, and
the organizational context stream may not declare one.
What is gated is a link you DECLARE with {{ table: <stream> }}. SQL you write
by hand that reads another stream's table, in a source: or in a field, is
your own definition of the dataset and is not checked.
5. Register it, and what the probe does and does not prove
Sign in as a super admin and open Admin → Context streams. Pick the recipe,
open Review the manifest and replace the document with yours. Enter the
five connection values and the password, and press Register. Prism
registers the source, then probes the connection with the password before
storing it; a password whose probe fails is not stored. Test on the
source's page probes it again, and also runs each stream's SELECT (below).
If you wrote the manifest yourself, open it with Paste a manifest… instead. Once the form has read the manifest, it shows a field for each connection parameter the manifest declares; a required one left blank is refused by name, and nothing is registered. This form has no password field: after registering, enter the password on the source's Credential tab and press Save and test.
Then approve the source, and only then enable it — enable is refused
from probed.
A passing probe means three things and no more:
- the server was reachable, on the TLS posture the recipe asks for;
- the credential was not rejected;
- the session Prism got is the one it asked for — the database you named, and the schema you named.
The third is worth its own sentence, because Postgres does not refuse a
search_path naming a schema that does not exist, or one your login cannot
see. It accepts the setting and quietly resolves past it, and every real
statement then fails to find your view. So Prism reads the session's schema
back and refuses on your behalf: a probe that says the schema resolved to
nothing means the schema is not there for this login, or the login (or the
role it assumes) has no USAGE on it.
The probe's encryption reading is about Prism's own connection. The
source's Overview says whether the connection Prism opened was encrypted,
because sslmode is editable on a registered source and two of its values are
clear text. It is read on Prism's side of the wire, so behind a connection
pooler — PgBouncer, pgpool, RDS Proxy — it describes Prism's link to the
pooler, and says nothing about the pooler's own link to the database. Where
you connect through one, the posture that matters for the second hop is
configured on the pooler and is yours to check.
Test on the source's page also runs each stream's own SELECT, returning no
rows. Entering the password checks only the connection, and the Overview then
says the streams are not yet tested. A view that does not exist, a column
it has not got, or a grant the login lacks is named with the stream and the
database's code, first on the source's Overview under Stream queries. It
does not stop the source being enabled: the other streams copy, and that stream
is refused at every copy until you fix its SELECT and press Test again. While
a stream is refused, each copy of the source reports failed and the source's
last completed copy stays where it was, though each table's freshness still
moves with its own stream's copy.
A key that is not unique, or a value the copy cannot convert, is found by the first copy, which refuses by name, never with an empty copy.
6. Verify it — with your questions, against your figures
Prism ships three example questions on the recipe; they are written for the fictional example and you should replace them with yours. Good ones are the ones where you already know the number: how many tickets were opened last week, against your own report for the same week; how many were resolved last month by group, against your service desk's own view. Ask them on the verification screen and mark each correct, wrong or skipped. Only a question you have marked correct earns the badge a reader sees beside an answer.
To ask about a person by name, such as "how many tickets is <name>
assigned", Prism looks the name up in your people roster and uses the
identifier this stream records them under. A kind of identifier your roster
marks hidden is never given out that way, to any viewer. So if this stream
is keyed only by employee ID and your roster hides the employee ID, a person's
tickets can't be reached from their name. To allow it, show that column in the
roster.
7. One current copy instead of a dated one
A snapshot keeps a dated copy of the whole view on every run. That is right
when the trend over copies is the point. It is wasteful for a large view whose
history nobody wants as a dated series. For such a view, declare the stream
incremental.mode: keyset under kind: mirror. The table then holds one row
per key, and each run copies only the rows that changed.
kind: mirror
# …
ingest:
streams:
- name: change_rows
table: change_current
query:
sql: >-
SELECT id, state, assignment_group, updated_on
FROM your_change_view
paginate: {type: none, fetch_size: 5000}
incremental:
mode: keyset
cursor: [updated_on, id] # STRUCTURAL: the version column, then a unique tie-breaker
initial_from: P12M # YOURS: optional, how far back a full read copies
reconcile:
schedule: "0 2 * * 0" # YOURS: how often a run re-reads every row
grace: P7D # YOURS: how long a vanished key is kept, marked absent
columns:
- {name: id, from: id, type: string, primary_key: true, nullable: false}
- {name: updated_on, from: updated_on, type: timestamp, nullable: false}
# …your other columns
Every dataset over the table exposes source_present as a boolean field.
Prism reads the table through it, so a key your view stopped returning counts
in no answer during the grace period.
Before you turn it on, ask the view's owner three questions. Prism cannot check the answers:
- Does the version column move on every insert and update, and never go backwards? A reload that resets it, or a value that repeats, hides rows from every run until the next reconcile.
- Is the tie-breaker never null, stable for the life of the record, and
unique per row of the view, after any
DISTINCTand joins? Prism refuses a run that returns a key twice. It cannot see a key that changes. - Does the bounded query reach an index? Run
EXPLAINonSELECT * FROM your_change_view WHERE (updated_on, id) > (…)on your server. If the predicate does not reach an index on the base table, every run still evaluates the whole view on your server, and the saving is only on Prism's side.
What the reconcile schedule bounds: until the next reconcile, a run cannot see a change that did not move the version above the stored position. That covers an edit to a joined lookup table, a row that left the view's filter, and a row whose version was stamped before an earlier run but committed after it (a long transaction on your server). A weekly reconcile means such a change can be up to a week old in answers. Choose the schedule for how stale those may be.
What Prism refuses when you register or apply the document:
- a cursor that is not the version column first and the primary key last (the key columns in any order); a primary key that contains the version column;
- a cursor column that is not declared
nullable: false; - an
initial_fromthat is neither a duration nor a date, or one on a version column that is not declareddateortimestamp; - a second stream writing the same table;
- a column named
source_row_hash,source_presentorabsent_sinceon any stream of the document, keyset or not: Prism adds those to a keyset table; - a dataset whose
sourceis a SELECT that reads the table, rather than the table itself.
What the first run refuses before it writes anything, stopping the whole
source (not only this stream): a table that another kind of stream left behind,
either keyed differently, holding rows with no source_present column, or
empty but not shaped as this stream's (a NOT NULL column the stream may leave
empty, or a column declared as another type than the stream declares it). Give the keyset stream a table name of its own. Reusing the snapshot's table would
otherwise cost you its copy.
What a run refuses instead of copying short:
- a NULL in a cursor column anywhere in the view;
- a key the view returns twice;
- a view that returns no rows while the copy still holds some;
- a reconcile that would mark more than half the copy deleted. A source read
while it was half reloaded looks exactly like that. So that reconcile marks
nothing deleted. It still copies the rows it read, the hourly runs carry
on, and the stream shows one failed run naming the counts. The next
scheduled reconcile tries again. The share is yours:
incremental.reconcile.max_absent, a fraction up to 1, default 0.5. If the deletes are real (a date filter you moved on purpose, a mass cleanup), raise it or set it to 1, and the next run reads the view whole and marks them. That is a manifest edit: see Change a context stream's manifest. If you narrow the SELECT on purpose, raisemax_absentin the same edit. What that reconcile did read, it copied as read, including values a lookup reloaded at the same moment got wrong; the next full read corrects them.
A refusal in a run stops that stream only, and its siblings still copy. Its table and position stay where they were, except after a withheld reconcile, which keeps the rows it read, as described above.
How far back the copy starts
Without initial_from, the first run copies every row of the view. On a view
with years of history, that first copy is large. incremental.initial_from
sets how far back a full read goes. A full read is the first copy and every
reconcile. It takes one of two forms:
- A duration, such as
P12M, counted back from each full read. Prism counts a month as 30 days and a year as 365. - A date, such as
2025-01-01.
A full read then copies only the rows whose version column is on or after
that day. The version column is the first column of cursor, and it must be
declared date or timestamp. A run between reconciles has no such bound. It
copies every row whose version moved above the last position, however old the
row is.
Use initial_from rather than a date filter in the SELECT. With a filter such
as WHERE updated_on >= now() - interval '12 months', each reconcile treats a
row that aged past the filter as a row that left the view, and marks it
absent.
A row that ages past the bound is kept. A full read does not read it again and does not mark it absent. So a row deleted at the source after it fell before the bound stays in the copy.
Answers say where the copy starts. Each answer from this stream carries
copy_from, the day the copy starts and the column it is on. The stream's
coverage in the source listing carries the same day. The answer, its
provenance panel and its exports say where the copy starts. A figure from
this stream is never called complete in these cases:
- The question's period starts on or before that day. Rows from before it may be missing.
- The figure is windowed on a time field other than the version column. A row in the period can have an older version, and then the copy never read it.
- The figure counts the whole copy whatever the window (
windowed: false).
A person with no rows is counted as a zero only from the day after
copy_from, and only for a figure windowed on the version column.
Bounds Prism refuses. Prism refuses a duration shorter than a day, such
as P0D or PT12H. When you save the manifest, Prism also refuses a date
more than a day after today (UTC). Either one would copy almost nothing. A
past date is never refused. A very old date such as 0001-01-01
copies every row, the same as no bound. Answers still treat it as a bound,
so remove initial_from instead.
Changing the bound. Changing or removing initial_from makes the next run
a full read. A wider bound copies the older rows. A narrower bound removes
nothing, and the rows already copied stay. To make the change, see Change a
context stream's manifest.
If something is wrong
- The copy loads nothing and the job is still running — see A source loads nothing, writes no error, and its job is still running. From 0.16.0, wait for the bound: most stalled copies then stop with a line saying what stopped them.
- A stream is refused: a row has no value in a column — a view returned
a row with no value in a key or a
nullable: falsecolumn. Filter those rows out (WHERE col IS NOT NULL) or give them a value (COALESCE) in the stream's SQL. A value that does not fit its column (too long, out of range) is refused the same way, naming the SQLSTATE. Either way only that stream is refused, and the other streams still copy. - A stream is refused: a column has a value that does not read as its
declared type — a value in a
number,dateortimestampcolumn would have landed as NULL or as a different number. Examples:n/ain anumbercolumn, anintervalin anumbercolumn, and9007199254740993as text in anumbercolumn. The message names the column and never the value. Cast the column in the stream's SQL, such ascol::numeric, or declare itstring. - The probe says
28P01or28000— the password, the login name, or apg_hba.confrule that does not admit this login from the appliance's address. - The probe says
3D000— the database you named does not exist for this login. - A copy refuses with
25P04, or the run log warned abouttransaction_timeout— the login'stransaction_timeout(Postgres 17 and later) ended Prism's one transaction before the run finished. It is not retried, because every retry would be a new transaction the same cap ends. Raise it for this login above the whole run's length, or unset it — see what to ask your DBA for. - The probe, or the first copy, refuses saying the server does not offer
TLS — under the default
sslmode: require, a server without TLS is a refusal that names this line, on the first attempt and without a retry. A test instance without TLS is the usual way to meet it. Confirm with your DBA before writingdisableorallow, both of which are clear text wherever they are used, andprefer, which is clear text against such a server; the probe reports which it got. You can write it on a registered source by editing its manifest — see the session settings — and then probe again. - The first copy refuses with
42P01— a table or view the SELECT or a function it calls reads is not in its named schema, or, if unqualified, in anysearch_pathschema the session's role mayUSE(a schema it may notUSEis skipped; qualified, the same schema is42501). It is also an alias the SELECT qualifies a column with but itsFROMdoes not have: the server says missing FROM-clause entry. - The first copy refuses with
3F000— a schema-qualified function, type, operator or collation the SELECT reaches, in the SELECT itself or in a function it calls, names a schema this database does not have. A missing table or view is42P01instead, even when its schema is the missing part. The server's message names the schema; to read it, see When the code is not in this list. - The first copy refuses with
42501, insufficient privilege — something the SELECT reads or locks is not granted, or row-level security refused it. The view and its schema are checked for the session's role (the login, or the rolerole_parameternames); an object behind a plain view is usually checked for the view's owner instead, and a function the view calls for the session's role. The server's message names the object, or says row-level security refused the rows; to read it, see When the code is not in this list. That is the table's policies and therow_securitysetting in force where it fired: the session's (show row_securityin that session), or aSET row_securityon a function the SELECT calls. The message's CONTEXT names a function it passed through, whether or not that function sets one. Not a grant:SET ROLEdoes not load the role's own settings, and turningrow_securityon makes the policies filter rows silently instead, so the copy lands short. Grant what is missing; or, if your standards grant it to a role the login does not inherit, setrole_parameterto that role (see the session settings), so the session assumes it. - The first copy refuses with
42703, naming a column — the column is not in the result set as spelled. Postgres folded it, or the alias differs from thefrom:line. - The first copy refuses with
42883, saying to cast the keyset key to text — apaginate: keysetkey (or anincrementalcursor column) has a type whose<the session cannot see. Keyset paging orders and compares the key with<, looked up under the session'ssearch_path, which is the source's schema alone, so an extension type installed elsewhere (ltreeinpublic) or one with no<at all (hstore) is refused on the first page. Cast the key to text in the SELECT (… , state::text AS state), or, for apaginate: keysetstream, usepaginate: none, which reads the view in one pass with no key. Anincrementalcursor column has only the first remedy. A42883that says to read the server's message instead is the SELECT's own: a comparison or join between two different types, or a function that does not exist. The message names it. - A copy refuses saying the key is citext — a
paginate: keysetkey (or anincrementalcursor column) iscitext, and the citext extension is installed in the source's own schema, so its operators are the ones the copy pages with. They holdaandAequal: two rows whose keys differ only in case would be one key, and a copy would skip rows without an error. Nothing is copied. Cast the key to text in the SELECT (… , ticket_number::text AS ticket_number). With citext installed in another schema, such aspublic, a keyset copy is not refused: the operators it pages with are text's. Apaginate: offsetcopy whose primary key has a citext column is refused wherever citext is installed, because its pages are ordered by citext's own order, which ignores case; the same cast is the remedy. A citext column that is not part of the key is fine to order by: the key, which is inorder_bytoo, breaks its ties. - The first copy refuses saying "the key
…has a collation that is not binary" — a key the copy pages on (paginate.keys,paginate.order_byor the keyset mode'sincremental.cursor) has a nondeterministic collation, such as an ICU collation created withdeterministic = falseto compare case-insensitively. Values that differ as bytes can then be one key, and paging on it would skip rows without an error. Nothing was copied. ApplyCOLLATE "C"to that column in the SELECT (… , ticket_number COLLATE "C" AS ticket_number), or page on a column with a deterministic collation. The run's log on the stream's Runs tab names the collation. The check needs Postgres 13. On Postgres 12 a paged copy is refused instead, saying so, when the database holds any nondeterministic collation, and copies as before when it holds none. - The first copy says the statement did not finish inside
statement_timeout— raise the ceiling, or ask your DBA whether the view can be materialised or indexed; the copy is not retried on a timeout, because a statement too slow once is too slow six times. The ceiling spans the whole copy — the cursor is drained under one clock, not one per fetch — and a cursor evaluates the view without parallel workers, so a view that runs in seconds on your console when it is parallelised can need a longer ceiling here. If the message says the ceiling is one the source's role or cluster carries, the recipe set none and the login's ownstatement_timeoutfired: set one in the recipe, above it. Either change is an edit of the source's manifest, followed by a probe, approve and enable — and a copy is next attempted at the schedule's time, or when you ask it to run now. - The probe says it could not assume the role (
42501,22023or42704) — a rolerole_parameternames that does not exist is22023, and one not granted to the login is42501: create it, or grant it to the login. These codes also come from a setting in the DSN's query that the server refuses (42704is only that: a setting it does not recognise), and a42501at sign-in can be the login lackingCONNECTon the database. - A copy is refused as
SESSION-CLOSED— the session closed while Prism held it open: the source'sidle_in_transaction_session_timeout(section 1), a DBA, a failover or the network path can each do it. From 1.0.0-beta1 a stream read withpaginate: nonekeeps its session alive every 30 seconds while Prism writes a chunk, so an idle limit of a minute or more no longer does it there; a shorter one, or a limit on the session's whole life (a network device's maximum connection age), still can. To shorten the gaps between fetches, lower the recipe'sfetch_size(page_sizeon a keyset or offset stream). Nothing of the copy was kept. - A copy is refused with
22021or22P05: a text value will not convert, usually to UTF-8. Prism's Postgres client asks the server for UTF-8, unless the source's DSN setsclient_encodingin its query. Your own SQL client may ask for something else, and then it shows the same rows without complaint. On aSQL_ASCIIserver Prism repairs most such values itself (see If your server's encoding isSQL_ASCII), so there this code usually means one of the cases that section lists as not covered. The server's message names the bytes and the encoding; to read it, see When the code is not in this list. Usually the fix is one of three: leave the column out of theSELECT(or cast it totexton aSQL_ASCIIserver), repair the row at the source, or ask your DBA about the database's encoding. - A copy stops with no answer to connect, session setup or begin
within 60s — the server, or something between it and Prism, stopped
answering at that step. None of those steps touches your view, so each has a
fixed 60-second limit. The copy is tried six times, each failed attempt logs
database error (no answer to … within 60s), and then it stops, about nine minutes after it began. Press Test on the source: if Test also fails, the network path is down. If Test passes, look for a firewall, NAT or load balancer that drops idle connections. - The run log warns that closing the read's cursor got no answer within
5s, so Prism ended the session — the server, or something between it and
Prism, stopped answering just after that stream's rows had been read or its
read had been stopped. What is read after it is read on a new session, at a
later instant under the same
as_of; a partitioned stream that meets it part way is abandoned instead, and the next run copies it whole. If it repeats, look for a firewall, NAT or load balancer that drops connections, as for the stalls above. - A copy stops saying the statement did not finish inside the engine's own
3600s bound on one step of the statement — the manifest sets no
statement_timeout, and one step of the statement returned nothing for an hour. A copy that keeps delivering never hits this. The step can be waiting on your server (a lock on the view's tables, from a reload or a refresh, or a queue); the view can need longer than an hour before its first row, because it sorts or aggregates everything first; or something between Prism and your server dropped the connection without closing it. Prism turns on TCP keepalive on the connection, so a connection whose far end has gone away usually fails within about two minutes instead. For the long view, setstatement_timeoutin the manifest to how long the copy needs, which replaces this bound. - A copy is refused for a wall clock that "never happened" — a
timestampwithout time zone holds a value inside the hour the clocks skipped in the zone you declared. Convert the column totimestamptzin the view's ownSELECT(AT TIME ZONE '<zone>') and dropnaive_timezone.
When the code is not in this list
Prism never prints your server's own error message. The message can quote the
statement, the login and sometimes a value. The message is also the fastest way
to find the cause, so read it yourself: run the stream's SELECT in a session
set up like the copy's, signed in as the service account with the source's DSN
if it has one (the settings in its query string are part of the session), and
with the recipe's
connection values (the schema becomes the
session's search_path) and
session settings.
After any settings in the DSN's query, the copy's session runs these, in this
order:
SET client_encoding = 'UTF8'; -- unless the DSN's query sets client_encoding
SET statement_timeout = '<the tightest statement_timeout in the run, in milliseconds>'; -- only if the manifest sets one
SET default_transaction_read_only = on;
SET TimeZone = 'UTC';
SET ROLE "<your role>"; -- only if the manifest has role_parameter; spelled as created
SET search_path = "<your schema>"; -- only if the source names a schema; spelled as created
BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY;
<the stream's SELECT, with the window values filled in>;
A session you set up by hand is close to the copy's, not identical, so a refusal can read differently there.