Search code examples
djangoupgradepsycopg2

Psycopg2: to upgrade or not to upgrade


I've just upgraded my development virtual environment from Django 1.11 to the latest 2 release (2.2.8), and upgraded various well-known apps and django support also to the latest. All seems good after fixing various backward-incompatibilities.

Now I'm reviewing pip list -o results, to see what hasn't been upgraded. Most are application codes that I can review myself. However, psycopg2 is an essential bit of "plumbing" between Django and Postgresql (which I've just upgraded to 12). I have 2.7.3.2 installed. The latest is 2.8.4. I don't have any feel for what upgrading it means or does or fixes, and what any problems might look like.

Am I right to assume that upgrade-installing Django would have upgraded Psycopg2 if the Django version wasn't happy with what was already installed? Where do I find out what is recommended for this version of Django? And more generally, should I upgrade it anyway, and if so to the most recent 2.7 or the most recent 2.8? (FWIW I note Centos 7.7 is shipping a mere 2.5.1 !)


Solution

  • Django 2.2 supports PostgreSQL 9.4 and higher. psycopg2 2.5.4 or higher is required, though the latest release is recommended.

    No, there is no need to upgrade unless specific features / bug fixes are required.

    Although my personal preference is to keep up with the latest versions, especially in dev (of course, reviewing that all dependencies support it).

    Yes, you will need to upgrade psycopg2 if you want to work with Postgresql 12, as support for postgresql 12 was added only since psycopg2 2.8.4.

    Such core packages are well developed, maintain backwards compatibility, basic functionality barely changes.

    One more note: psycopg2 was split into two packages (more separate after 2.8) - psycopg2 and psycopg2-binary. To not dig into details, this is suggested options to be set in requirements.txt (if you are using virtualenv):

    • for the start - psycopg2-binary
    • if any ssl issues, or want to build from source - then set psycopg2

    Looks like you are using system-wide python packages installation, provided by os distribution repositories.

    While would not suggest rushing into switching, would definitely recommend to look into using virtualenv (with helpers such as pipenv or virtualenwrapper) to have nice local python environment individually for each project with packages installed directly from pypi and not bound to os vendor.