Interface PostgresAdapterOptions

Configuration options for PostgreSQL adapter. Supports both connection strings and granular configuration.

interface PostgresAdapterOptions {
    connectionString?: string;
    host?: string;
    port?: number;
    database?: string;
    user?: string;
    password?: string;
    ssl?: boolean | {
        rejectUnauthorized?: boolean;
        ca?: string;
        cert?: string;
        key?: string;
    };
    max?: number;
    min?: number;
    idleTimeoutMillis?: number;
    connectionTimeoutMillis?: number;
    application_name?: string;
    statement_timeout?: number;
    query_timeout?: number;
    allowExitOnIdle?: boolean;
    typeParsers?: PostgresTypeParsers;
    segment?: string;
    pool?: PostgresPoolLike;
    ownsPool?: boolean;
    onError?: ((error: Error) => void);
}

Properties

connectionString?: string

PostgreSQL connection string (e.g., 'postgresql://user:pass@host:5432/dbname')

host?: string

Host name or IP address (default: localhost)

port?: number

Port number (default: 5432)

database?: string

Database name

user?: string

Username for authentication

password?: string

Password for authentication

ssl?: boolean | {
    rejectUnauthorized?: boolean;
    ca?: string;
    cert?: string;
    key?: string;
}

Enable SSL/TLS connection (recommended for remote)

max?: number

Connection pool size (default: 10)

min?: number

Minimum pool size (default: 0)

idleTimeoutMillis?: number

Idle timeout in ms (default: 10000)

connectionTimeoutMillis?: number

Connection timeout in ms (default: 0 = no timeout)

application_name?: string

Application name for connection tracking

statement_timeout?: number

Statement timeout in ms (0 = no timeout)

query_timeout?: number

Query timeout in ms (0 = no timeout)

allowExitOnIdle?: boolean

Let Node exit while every connection in the pool is idle (pg's allowExitOnIdle). Default: false, so idle connections keep the process running until idleTimeoutMillis closes them or close() ends the pool.

typeParsers?: PostgresTypeParsers

How this pool's connections decode the column types whose pg defaults surprise JavaScript code, through pg's per-client type parsers. Each field left out keeps pg's default. A value it does not know fails open(). A pool of the caller's decodes with the types it was made with, so this cannot be given with pool.

segment?: string

A schema of its own for the adapter's tables. Every connection of the adapter's pool starts with search_path set to the segment, then public, so the tables it creates without a schema land in the segment, and the types, functions and operators of extensions in public (pgvector's vector, <->) still resolve. open() creates the schema when it is missing, and a CREATE EXTENSION that names no schema installs the extension where it would without a segment, in public.

open() fails when the segment is not the current schema of its first connection: PostgreSQL leaves a schema the role has no USAGE privilege on out of the search_path without a word (an existing schema another role made), and a pooler that drops startup options leaves it out too. The role needs USAGE and CREATE on the segment's schema.

A name the segment does not hold falls through to public: create a segment's tables before reading them (CREATE TABLE IF NOT EXISTS creates one in the segment even when public has a table of that name), and name the segment in a DROP or ALTER that public could also answer.

Lower-case letters, digits and underscores; not public, information_schema or a name beginning with pg_. A segment cannot be combined with pool, nor with a connection string that sets its own options startup parameter: pg sends those in place of the segment's.

A pool the caller made (a pg Pool) for the adapter to run on, instead of making one. The adapter runs on it from the start: no open() is needed, and open() after close() takes it up again. The connection settings above apply when a pool is made, so none of them, nor segment, can be given with it.

ownsPool?: boolean

Whether close() ends pool. False by default: the pool is its caller's, and close() leaves it open. Pass true when the adapter is the pool's one holder and closing the adapter is how the pool should end; close() then ends it once, however often it is called.

onError?: ((error: Error) => void)

Called with the error an idle connection of the pool reports (the server ended it, the network dropped). pg's Pool raises such an error as an event that, with no listener, ends the process. On a pool the adapter makes or owns, the adapter listens even without onError and logs one warning per error; on a pool of its caller's that it does not own, it listens only when given onError, and takes its listener off again on close().