You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/features/load-balancer/index.md
+52-3Lines changed: 52 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,18 +145,67 @@ COMMIT;
145
145
146
146
Read-only transactions are useful when queries depend on each other's results and need a consistent view of the database. Some Postgres database drivers allow this option to be set in the code, for example:
147
147
148
-
=== "Golang/pgx"
149
-
```golang
148
+
=== "pgx (go)"
149
+
```go
150
150
tx, err := conn.BeginTx(ctx, pgx.TxOptions{
151
151
AccessMode: pgx.ReadOnly,
152
152
})
153
153
```
154
-
=== "Node/Sequelize"
154
+
=== "Sequelize (node)"
155
155
```javascript
156
156
const tx = await sequelize.transaction({
157
157
readOnly: true,
158
158
});
159
159
```
160
+
=== "SQLAlchemy (python)"
161
+
Add `postgresql_readonly=True` to [execution options](https://docs.sqlalchemy.org/en/20/core/connections.html#sqlalchemy.engine.Engine.execution_options), like so:
If you need to override the load balancer routing decision and send a query (or all queries) to the primary, it's possible to do so by configuring the `pgdog.role` connection parameter.
170
+
171
+
Configuring this connection parameter can be done at connection creation:
|`primary`| Queries are sent to the primary database only. |
208
+
|`replica`| Queries are load balanced between primary and replicas, depending on the value of the [`read_write_split`](../../configuration/pgdog.toml/general.md#read_write_split) setting. |
0 commit comments