Overview
PostgreSQL dialect that uses the pg library (node-postgres). This is the recommended way to connect Kysely to PostgreSQL databases. Source:src/dialect/postgres/postgres-dialect.ts:43
Installation
Install the required peer dependencies:Basic Usage
Configuration
PostgresDialectConfig
Source:src/dialect/postgres/postgres-dialect-config.ts:6
A postgres Pool instance or a function that returns one.If a function is provided, it’s called once when the first query is executed. This allows for lazy initialization of the connection pool.See node-postgres Pool documentation for available pool options.
Called once for each created connection. Useful for setting up connection-level configuration.
Called every time a connection is acquired from the pool. Use this for per-query setup that needs to run every time.
Connection Pooling
The PostgreSQL dialect uses thepg library’s built-in connection pooling. Here are some recommended pool settings:
Streaming with Cursors
For large result sets, you can use cursors to stream results:SSL/TLS Configuration
To connect using SSL:Environment Variables
Thepg library automatically reads these environment variables:
PGHOST- Database hostPGPORT- Database portPGDATABASE- Database namePGUSER- Database userPGPASSWORD- Database password
Related Types
PostgresPool
Source:src/dialect/postgres/postgres-dialect-config.ts:52
The subset of the pg Pool interface that Kysely requires:
PostgresPoolClient
Source:src/dialect/postgres/postgres-dialect-config.ts:57