postgreSQL.connection.grab

Syntax

postgreSQL.connection.grab (poolname)

Params

poolname is a string containing the global name for the pool.

Action

Grab a connection from the specified pool.

Returns

A reference to the connection.

Examples

connectionRef = postgreSQL.connection.grab ("mytestpool")

« 63009680

Notes

This verb secures exclusive access to an idle connection in the specified pool, or if all existing connections in the pool are already in use, it opens a new connection to the database server. If the total number of connections has reached the limit given by the maxConnections parameter of the postgreSQL.pool.create, no further connections will be created and this verb will return a script error instead.

The grabbed connection automatically starts a new transaction and sets the transaction isolation level to serializable. Call postgreSQL.connection.commit to finalize any changes you made to the database. Call postgreSQL.connection.rollback to roll back all changes you made since last calling postgreSQL.connection.commit or since grabbing the connection. Any changes not yet committed when releasing the connection will be rolled back automatically. To turn off this default behaviour, you can switch to auto-commit mode by calling postgreSQL.connection.setAutoCommit.

To conserve system resources both on the client and the server, it is critically important that you call postgreSQL.connection.release when you no longer need the connection. Therefore, all code executed after grabbing the connection should run inside a try statement with the corresponding else block taking care of releasing the connection even in case a script error is encountered.

See Also

postgreSQL.pool.create

postgreSQL.connection.release

postgreSQL.connection.commit

postgreSQL.connection.rollback

postgreSQL.connection.setAutoCommit