postgreSQL.pool.create

Syntax

postgreSQL.pool.create (poolname, conninfo, minConnections, maxConnections, restartTimeoutSecs, idleTimeoutSecs)

Params

poolname is a string serving as the global name for the pool.

conninfo is a string specifying the connection parameters.

minConnections is an optional number. Default is 4.

maxConnections is an optional number. Default is 32.

restartTimeoutSecs is an optional number. Default is 14400, i.e. four hours.

idleTimeoutSecs is an optional number. Default is 300, i.e. five minutes.

Action

Creates a pool of connections to the specified database server.

Returns

A boolean that is true if the pool was created or false if a pool with the given name already exists.

Examples

postgreSQL.pool.create ("mytestpool", "hostaddr=192.168.1.3 user=test password=test")

« true

Notes

Initially, the pool contains a number of open connections equal to minConnections. Use postgreSQL.connection.grab to obtain a reference to an idle connection, or if none is available, to transparently have a new connection opened and added to the pool. The upper limit on the number of connections to the database server is given by maxConnections.

For a detailed description of the key-value pairs in a legal conninfo string, see the notes for postgreSQL.connection.open.

Once a minute, a scheduler thread checks the status of the connections in the pool. In order to conserve resources on the database server, connections that have been idle for longer than idleTimeoutSecs seconds are closed until the total number of connections has dropped back to minConnections. Sometimes connections that have been open for a long time can get unreliable. Therefore, idle connections that have been opened more than restartTimeoutSecs seconds ago are closed and re-opened by the scheduler thread.

minConnections must be less than or equal to maxConnections, and both must be at least 1. If a value less than 1800 (i.e. half an hour) is specified for restartTimeoutSecs, the extension will use a value of 1800 instead. If a value less than 60 (i.e. one minute) is specified for idleTimeoutSecs, the extension will use a value of 60 instead.

If you are building a web application or operate in a similar scenario where low latency is important, you can minimize latency by calling this verb once from your applications startup code and then call postgreSQL.connection.grab whenever you need to obtain a connection reference from the pool, rather than incurring the overhead associated with calling postgreSQL.connection.open every time you need a connection to the database.

See Also

postgreSQL.connection.grab

postgreSQL.connection.release

postgreSQL.connection.open

postgreSQL.pool.dispose

postgreSQL.pool.minimize

postgreSQL.util.buildConnInfoString