cur = psycopg.ClientCursor(conn)
-You can also use `~ClientCursor` with autocommit mode to disable Extended
-Query Protocol and use Simple Query Protocol instead. This is useful for
-example when issuing `SHOW STATS` to a `pgbouncer` for example, since the
-`Pgbouncer Admin Console <https://www.pgbouncer.org/usage.html#admin-console>`_
-only support Simple Query Protocol.
-
-.. code:: python
-
- from psycopg import connect, ClientCursor
-
- conn = psycopg.connect(DSN, cursor_factory=ClientCursor, autocommit=True)
- cur = conn.cursor()
- cur.execute("SHOW STATS")
- cur.fetchall()
-
-
.. warning::
Client-side cursors don't support :ref:`binary parameters and return
to parametrize tables and fields names too, or entirely generic SQL
snippets.
+
+.. index::
+ single: PgBouncer
+ double: Query protocol; simple
+
+.. _simple-query-protocol:
+
+Simple query protocol
+^^^^^^^^^^^^^^^^^^^^^
+
+Using the `!ClientCursor` should ensure that psycopg will always use the
+`simple query protocol`__ for querying. In most cases, the choice of the
+fronted/backend protocol used is transparent on PostgreSQL. However, in some
+case using the simple query protocol is mandatory. This is the case querying
+the `PgBouncer admin console`__ for instance, which doesn't support the
+extended query protocol.
+
+.. __: https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-SIMPLE-QUERY
+.. __: https://www.pgbouncer.org/usage.html#admin-console
+
+.. code:: python
+
+ from psycopg import connect, ClientCursor
+
+ conn = psycopg.connect(ADMIN_DSN, cursor_factory=ClientCursor)
+ cur = conn.cursor()
+ cur.execute("SHOW STATS")
+ cur.fetchall()
+
+.. versionchanged:: 3.1.20
+ While querying using the `!ClientCursor` works well with PgBouncer, the
+ connection's COMMIT and ROLLBACK commands are only ensured to be executed
+ using the simple query protocol starting from Psycopg 3.1.20.
+
+ In previous versions you should use an autocommit connection in order to
+ query the PgBouncer admin console:
+
+ .. code:: python
+
+ from psycopg import connect, ClientCursor
+
+ conn = psycopg.connect(ADMIN_DSN, cursor_factory=ClientCursor, autocommit=True)
+ ...
+
+
.. index::
double: Cursor; Server-side
single: Portal
... .format(sql.Identifier(username), password))
+.. index::
+ single: PgBouncer
+ double: Query protocol; advanced
+
+.. _advanced-query-protocol:
+
+Extended query Protocol
+-----------------------
+
+In order to use :ref:`server-side-binding`, psycopg normally uses the
+`extended query protocol`__ to communicate with the backend.
+
+In certain context outside pure PostgreSQL, the extended query protocol is not
+supported, for instance to query the `PgBouncer admin console`__. In this case
+you should probably use a `ClientCursor`. See :ref:`simple-query-protocol` for
+details.
+
+.. __: https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
+.. __: https://www.pgbouncer.org/usage.html#admin-console
+
+
.. _multi-statements:
Multiple statements in the same query