Fixed #33308 -- Added support for psycopg version 3.

Thanks Simon Charette, Tim Graham, and Adam Johnson for reviews.

Co-authored-by: Florian Apolloner <florian@apolloner.eu>
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
This commit is contained in:
Daniele Varrazzo 2022-12-01 20:23:43 +01:00 committed by Mariusz Felisiak
parent d44ee518c4
commit 09ffc5c121
42 changed files with 673 additions and 223 deletions

View file

@ -114,11 +114,21 @@ below for information on how to set up your database correctly.
PostgreSQL notes
================
Django supports PostgreSQL 12 and higher. `psycopg2`_ 2.8.4 or higher is
required, though the latest release is recommended.
Django supports PostgreSQL 12 and higher. `psycopg`_ 3.1+ or `psycopg2`_ 2.8.4+
is required, though the latest `psycopg`_ 3.1+ is recommended.
.. _psycopg: https://www.psycopg.org/psycopg3/
.. _psycopg2: https://www.psycopg.org/
.. note::
Support for ``psycopg2`` is likely to be deprecated and removed at some
point in the future.
.. versionchanged:: 4.2
Support for ``psycopg`` 3.1+ was added.
.. _postgresql-connection-settings:
PostgreSQL connection settings
@ -199,12 +209,12 @@ level`_. If you need a higher isolation level such as ``REPEATABLE READ`` or
``SERIALIZABLE``, set it in the :setting:`OPTIONS` part of your database
configuration in :setting:`DATABASES`::
import psycopg2.extensions
from django.db.backends.postgresql.psycopg_any import IsolationLevel
DATABASES = {
# ...
'OPTIONS': {
'isolation_level': psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE,
'isolation_level': IsolationLevel.SERIALIZABLE,
},
}
@ -216,6 +226,10 @@ configuration in :setting:`DATABASES`::
.. _isolation level: https://www.postgresql.org/docs/current/transaction-iso.html
.. versionchanged:: 4.2
``IsolationLevel`` was added.
Indexes for ``varchar`` and ``text`` columns
--------------------------------------------
@ -244,7 +258,7 @@ Server-side cursors
When using :meth:`QuerySet.iterator()
<django.db.models.query.QuerySet.iterator>`, Django opens a :ref:`server-side
cursor <psycopg2:server-side-cursors>`. By default, PostgreSQL assumes that
cursor <psycopg:server-side-cursors>`. By default, PostgreSQL assumes that
only the first 10% of the results of cursor queries will be fetched. The query
planner spends less time planning the query and starts returning results
faster, but this could diminish performance if more than 10% of the results are