Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postgres connection timeout option #6160

Merged
merged 1 commit into from Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/connection-options.md
Expand Up @@ -173,6 +173,8 @@ See [SSL options](https://github.com/mysqljs/mysql#ssl-options).

* `schema` - Schema name. Default is "public".

* `connectTimeoutMS` - The milliseconds before a timeout occurs during the initial connection to the postgres server. If `undefined`, or set to `0`, there is no timeout. Defaults to `undefined`.

* `ssl` - Object with ssl parameters. See [TLS/SSL](https://node-postgres.com/features/ssl).

* `uuidExtension` - The Postgres extension to use when generating UUIDs. Defaults to `uuid-ossp`. Can be changed to `pgcrypto` if the `uuid-ossp` extension is unavailable.
Expand Down
6 changes: 6 additions & 0 deletions src/driver/postgres/PostgresConnectionOptions.ts
Expand Up @@ -33,6 +33,12 @@ export interface PostgresConnectionOptions extends BaseConnectionOptions, Postgr

};

/**
* The milliseconds before a timeout occurs during the initial connection to the postgres
* server. If undefined, or set to 0, there is no timeout. Defaults to undefined.
*/
readonly connectTimeoutMS?: number;

/**
* The Postgres extension to use to generate UUID columns. Defaults to uuid-ossp.
* If pgcrypto is selected, TypeORM will use the gen_random_uuid() function from this extension.
Expand Down
4 changes: 3 additions & 1 deletion src/driver/postgres/PostgresDriver.ts
Expand Up @@ -925,13 +925,15 @@ export class PostgresDriver implements Driver {
credentials = Object.assign({}, credentials, DriverUtils.buildDriverOptions(credentials)); // todo: do it better way

// build connection options for the driver
// See: https://github.com/brianc/node-postgres/tree/master/packages/pg-pool#create
const connectionOptions = Object.assign({}, {
host: credentials.host,
user: credentials.username,
password: credentials.password,
database: credentials.database,
port: credentials.port,
ssl: credentials.ssl
ssl: credentials.ssl,
connectionTimeoutMillis: options.connectTimeoutMS
}, options.extra || {});

// create a connection pool
Expand Down