Skip to content

Commit 8e9aae9

Browse files
claudespicelukekim
authored andcommitted
docs: Document PostgreSQL DML support and acceleration.write_mode
Adds: - Write Support section on the PostgreSQL data connector page covering INSERT/UPDATE/DELETE with `access: read_write`, plus the write_through vs write_back acceleration write modes and refresh_mode: changes interaction. - `write` tag to the PostgreSQL connector frontmatter so it lists under the write-capable connectors tag page. - `acceleration.write_mode` reference entry in datasets.md. Source: spiceai/spiceai#10446
1 parent e6ac7b6 commit 8e9aae9

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

website/docs/components/data-connectors/postgres/index.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
title: 'PostgreSQL Data Connector'
33
sidebar_label: 'PostgreSQL Data Connector'
44
description: 'PostgreSQL Data Connector Documentation'
5+
tags:
6+
- data-connectors
7+
- postgres
8+
- write
59
---
610

711
PostgreSQL is an advanced open-source relational database management system known for its reliability, extensibility, and support for SQL compliance.
@@ -171,6 +175,69 @@ The Postgres federated queries may result in unexpected result types due to the
171175

172176
:::
173177

178+
## Write Support
179+
180+
The PostgreSQL connector supports writing data to PostgreSQL tables using SQL [`INSERT INTO`](../../../reference/sql/dml#insert), `UPDATE`, and `DELETE FROM` statements.
181+
182+
To enable writes, set `access: read_write` on the dataset:
183+
184+
```yaml
185+
datasets:
186+
- from: postgres:public.events
187+
name: events
188+
access: read_write
189+
params:
190+
pg_host: localhost
191+
pg_port: '5432'
192+
pg_db: mydb
193+
pg_user: spice_writer
194+
pg_pass: ${secrets:PG_PASSWORD}
195+
```
196+
197+
```sql
198+
-- Insert rows
199+
INSERT INTO events (id, name, amount)
200+
VALUES (1, 'Alice', 100.0), (2, 'Bob', 200.0);
201+
202+
-- Update rows
203+
UPDATE events SET amount = 150.0 WHERE id = 1;
204+
205+
-- Delete rows
206+
DELETE FROM events WHERE id = 2;
207+
```
208+
209+
### Write modes with acceleration
210+
211+
When PostgreSQL is used as the federated source for an accelerated dataset, `acceleration.write_mode` selects how writes propagate between the local accelerator and PostgreSQL:
212+
213+
- `write_through` (default) — writes are sent to PostgreSQL synchronously. The client receives an ACK only after the source commits. The local accelerator is updated via the configured refresh path. Choose this for ACID guarantees.
214+
- `write_back` — writes are applied to the local accelerator first (fast ACK), then forwarded asynchronously to PostgreSQL. Choose this for write throughput when eventual consistency at the source is acceptable.
215+
216+
`acceleration.refresh_mode: changes` is supported for `access: read_write` datasets: writes go to PostgreSQL and the WAL replication stream applies the resulting changes back to the accelerator.
217+
218+
```yaml
219+
datasets:
220+
- from: postgres:public.events
221+
name: events
222+
access: read_write
223+
params:
224+
pg_host: localhost
225+
pg_port: '5432'
226+
pg_db: mydb
227+
pg_user: spice_writer
228+
pg_pass: ${secrets:PG_PASSWORD}
229+
# Replication-mode parameters (see Configuration above)
230+
pg_replication_publication: spice_pub
231+
pg_replication_slot_name: spice_slot
232+
acceleration:
233+
engine: duckdb
234+
mode: file
235+
refresh_mode: changes
236+
write_mode: write_through # default; use write_back for fast async writes
237+
```
238+
239+
For more details, see [Data Ingestion](../../../features/data-ingestion).
240+
174241
## Examples
175242

176243
### Connecting using Username/Password

website/docs/reference/spicepod/datasets.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,15 @@ Optional. How to refresh the dataset. The following values are supported:
467467
- `caching` - Cache data based on request metadata (HTTP requests). Uses row-level replacement based on cache keys. See [Caching Mode](../../features/data-acceleration/refresh-modes/caching) for details.
468468
- `snapshot` - Reload exclusively from the [snapshot store](../../features/data-acceleration/snapshots). The federated source is never queried; the runtime polls for newer snapshots at `refresh_check_interval` (default: 60s). Requires `acceleration.snapshots: enabled` or `bootstrap_only` and a snapshot-capable file-based engine (DuckDB, SQLite, Cayenne, or Turso). Writes (`INSERT INTO`) are rejected. See [Snapshot Refresh Mode](../../features/data-acceleration/data-refresh#snapshot).
469469

470+
## `acceleration.write_mode`
471+
472+
Optional. Controls how writes to a `read_write` accelerated dataset propagate between the local accelerator and the federated source. Only applies when the dataset has `access: read_write` and the source connector supports writes.
473+
474+
Supported values:
475+
476+
- `write_through` (default) – Writes are sent to the federated source synchronously. The client receives an ACK only after the source commits the change, providing ACID guarantees. The local accelerator is updated through the configured refresh path (for example, the WAL stream when `refresh_mode: changes`).
477+
- `write_back` – Writes are applied to the local accelerator first (fast ACK), then forwarded asynchronously to the federated source. Choose this for write throughput when eventual consistency at the source is acceptable.
478+
470479
## `acceleration.refresh_check_interval`
471480

472481
Optional. How often data should be refreshed. For `append` datasets without a specific `time_column`, this config is not used. If not defined, the accelerator will not refresh after it initially loads data. Cannot be specified in conjunction with a `refresh_cron`.

0 commit comments

Comments
 (0)