Skip to content

Connection Syntax

Vitaly Tomilov edited this page May 23, 2019 · 74 revisions

Connection details syntax to be used when creating a Database object.

Most of the connection parameters are optional. See their default values.

Configuration Object

  • string host - server name or IP address
  • number port - server port number
  • string database - database name
  • string user - user name
  • string password - user password
  • boolean ssl - use SSL (it also can be a TSSLConfig-like object)
  • boolean binary - binary result mode
  • string client_encoding
  • string application_name
  • string fallback_application_name
  • number idleTimeoutMillis - lifespan for unused connections
  • number max - maximum size of the connection pool
  • number min - minimum size of the connection pool
  • number query_timeout - query execution timeout
  • boolean keepAlive - keep TCP alive

etc, there are more advanced parameters - reapIntervalMillis, returnToHead, poolLog, parseInputDatesAsUTC, rows and statement_timeout. Check the driver for their usage.

Example:

const cn = {
    host: 'localhost',
    port: 5432,
    database: 'my-database-name',
    user: 'user-name',
    password: 'user-password'
};

const db = pgp(cn);

Connection String

Connection strings support only a subset of connection parameters as show below:

postgres://username:password@host:port/database?ssl=false&application_name=name
&fallback_application_name=name&client_encoding=encoding

Other parameters are also supported, similar to the ones within the connection object, but not all of them. For example, when ssl needs to be an object, it is not supported by the connection string.

Example:

const db = pgp('postgres://john:pass123@localhost:5432/products');

See also:

You can’t perform that action at this time.