def _get_leader_connection_cursor(self, leader: Leader) -> Iterator[Union['cursor', 'Cursor[Any]']]:
        """Create a new database connection to the leader.

        .. note::
            Uses rewind user credentials because it has enough permissions to read files from PGDATA.
            Sets the options ``connect_timeout`` to ``3`` and ``statement_timeout`` to ``2000``.

        :param leader: object with information on the leader

        :yields: connection cursor object, note implementation varies depending on version of ``psycopg``.
        """
        conn_kwargs = leader.conn_kwargs(self._postgresql.config.rewind_credentials)
        conn_kwargs['dbname'] = self._postgresql.database
        with get_connection_cursor(connect_timeout=3, options="-c statement_timeout=2000", **conn_kwargs) as cur:
            yield cur
Create a new database connection to the leader.

        .. note::
            Uses rewind user credentials because it has enough permissions to read files from PGDATA.
            Sets the options ``connect_timeout`` to ``3`` and ``statement_timeout`` to ``2000``.

        :param leader: object with information on the leader

        :yields: connection cursor object, note implementation varies depending on version of ``psycopg``.
        
patroni/postgresql/slots.py