Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psycopg2-binary 2.9.2 bundles wrong libpq version on aarch64 #1396

Closed
oar-spease opened this issue Dec 2, 2021 · 21 comments
Closed

psycopg2-binary 2.9.2 bundles wrong libpq version on aarch64 #1396

oar-spease opened this issue Dec 2, 2021 · 21 comments
Labels
wheel Bugs related to the wheel distribution, not happening installing from source

Comments

@oar-spease
Copy link

oar-spease commented Dec 2, 2021

  • OS: Docker container python:3.9-slim (Linux face723b8883 5.10.47-linuxkit 1 SMP PREEMPT Sat Jul 3 21:50:16 UTC 2021 aarch64 GNU/Linux)
  • Psycopg version: 2.9.2
  • Python version: 3.9
  • PostgreSQL version: Debian 14.0-1.pgdg110+1
  • pip version: 21.3.1

As the title says, psycopg2-binary is including the wrong libpq version. This causes the error "SCRAM authentication requires libpq version 10 or above"

The file appears to be /usr/local/lib/python3.9/site-packages/psycopg2_binary.libs/libpq-4fa63d26.so.5.9

The installation was pip install psycopg2-binary on a python:3.9-slim docker container, which to my knowledge is debian based.

Python 3.9.9 (main, Nov 17 2021, 12:25:33)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> psycopg2.__version__
'2.9.2 (dt dec pq3 ext lo64)'
>>> psycopg2.__libpq_version__
90623
@dvarrazzo
Copy link
Member

Yes, the problem is aarch64. We don't build the libpq from scratch on manylinux_2_24, we use the packaged version, and postgres doesn't have a repository where to fetch a more modern libpq version, so you get what debian gives.

Did we find in the wrong place?

@dvarrazzo dvarrazzo changed the title psycopg2-binary 2.9.2 bundles wrong libpq version psycopg2-binary 2.9.2 bundles wrong libpq version on aarch64 Dec 3, 2021
@dvarrazzo dvarrazzo added the wheel Bugs related to the wheel distribution, not happening installing from source label Dec 3, 2021
@oar-spease
Copy link
Author

Looking at https://packages.debian.org/sid/libpq-dev, it appears as though debian's repos should be able to provide libpq 14.1

@dvarrazzo
Copy link
Member

Have you got any way to install it on your system? If you manage we would be happy to upgrade the packages.

@oar-spease
Copy link
Author

I can have the docker container manually apt-get update && apt-get install -y libpq-dev, which gives libpq-dev 13.5-0+deb11u1 and libpq5:arm64 13.5-0+dev11u1, but psycopg2 does not use it.

@dvarrazzo
Copy link
Member

If you install psycopg2 instead of psycopg2-binary it will use them.

@oar-spease
Copy link
Author

I assume that's meant to be a temp fix? Just double checking, since we want deployments to be fast, which means we generally try to limit compilation from source as much as possible. It does, however, work.

@dvarrazzo
Copy link
Member

If PostgreSQL Debian packagers will package a more modern version we will use it. I don't know their reason behind not having an aarch64 distribution.

If you want to save the compilation time, and you said you can install a libpq in other ways, you can make a package to keep on a private pypi instance.

