patroni.postgresql.connection module

class patroni.postgresql.connection.ConnectionPoolView on GitHub

Bases: object

Helper class to manage named connections from Patroni to PostgreSQL.

The instance keeps named NamedConnection objects and parameters that must be used for new connections.

__init__() NoneView on GitHub

Create an instance of ConnectionPool class.

close() NoneView on GitHub

Close all named connections from Patroni to PostgreSQL registered in the pool.

property conn_kwargs: Dict[str, Any]

Connection parameters that must be used for new psycopg connections.

get(name: str, kwargs_override: Dict[str, Any] | None = None) NamedConnectionView on GitHub

Get a new named NamedConnection object from the pool.

Note

Creates a new NamedConnection object if it doesn’t yet exist in the pool.

Parameters:
  • name – name of the connection.

  • kwargs_overridedict object with connection parameters that should be different from default values provided by conn_kwargs.

Returns:

NamedConnection object.

class patroni.postgresql.connection.NamedConnection(pool: ConnectionPool, name: str, kwargs_override: Dict[str, Any] | None)View on GitHub

Bases: object

Helper class to manage psycopg connections from Patroni to PostgreSQL.

Variables:

server_version – PostgreSQL version in integer format where we are connected to.

__init__(pool: ConnectionPool, name: str, kwargs_override: Dict[str, Any] | None) NoneView on GitHub

Create an instance of NamedConnection class.

Parameters:
  • pool – reference to a ConnectionPool object.

  • name – name of the connection.

  • kwargs_overridedict object with connection parameters that should be different from default values provided by connection pool.

property _conn_kwargs: Dict[str, Any]

Connection parameters for this NamedConnection.

close(silent: bool = False) boolView on GitHub

Close the psycopg connection to postgres.

Parameters:

silent – whether the method should not write logs.

Returns:

True if psycopg connection was closed, False otherwise.``

get() connection | Connection[Any]View on GitHub

Get psycopg/psycopg2 connection object.

Note

Opens a new connection if necessary.

Returns:

psycopg or psycopg2 connection object.

query(sql: str, *params: Any) List[Tuple[Any, ...]]View on GitHub

Execute a query with parameters and optionally returns a response.

Parameters:
  • sql – SQL statement to execute.

  • params – parameters to pass.

Returns:

a query response as a list of tuples if there is any.

Raises:

Error if had issues while executing sql.

PostgresConnectionException: if had issues while connecting to the database.

server_version: int
patroni.postgresql.connection.get_connection_cursor(**kwargs: Any) Iterator[cursor | Cursor[Any]]View on GitHub