patroni.postgresql.connection module
- class patroni.postgresql.connection.ConnectionPool
Bases:
objectHelper class to manage named connections from Patroni to PostgreSQL.
The instance keeps named
NamedConnectionobjects and parameters that must be used for new connections.- __init__() None
Create an instance of
ConnectionPoolclass.
- property conn_kwargs: Dict[str, Any]
Connection parameters that must be used for new
psycopgconnections.
- get(name: str, kwargs_override: Optional[Dict[str, Any]] = None) patroni.postgresql.connection.NamedConnection
Get a new named
NamedConnectionobject from the pool.Note
Creates a new
NamedConnectionobject if it doesn’t yet exist in the pool.- Parameters
name – name of the connection.
kwargs_override –
dictobject with connection parameters that should be different from default values provided byconn_kwargs.
- Returns
NamedConnectionobject.
- class patroni.postgresql.connection.NamedConnection(pool: patroni.postgresql.connection.ConnectionPool, name: str, kwargs_override: Optional[Dict[str, Any]])
Bases:
objectHelper class to manage
psycopgconnections from Patroni to PostgreSQL.- Variables
server_version – PostgreSQL version in integer format where we are connected to.
- __init__(pool: patroni.postgresql.connection.ConnectionPool, name: str, kwargs_override: Optional[Dict[str, Any]]) None
Create an instance of
NamedConnectionclass.- Parameters
pool – reference to a
ConnectionPoolobject.name – name of the connection.
kwargs_override –
dictobject 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) bool
Close the psycopg connection to postgres.
- Parameters
silent – whether the method should not write logs.
- Returns
Trueifpsycopgconnection was closed,Falseotherwise.``
- get() Union[connection, Connection[Any]]
Get
psycopg/psycopg2connection object.Note
Opens a new connection if necessary.
- Returns
psycopgorpsycopg2connection object.
- query(sql: str, *params: Any) List[Tuple[Any, ...]]
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
Errorif had issues while executing sql.PostgresConnectionException: if had issues while connecting to the database.
- patroni.postgresql.connection.get_connection_cursor(**kwargs: Any) Iterator[Union[cursor, Cursor[Any]]]