rockstor / rockstor-core

Linux/BTRFS based Network Attached Storage(NAS)
http://rockstor.com/docs/contribute_section.html
GNU General Public License v3.0
557 stars 138 forks source link

update to psycopg 3 #2740

Closed phillxnet closed 11 months ago

phillxnet commented 1 year ago

As part of our ongoing modernisation, and post our move to Django 4.2, we can adopt the async capable psycopg 3.

This is a requirement for: "Django Server Sent Events to provide live data requirements" #2739

Project Docs: https://www.psycopg.org/psycopg3/docs/

Fun fact: there is no psycopg3 package, only psycopg!

PyPi: https://pypi.org/project/psycopg/ Latest is 3.1.13 Released: Nov 17, 2023

https://www.psycopg.org/psycopg3/docs/basic/install.html#supported-systems

Python: from version 3.8 to 3.12

PostgreSQL: from version 10 to 16

Pure Python installation

https://www.psycopg.org/psycopg3/docs/basic/install.html#pure-python-installation

In order to use the pure Python installation you will need the libpq installed in the system: for instance on Debian system you will probably need:

sudo apt install libpq5

The libpq is the client library used by psql, the PostgreSQL command line client, to connect to the database. On most systems, installing psql will install the libpq too as a dependency.

Differences from psycopg2

https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html#differences-from-psycopg2

phillxnet commented 11 months ago

Our existing use of psycopg2 is now one of our older dependencies. Given we are now on the indicated Django 4.2 we have the following constraint re psycopg 3:

https://django.readthedocs.io/en/latest/releases/4.2.html#psycopg-3-support

Psycopg 3 support Django now supports psycopg version 3.1.8 or higher. To update your code, install the psycopg library, you don’t need to change the ENGINE as django.db.backends.postgresql supports both libraries.

Support for psycopg2 is likely to be deprecated and removed at some point in the future.

Be aware that psycopg 3 introduces some breaking changes over psycopg2. As a consequence, you may need to make some changes to account for differences from psycopg2.

phillxnet commented 11 months ago

Adjusting our pinning to a 3 major version only: "~3" we have the following:

lbuildvm:/opt/rockstor # poetry update
Updating dependencies
Resolving dependencies... (7.9s)

Writing lock file

Package operations: 1 install, 1 update, 1 removal

  • Removing psycopg2 (2.8.6)
  • Updating certifi (2023.7.22 -> 2023.11.17)
  • Installing psycopg (3.1.13)

So we have one incidental update of:

PyPi.org: https://pypi.org/project/certifi/ This is a single release version update:

Our new psycopg (3) has the following, non unique dependencies:

psycopg 3.1.13 PostgreSQL database adapter for Python
├── typing-extensions >=4.1
└── tzdata *
phillxnet commented 11 months ago

Tests

lbuildvm:/opt/rockstor # poetry run python -Wa .venv/bin/django-admin test
Found 0 test(s).
System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
lbuildvm:/opt/rockstor/src/rockstor # poetry run django-admin test -v 2
...
----------------------------------------------------------------------
Ran 278 tests in 40.166s

OK
Destroying test database for alias 'default' ('test_storageadmin')...
Destroying test database for alias 'smart_manager' ('test_smartdb')...
phillxnet commented 11 months ago

Closing as: Fixed by #2753