Add plpython3 Extension to Postgres/timescaledb Alpine Docker Image
Asked Answered
C

2

10

I try to add the plpython3 extension to my timescaledb/postgres (based on linux alpine) image:

FROM timescale/timescaledb:0.9.0-pg10

RUN set -ex \
    && apk add --no-cache --virtual .plpython3-deps --repository http://nl.alpinelinux.org/alpine/edge/testing \
    postgresql-plpython3

When I try to create the extension I get the following error:

postgres=# CREATE EXTENSION plpython3u;
ERROR:  could not open extension control file "/usr/local/share/postgresql/extension/plpython3u.control": No such file or directory

But when I search for the files inside my container I can find them within a different directory:

/ # find / -name '*plpy*'
/usr/lib/postgresql/plpython3.so
/usr/share/postgresql/extension/plpython3u.control
/usr/share/postgresql/extension/plpython3u--1.0.sql
/usr/share/postgresql/extension/plpython3u--unpackaged--1.0.sql

How can I install postgresql-plpython3 to a different directory or configure postgres to recognize my added extension?

Update

When I just mv the files to /usr/local/share/postgresql/extension I get the error:

postgres=# CREATE EXTENSION plpython3u;
ERROR:  could not access file "$libdir/plpython3": No such file or directory

Update 2

So the issue with $libdir was that pg_config --pkglibdir points to /usr/local/lib/postgresql but plpython3.so is inside /usr/lib/postgresql. When I move everything to the according /usr/local directories I can successfully create the extension.

This leads to the question where I hope to find an answer. How can I install postgresql-plpython3 to /usr/local/... instead of /usr/...?

Correa answered 20/3, 2018 at 8:26 Comment(1)
try one of them in your dockerfile COPY pg_config /usr/local/bin/pg_config RUN chmod a+x /usr/local/bin/pg_config #using try it # RUN sed -i '/PKGLIBDIR = /usr/local/lib/postgresql/c\/PKGLIBDIR = /usr/share/postgresql' /usr/local/bin/pg_config #second option create semi link # RUN ln -s /usr/share/postgresql/extension/plpython3u.control /usr/local/share/postgresql/extension/plpython3u.controlDeconsecrate
H
7

I am fairly certain that if you use prebuilt packages you are stuck with hardcoded installation paths.

The easiest way around your problem is to create symlinks after installation:

FROM timescale/timescaledb:0.9.0-pg10

RUN set -ex \
    && apk add --no-cache --virtual .plpython3-deps --repository http://nl.alpinelinux.org/alpine/edge/testing \
    postgresql-plpython3 \
    && ln -s /usr/lib/postgresql/plpython3.so /usr/local/lib/postgresql/plpython3.so \
    && ln -s /usr/share/postgresql/extension/plpython3u.control /usr/local/share/postgresql/extension/plpython3u.control \
    && ln -s /usr/share/postgresql/extension/plpython3u--1.0.sql /usr/local/share/postgresql/extension/plpython3u--1.0.sql \
    && ln -s /usr/share/postgresql/extension/plpython3u--unpackaged--1.0.sql /usr/local/share/postgresql/extension/plpython3u--unpackaged--1.0.sql
Hautegaronne answered 4/4, 2019 at 11:45 Comment(0)
L
1

Just configure your postgresql.conf to load the extension shared libraries from the expected path.

plpython3u.library_path = '/usr/lib'
Linkoski answered 14/6, 2023 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.