|
2 | 2 | title: 'PostgreSQL Data Connector' |
3 | 3 | sidebar_label: 'PostgreSQL Data Connector' |
4 | 4 | description: 'PostgreSQL Data Connector Documentation' |
| 5 | +tags: |
| 6 | + - data-connectors |
| 7 | + - postgres |
| 8 | + - write |
5 | 9 | --- |
6 | 10 |
|
7 | 11 | 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 |
171 | 175 |
|
172 | 176 | ::: |
173 | 177 |
|
| 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 | + |
174 | 241 | ## Examples |
175 | 242 |
|
176 | 243 | ### Connecting using Username/Password |
|
0 commit comments