SessionPool Object

Note

This object is an extension to the DB API.

SessionPool.acquire(user=None, password=None, cclass=None, purity=cx_Oracle.ATTR_PURITY_DEFAULT, tag=None, matchanytag=False)

Acquire a connection from the session pool and return a connection object.

The user and password arguments may not be specified if the pool is homogeneous. In that case an exception will be raised.

The cclass argument, if specified, should be a string corresponding to the connection class for database resident connection pooling (DRCP).

The purity argument is expected to be one of ATTR_PURITY_NEW, ATTR_PURITY_SELF, or ATTR_PURITY_DEFAULT.

The tag argument, if specified, is expected to be a string and will limit the sessions that can be returned from a session pool unless the matchanytag argument is set to True. In that case sessions with the specified tag will be preferred over others, but if no such sessions are available a session with a different tag may be returned instead. In any case, untagged sessions will always be returned if no sessions with the specified tag are available. Sessions are tagged when they are released back to the pool.

SessionPool.busy

This read-only attribute returns the number of sessions currently acquired.

SessionPool.drop(connection)

Drop the connection from the pool which is useful if the connection is no longer usable (such as when the session is killed).

SessionPool.dsn

This read-only attribute returns the TNS entry of the database to which a connection has been established.

SessionPool.homogeneous

This read-write boolean attribute indicates whether the pool is considered homogeneous or not. If the pool is not homogeneous different authentication can be used for each connection acquired from the pool.

SessionPool.increment

This read-only attribute returns the number of sessions that will be established when additional sessions need to be created.

SessionPool.max

This read-only attribute returns the maximum number of sessions that the session pool can control.

SessionPool.max_lifetime_session

This read-write attribute returns the lifetime (in seconds) for all of the sessions in the pool. Sessions in the pool are terminated when they have reached their lifetime. If timeout is also set, the session will be terminated if either the idle timeout happens or the max lifetime setting is exceeded. This attribute is only available in Oracle Database 12.1.

New in version 5.3.

SessionPool.min

This read-only attribute returns the number of sessions with which the session pool was created and the minimum number of sessions that will be controlled by the session pool.

SessionPool.name

This read-only attribute returns the name assigned to the session pool by Oracle.

SessionPool.opened

This read-only attribute returns the number of sessions currently opened by the session pool.

SessionPool.release(connection, tag=None)

Release the connection back to the pool. This will be done automatically as well if the connection object is garbage collected.

If a tag is specified, the session will be tagged (or retagged) with the specified value before being returned to the pool.

SessionPool.stmtcachesize

This read-write attribute specifies the size of the statement cache that will be used as the starting point for any connections that are created by the session pool. Once created, the connection’s statement cache size can only be changed by setting the stmtcachesize attribute on the connection itself.

New in version 6.0.

SessionPool.timeout

This read-write attribute indicates the time (in seconds) after which idle sessions will be terminated in order to maintain an optimum number of open sessions.

SessionPool.tnsentry

This read-only attribute returns the TNS entry of the database to which a connection has been established.

SessionPool.username

This read-only attribute returns the name of the user which established the connection to the database.