Skip to content
Effect Days 2026 Get your ticket

PgPool

Pools of native PgConnection sessions.

6 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

Creates a scoped PostgreSQL session pool.

Details

Connections are opened lazily up to maxConnections and released down to minConnections after idleTimeout without use. Closing the scope shuts the pool down and releases every session.

Signature

declare const make: (...args: [options: Config]) => Effect<PgPool, SqlError, Scope>

Models

Config interface

Added in v4.0.0 Source

Connection and sizing settings for a PostgreSQL session pool.

Details

The defaults are 0 to 10 connections and a 10-second idle timeout. connectionTTL replaces connections that exceed the configured lifetime. Every connection is used at least once, so a TTL of zero disables reuse.

With multiplex enabled, fibers may share pooled connections for pipelined queries. Reserved connections remain exclusive. Without multiplexing, every checkout is exclusive.

Signature

interface Config extends Config {
readonly connectionTTL?: Input;
readonly idleTimeout?: Input;
readonly maxConnections?: number;
readonly minConnections?: number;
readonly multiplexConcurrency?: number;
}

PgPool interface

Added in v4.0.0 Source

A PostgreSQL session pool.

Signature

interface PgPool {
readonly "~@effect/sql-pg/PgPool": "~@effect/sql-pg/PgPool";
readonly config: Config;
readonly get: Effect<PgConnection, SqlError, Scope>;
readonly invalidate: (connection: PgConnection) => Effect<void>;
readonly reserve: Effect<PgConnection, SqlError, Scope>;
readonly use: <A, E, R>(f: (connection: PgConnection) => Effect<A, E, R>) => Effect<A, SqlError | E, R>;
}

Services

PgPool

Added in v4.0.0 Source

The service tag for PgPool.

Signature

declare const PgPool: Service<PgPool, PgPool>

Type IDs

TypeId

Added in v4.0.0 Source

The runtime type identifier for PgPool.

Signature

declare const TypeId: TypeId

TypeId type

Added in v4.0.0 Source

The type-level identifier for PgPool.

Signature

type TypeId = "~@effect/sql-pg/PgPool"