Skip to content

Commit

Permalink
session mode docs
Browse files Browse the repository at this point in the history
  • Loading branch information
levkk committed Jan 11, 2025
1 parent f28ab2d commit 663202e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
30 changes: 30 additions & 0 deletions docs/docs/features/session-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Session mode

In session mode, pgDog allocates one PostgreSQL server connection per client. This ensures that all PostgreSQL features work as expected, including persistent session variables, settings, and
process-based features like `LISTEN`/`NOTIFY`. Some batch-based tasks, like ingesting large amounts of data, perform better in session mode.

## Enable session mode

Session mode can be enabled globally or on a per-user basis:

=== "pgdog.toml"
```toml
[general]
pooler_mode = "session"
```
=== "users.toml"
```toml
[[users]]
name = "pgdog"
database = "pgdog"
pooler_mode = "session"
```

## Performance

Unlike [transaction mode](transaction-mode.md), session mode doesn't allow for client/server connection multiplexing, so the maximum number of allowed client connections
is controlled by the `default_pool_size` (and `pool_size`) settings. For example, if your database pool size is 15,
only 15 clients will be able to connect and use the database at any given moment.

!!! note
In session mode, when the connection pool reaches full capacity, a client has to disconnect before another one can connect to pgDog.
2 changes: 1 addition & 1 deletion docs/docs/features/transaction-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ more than a few thousand concurrently open connections.

<center>
<img src="/images/transaction-mode.png" width="65%" alt="Load balancer" />
<p><i>In transaction mode, multiple clients reuse one Postgres connection.</i></p>
<p><i>In transaction mode, multiple clients can reuse one Postgres connection.</i></p>
</center>


Expand Down
5 changes: 2 additions & 3 deletions pgdog/src/frontend/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use tracing::{debug, error, info, trace};
use super::{Buffer, Comms, Error, Router, Stats};
use crate::auth::scram::Server;
use crate::backend::pool::Connection;
use crate::config::PoolerMode;
use crate::net::messages::{
Authentication, BackendKeyData, ErrorResponse, Protocol, ReadyForQuery,
};
Expand Down Expand Up @@ -55,7 +54,7 @@ impl Client {
Ok(params) => params,
Err(err) => {
if err.no_server() {
error!("Connection pool is down");
error!("connection pool is down");
stream.fatal(ErrorResponse::connection()).await?;
return Ok(());
} else {
Expand Down Expand Up @@ -161,7 +160,7 @@ impl Client {
match backend.connect(&self.id, router.route()).await {
Ok(()) => (),
Err(err) => if err.no_server() {
error!("Connection pool is down");
error!("connection pool is down");
self.stream.error(ErrorResponse::connection()).await?;
comms.stats(stats.error());
continue;
Expand Down

0 comments on commit 663202e

Please sign in to comment.