Skip to content

Commit f14e0cd

Browse files
dieribahcourdent
andauthored
Dt/database docs (windmill-labs#833)
* feat: database-docs * feat: postgres docs * nits: add sentance case * update docs * nits: fix case and rename postgresql to postgres * nits: update docs * nits: update docs * Doc typo + changelog * feat: docs * feat(dt/database-docs): add section for host db provider * update docs * update docs * update docs * update docs * update * docs: update * docs: * docs: * update docs * update docs --------- Co-authored-by: hcourdent <henri@windmill.dev>
1 parent 7278023 commit f14e0cd

File tree

5 files changed

+119
-7
lines changed

5 files changed

+119
-7
lines changed

docs/core_concepts/43_preprocessors/index.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Here are examples of a preprocessor function in [TypeScript](../../getting_start
2323
export async function preprocessor(
2424
/* args from the request body (e.g. webhook/http body args, msg for ws/kafka/nats, raw_email and parsed_email for email) */
2525
wm_trigger: {
26-
kind: 'http' | 'email' | 'webhook' | 'websocket' | 'kafka' | 'nats',
26+
kind: 'http' | 'email' | 'webhook' | 'websocket' | 'postgres' | 'kafka' | 'nats',
2727
http?: {
2828
route: string // The route path, e.g. "/users/:id"
2929
path: string // The actual path called, e.g. "/users/123"
@@ -90,7 +90,7 @@ class Nats(TypedDict):
9090
length: int
9191

9292
class WmTrigger(TypedDict):
93-
kind: Literal["http", "email", "webhook", "websocket", "kafka", "nats"]
93+
kind: Literal["http", "email", "webhook", "websocket", "postgres", "kafka", "nats"]
9494
http: Http | None
9595
websocket: Websocket | None
9696
kakfa: Kafka | None
@@ -129,7 +129,7 @@ The flow preprocessor takes the same arguments as the script preprocessor and sh
129129
export async function preprocessor(
130130
/* args from the request body (e.g. webhook/http body args, msg for ws/kafka/nats, raw_email and parsed_email for email) */
131131
wm_trigger: {
132-
kind: 'http' | 'email' | 'webhook' | 'websocket' | 'kafka' | 'nats',
132+
kind: 'http' | 'email' | 'webhook' | 'websocket' | 'postgres' | 'kafka' | 'nats',
133133
http?: {
134134
route: string // The route path, e.g. "/users/:id"
135135
path: string // The actual path called, e.g. "/users/123"
@@ -188,7 +188,7 @@ class Nats(TypedDict):
188188
length: int
189189

190190
class WmTrigger(TypedDict):
191-
kind: Literal["http", "email", "webhook", "websocket", "kafka", "nats"]
191+
kind: Literal["http", "email", "webhook", "websocket", "postgres", "kafka", "nats"]
192192
http: Http | None
193193
websocket: Websocket | None
194194
kafka: Kafka | None

docs/core_concepts/46_postgres_triggers/index.mdx

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Postgres triggers are not available on the [Cloud](/pricing).
1818

1919
Windmill's Postgres trigger feature is built on Postgres's logical replication protocol, which allows changes to a database to be streamed in real time to subscribers. Logical replication provides fine-grained control over what data is replicated by allowing the user to define publications and subscribe to specific changes.
2020

21-
#### How logical replication works:
21+
### How logical replication works
2222
1. **Publications**: Define what changes (e.g., INSERT, UPDATE, DELETE) should be made available for replication. Publications allow you to select specific tables or schemas to track.
2323
2. **Replication slots**: Ensure that all changes from a publication are retained until they are successfully delivered to the subscriber (e.g., Windmill triggers). This guarantees data reliability and prevents data loss.
2424

@@ -27,8 +27,96 @@ Windmill uses logical replication to efficiently stream database changes to your
2727
For more details, see the [Postgres documentation on logical replication](https://www.postgresql.org/docs/current/logical-replication.html).
2828
For more details, see the [Postgres documentation on logical replication streaming protocol](https://www.postgresql.org/docs/current/protocol-logical-replication.html).
2929

30+
31+
## Requirements
32+
33+
Before using Postgres triggers with Windmill, your database must be properly configured for logical replication. The primary requirement is setting the Write-Ahead Log (WAL) level to `'logical'`.
34+
35+
### Setting `wal_level` to `logical`
36+
37+
You have two options to configure this setting. Both options require a restart of your Postgres instance to take effect.
38+
39+
#### Option 1: Using SQL (requires database restart)
40+
41+
1. Run the following SQL command to set `wal_level` to `'logical'`:
42+
43+
```sql
44+
ALTER SYSTEM SET wal_level = 'logical';
45+
```
46+
47+
2. After executing the command, restart your Postgres instance for the changes to take effect.
48+
49+
#### Option 2: Editing the `postgresql.conf` file (requires database restart)
50+
51+
1. Locate and open your `postgresql.conf` file. The location of this file may vary depending on your installation.
52+
53+
2. Look for the `wal_level` setting. If it's not already present, **add** the following line to the file:
54+
55+
```ini
56+
wal_level = logical
57+
```
58+
59+
If the setting is already there, **update** it to `logical`.
60+
61+
3. Save the file and restart your Postgres instance for the changes to take effect.
62+
63+
### Verifying Logical Replication
64+
65+
You can verify that logical replication is enabled by running the following query:
66+
67+
```sql
68+
SHOW wal_level;
69+
```
70+
71+
This should return:
72+
73+
```plaintext
74+
wal_level
75+
-----------
76+
logical
77+
```
78+
79+
### Impact of Enabling Logical Replication
80+
81+
Enabling logical replication turns on detailed logging, which is essential for supporting the replication process. Be aware that this will increase the amount of data written to the Write-Ahead Log (WAL). Typically, you can expect a 10% to 30% increase in the amount of data written to the WAL, depending on the volume of write activity in your database.
82+
83+
---
84+
85+
## Additional Configuration for Logical Replication
86+
87+
For logical replication to work properly, you need to configure additional parameters in your `postgresql.conf` file. These parameters control the number of replication processes and slots available for replication. Both settings require a restart of your Postgres instance to take effect.
88+
89+
#### `max_wal_senders`
90+
91+
The `max_wal_senders` setting determines the maximum number of **walsender** processes that can run concurrently. A **walsender** is responsible for sending the Write-Ahead Log (WAL) data to subscribers for logical replication. The default value is 10, but you can increase this based on your replication needs.
92+
93+
```ini
94+
#max_wal_senders = 10 # max number of walsender processes (change requires restart)
95+
```
96+
97+
- **Impact on Triggers**: Each active trigger in logical replication will use a **walsender** process. So, if `max_wal_senders` is set to 10, only 10 active triggers can be used at the same time. If you reach this limit, you will need to increase the `max_wal_senders` value to accommodate more active triggers.
98+
99+
#### `max_replication_slots`
100+
101+
The `max_replication_slots` setting determines how many **replication slots** can be created. Replication slots are used to maintain state for each logical replication subscription. This setting also limits the number of triggers that can be created for logical replication.
102+
103+
```ini
104+
#max_replication_slots = 10 # max number of replication slots (change requires restart)
105+
```
106+
107+
- **Impact on Trigger Creation**: You can only create as many triggers as there are replication slots available. So if `max_replication_slots` is set to 10, you will be able to create a maximum of 10 triggers. If you need more triggers, you will need to increase the `max_replication_slots` value.
108+
109+
### Summary of Limits
110+
111+
- **Active triggers**: The number of active triggers you can have is limited by `max_wal_senders`. If you set `max_wal_senders` to 10, only 10 active triggers can be running simultaneously.
112+
113+
- **Trigger creation**: The number of triggers you can create is limited by `max_replication_slots`. If you set `max_replication_slots` to 10, you can only create 10 triggers in total.
114+
30115
---
31116

117+
### Final Considerations
118+
119+
When configuring these settings, make sure to account for the number of active triggers and replication slots needed for your application. If you expect to have many triggers or high replication activity, you may need to increase both `max_wal_senders` and `max_replication_slots`.
32120
## How to use
33121
Learn how to set up and configure Postgres triggers in Windmill through these key steps.
34122

docs/getting_started/8_triggers/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ Windmill can connect to WebSocket servers and trigger runnables (scripts, flows)
271271

272272
### Postgres triggers
273273

274-
Windmill can connect to postgres database servers and trigger runnables (scripts, flows) when a message is received.
274+
Windmill can connect to a [Postgres](https://www.postgresql.org/) database and trigger runnables (scripts, flows) in response to database transactions (INSERT, UPDATE, DELETE) on specified tables, schemas, or the entire database.
275275

276276
<div className="grid grid-cols-2 gap-6 mb-4">
277277
<DocCard

docs/script_editor/settings.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,18 @@ Windmill can connect to WebSocket servers and trigger runnables (scripts, flows)
244244
/>
245245
</div>
246246

247+
### Postgres
248+
249+
Windmill can connect to a [Postgres](https://www.postgresql.org/) database and trigger runnables (scripts, flows) in response to database transactions (INSERT, UPDATE, DELETE) on specified tables, schemas, or the entire database.
250+
251+
<div className="grid grid-cols-2 gap-6 mb-4">
252+
<DocCard
253+
title="Postgres triggers"
254+
description="Trigger scripts and flows from postgres database servers."
255+
href="/docs/core_concepts/postgres_triggers"
256+
/>
257+
</div>
258+
247259
### Kafka
248260

249261
Windmill can connect to Kafka brokers and trigger scripts or flows when messages are received on specific topics. This enables real-time processing of events from your Kafka ecosystem.

src/components/Pricing.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,25 @@ const sections = [
469469
tiers: {
470470
'tier-free-selfhost': true,
471471
'tier-enterprise-selfhost': true,
472-
'tier-enterprise-cloud': false,
472+
'tier-enterprise-cloud': true,
473473
'tier-free': false,
474474
'tier-team': false
475475
},
476476
link: '/docs/core_concepts/40_websocket_triggers',
477477
tooltip: 'Self-hosted only'
478478
},
479+
{
480+
name: 'Postgres triggers',
481+
tiers: {
482+
'tier-free-selfhost': true,
483+
'tier-enterprise-selfhost': true,
484+
'tier-enterprise-cloud': true,
485+
'tier-free': false,
486+
'tier-team': false
487+
},
488+
link: '/docs/core_concepts/46_postgres_triggers',
489+
tooltip: 'Self-hosted only'
490+
},
479491
{
480492
name: 'Kafka triggers',
481493
tiers: {

0 commit comments

Comments
 (0)