Skip to content

Commit 20a02a0

Browse files
committed
updated postgres config documentation for version 0.5.1
1 parent 8faa34e commit 20a02a0

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

_posts/2025-11-29-eventstore-configuring-postgresql-storage.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,9 @@ The EventStore can automatically create and configure DataSources from a `db.pro
100100
2. Environment variable: `EVENTSTORE_DB_CONFIG=/path/to/db.properties`
101101
3. Current working directory and up to 2 parent directories: `./db.properties`, `../db.properties`, `../../db.properties`
102102

103-
### Simple Configuration (Single DataSource)
103+
### Configuring the pooled and non-pooled connections
104104

105-
For basic setups, define a single pooled DataSource:
106-
107-
```properties
108-
# db.properties - Simple configuration
109-
db.url=jdbc:postgresql://<host>/<db>
110-
db.username=<user>
111-
db.password=<password>
112-
db.leakDetectionThreshold=70000
113-
db.maximumPoolSize=2
114-
db.datasource.sslmode=require
115-
db.datasource.channelBinding=require
116-
db.datasource.cachePrepStmts=true
117-
db.datasource.prepStmtCacheSize=250
118-
db.datasource.prepStmtCacheSqlLimit=2048
119-
```
120-
121-
The monitoring mechanism holds on for longer periods to the connection, making it required to avoid false positive leakDetections too early one them.
122-
123-
124-
### Advanced Configuration (Separate Pooled and Non-pooled)
125-
126-
For production environments, especially with PgBouncer, define separate datasources:
105+
Define separate datasources:
127106

128107
```properties
129108
# db.properties - Advanced configuration
@@ -156,7 +135,7 @@ db.nonpooled.datasource.prepStmtCacheSqlLimit=2048
156135
Be sure the size your pooled datasource connections according to your application needs.
157136
The non-pooled datasource used for monitoring appends with the NOTIFY/LISTEN mechanism only needs 2 connections.
158137

159-
The EventStore automatically detects the configuration style and creates appropriate DataSources.
138+
leakDetectionThreshold on the pooled (application) connections should be set quite low, for the monitoring connections this should be at least 30 seconds, as the monitoring connection only refreshes after a longer LISTEN for updates.
160139

161140
## Preparing the Database Schema Manually via DDL
162141

@@ -171,18 +150,34 @@ The recommended approach is to create the database schema manually using DDL scr
171150
The library includes an `quickstart.ddl.sql` script (available in the JAR or source repository):
172151

173152
```sql
174-
175153
CREATE TABLE events (
154+
-- Primary key and positioning
176155
event_position BIGSERIAL PRIMARY KEY,
156+
157+
-- XID8 transaction id
158+
event_tx xid8 DEFAULT pg_current_xact_id()::xid8 NOT NULL,
159+
160+
-- Event identification
177161
event_id UUID NOT NULL UNIQUE,
162+
163+
-- Stream identification
178164
stream_context TEXT NOT NULL,
179165
stream_purpose TEXT NOT NULL DEFAULT '',
166+
167+
-- Event metadata
180168
event_type TEXT NOT NULL,
169+
170+
-- Transaction information
181171
event_timestamp TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
172+
173+
-- Event payload
182174
event_data JSONB NOT NULL,
183175
event_erasable_data JSONB,
176+
177+
-- Tags as string array
184178
event_tags TEXT[] DEFAULT '{}'
185-
);
179+
180+
) WITH (FILLFACTOR = 100);
186181

187182
-- Additional indexes, functions, and triggers...
188183
```
@@ -201,18 +196,34 @@ For these scenario's, EventStore supports the usage of prefixes, in which all re
201196
You can find a DDL script named `initialisation.sql`, which has exactly the same content as `quickstart.ddl.sql`, but with a "PREFIX_" before each object that you can replace by any tenant name you like, ending with "_":
202197

203198
```sql
204-
205199
CREATE TABLE PREFIX_events (
200+
-- Primary key and positioning
206201
event_position BIGSERIAL PRIMARY KEY,
202+
203+
-- XID8 transaction id
204+
event_tx xid8 DEFAULT pg_current_xact_id()::xid8 NOT NULL,
205+
206+
-- Event identification
207207
event_id UUID NOT NULL UNIQUE,
208+
209+
-- Stream identification
208210
stream_context TEXT NOT NULL,
209211
stream_purpose TEXT NOT NULL DEFAULT '',
212+
213+
-- Event metadata
210214
event_type TEXT NOT NULL,
215+
216+
-- Transaction information
211217
event_timestamp TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
218+
219+
-- Event payload
212220
event_data JSONB NOT NULL,
213221
event_erasable_data JSONB,
222+
223+
-- Tags as string array
214224
event_tags TEXT[] DEFAULT '{}'
215-
);
225+
226+
) WITH (FILLFACTOR = 100);
216227

217228
-- Additional indexes, functions, and triggers...
218229
```

0 commit comments

Comments
 (0)