MasterKale added a commit to MasterKale/Docker-Django that referenced this issue Dec 16, 2021
Gonna try building from source instead to get a newer libpq (see psycopg/psycopg2#1396)
MasterKale added a commit to MasterKale/Docker-Django that referenced this issue Dec 23, 2021
* Remove django-redis

* Update to Python 3.10

* Run `pipenv update`

* Upgrade images

* Uninstall psycopg2-binary

Gonna try building from source instead to get a newer libpq (see psycopg/psycopg2#1396)

* Rearrange Dockerfile for better caching

* Switch to bare psycopg2

* Use Django's new Redis caching
@Borketh
Copy link

Borketh commented Apr 19, 2022

Here's my solution, this may or may not help some of you, @oar-spease especially.

Dockerfile

FROM python:3.10-slim as runtime

VOLUME /config
WORKDIR /app

COPY runtime-deps.sh .
RUN bash runtime-deps.sh 1> /dev/null && rm runtime-deps.sh

FROM python:3.10-slim as build

WORKDIR /app

RUN apt-get -qq update && apt-get -qq install curl libpq-dev gcc 1> /dev/null

RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/usr/local python3 -

COPY pyproject.toml .
RUN poetry install -nvvv --no-dev && mv $(poetry env info --path) /app/venv

FROM runtime

COPY --from=build /app/venv /app/venv
COPY fred *.env ./fred/

CMD ./venv/bin/python3 -m fred

runtime-deps.sh

#!/bin/bash
# This file is meant to be run in the Dockerfile to get the runtime dependencies
# if you run it outside, good luck

echo "Getting initial setup dependencies..." 1>&2
apt-get update
apt-get install software-properties-common ca-certificates gnupg curl -y

# add repo that adds libpq properly
echo "Adding repository for libpq..." 1>&2
curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null
add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main"
apt-get update

# install runtime dependencies
echo "Installing runtime dependencies..." 1>&2
apt-get install -y libpq5 tesseract-ocr

# we don't need this crap anymore
echo "Cleaning up..." 1>&2
apt-get remove -y software-properties-common gnupg curl
apt-get autopurge -y
rm -rf /var/lib/apt/lists/*
echo "All runtime dependencies handled!"

@ptman
Copy link

ptman commented May 5, 2022

@ptman
Copy link

ptman commented May 5, 2022

Right, the error message seems to be:

N: Skipping acquire of configured file 'main/binary-arm64/Packages' as repository 'http://apt.postgresql.org/pub/repos/apt stretch-pgdg InRelease' doesn't support architecture 'arm64'

@ptman
Copy link

ptman commented May 5, 2022

build-manylinux seems to run on ubuntu20.04, i.e. focal. why use stretch packages on arm64 when pgdg doesn't supply arm64 packages for stretch, but does for focal?

@Borketh
Copy link

Borketh commented May 6, 2022

As you can see in my example it also works on debian bullseye

@dvarrazzo
Copy link
Member

manylinux_2_24 images are build on Debian 9 (Stretch). pgdg packages for aarch64 are only available from Debian 10 on.

Is it possible to install Debian 10 or Ubuntu packages on Debian 9? If so let me know, possibly with a MR.

@mbanck
Copy link

mbanck commented May 19, 2022

@dvarrazzo why are you (or is manylinux) still using Debian stretch? Is there some roadmap to move to supported version of Debian?

@df7cb
Copy link
Contributor

df7cb commented May 19, 2022

apt.postgresql.org has been supporting arm64 (=aarch64) for some time now, but only for buster and newer. (I forgot why, but there was some reason that made stretch unsuitable for arm64 when I added that architecture.)

@dvarrazzo
Copy link
Member

@df7cb do you think it would be possible to backport at least the libpq5/libpq-dev packages to stretch?

I am aware that stretch is getting old; however Python binary packages are built "by design" on old-ish architectures in order to give the produced artifacts the maximum ABI compatibility.

Even if those packages didn't make it to the public apt.postgresql.org, but there was a way to generate them using our CI, it would be extremely useful. I'm not very experience with .deb packaging but it would be nice to have some help on that front 🙂

@mbanck
Copy link

mbanck commented May 19, 2022

But the non-arm64 binary packages appear to be fine, at least that is what I've been told, maybe they are built in a totally different way?

The problem with being API compatible is that things like SCRAM or target_session_attrs won't work with the bundled libpq and honestly, this is not about skipping major (library) versions - bullseye still has libpq.so.5, but shipping a recent minor version.

@df7cb
Copy link
Contributor

df7cb commented May 20, 2022

Stretch is 6 weeks away from the LTS EOL, so I don't think it makes sense to fix that now, only to tear it down again at the end of June.

https://wiki.debian.org/LTS/

@ptman
Copy link

ptman commented May 20, 2022

There's ELTS: https://wiki.debian.org/LTS/Extended if one really wants to support it.

@jesseinit
Copy link

I'm facing an issue where when I install psycopg2, then build and run the container with docker run, I notice that libpq_version == 130009 but when I run the same image via docker-compose then access the shell for the container, I notice libpq_version == 90624.

How do I fix this?

@dvarrazzo
Copy link
Member

Fixed by #1545. To be released in 2.9.6.

pking-moj referenced this issue in ministryofjustice/laa-crime-application-store Jan 15, 2024
Bumps [psycopg2-binary](https://github.com/psycopg/psycopg2) from 2.9.7
to 2.9.9.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/psycopg/psycopg2/blob/master/NEWS">psycopg2-binary's
changelog</a>.</em></p>
<blockquote>
<h2>Current release</h2>
<p>What's new in psycopg 2.9.9
^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>Add support for Python 3.12.</li>
<li>Drop support for Python 3.6.</li>
</ul>
<p>What's new in psycopg 2.9.8
^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>Wheel package bundled with PostgreSQL 16 libpq in order to add
support for
recent features, such as <code>sslcertmode</code>.</li>
</ul>
<p>What's new in psycopg 2.9.7
^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>Fix propagation of exceptions raised during module initialization

(:ticket:<code>[#1598](https://github.com/psycopg/psycopg2/issues/1598)</code>).</li>
<li>Fix building when pg_config returns an empty string
(:ticket:<code>[#1599](https://github.com/psycopg/psycopg2/issues/1599)</code>).</li>
<li>Wheel package bundled with OpenSSL 1.1.1v.</li>
</ul>
<p>What's new in psycopg 2.9.6
^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>Package manylinux 2014 for aarch64 and ppc64le platforms, in order
to
include libpq 15 in the binary package
(:ticket:<code>[#1396](https://github.com/psycopg/psycopg2/issues/1396)</code>).</li>
<li>Wheel package bundled with OpenSSL 1.1.1t.</li>
</ul>
<p>What's new in psycopg 2.9.5
^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>Add support for Python 3.11.</li>
<li>Add support for rowcount in MERGE statements in binary packages

(:ticket:<code>[#1497](https://github.com/psycopg/psycopg2/issues/1497)</code>).</li>
<li>Wheel package bundled with OpenSSL 1.1.1r and PostgreSQL 15
libpq.</li>
</ul>
<p>What's new in psycopg 2.9.4
^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>Fix <code>~psycopg2.extras.register_composite()</code>,
<code>~psycopg2.extras.register_range()</code> with customized
:sql:<code>search_path</code>

(:ticket:<code>[#1487](https://github.com/psycopg/psycopg2/issues/1487)</code>).</li>
<li>Handle correctly composite types with names or in schemas requiring
escape.</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/psycopg/psycopg2/commit/ad5bee7054519d87f25bc5828c502b2ebe197049"><code>ad5bee7</code></a>
chore: bump version number to 2.9.9</li>
<li><a
href="https://github.com/psycopg/psycopg2/commit/37d1de1c8f446478666258f4370315f554efa16f"><code>37d1de1</code></a>
chore: add support for Python 3.12</li>
<li><a
href="https://github.com/psycopg/psycopg2/commit/abf2723c0a9d89740b433bf49b82ad765e87d5d4"><code>abf2723</code></a>
chore: drop support for Python 3.6</li>
<li><a
href="https://github.com/psycopg/psycopg2/commit/2da65a715c71fa5a242fce016835ba500376bf28"><code>2da65a7</code></a>
chore: drop leftover Python 2.7 import aliases from setup.py</li>
<li><a
href="https://github.com/psycopg/psycopg2/commit/3fa60fd26839a7e8b083ed3eb3dc592a0f2604f6"><code>3fa60fd</code></a>
chore: bump doc requirement complained by dependabot</li>
<li><a
href="https://github.com/psycopg/psycopg2/commit/1c1484e43bdd4927ac5725d4f250b198fbe7600f"><code>1c1484e</code></a>
ci: better interaction with scaleway build server</li>
<li><a
href="https://github.com/psycopg/psycopg2/commit/c81cec604f467dfb4fc87c9cbaaf4b758b4ca740"><code>c81cec6</code></a>
chore: bump to next dev release</li>
<li><a
href="https://github.com/psycopg/psycopg2/commit/7fe8cb77ca68a06c96d4551c6c9f8cab33904d2a"><code>7fe8cb7</code></a>
chore: bump docs requirements dependabot complains about</li>
<li><a
href="https://github.com/psycopg/psycopg2/commit/b39d5d64923a3e321672847bd57c002145f57430"><code>b39d5d6</code></a>
chore: bundle libpq 16</li>
<li><a
href="https://github.com/psycopg/psycopg2/commit/921510d5be7bc2f2dbf7ff3ce613ad0623de79f2"><code>921510d</code></a>
docs: replace &quot;compiled against&quot; with &quot;bundled with&quot;
in news file</li>
<li>Additional commits viewable in <a
href="https://github.com/psycopg/psycopg2/compare/2.9.7...2.9.9">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=psycopg2-binary&package-manager=pip&previous-version=2.9.7&new-version=2.9.9)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wheel Bugs related to the wheel distribution, not happening installing from source
Projects
None yet
Development

No branches or pull requests

7 participants