Search code examples
postgresqldockerpg-dumppg-dumpall

Can I use pg_dumpall withtout installing postgresQL?


I tried in my docker container(from alpine3.6) to run command to install pg_dumpall I've seen in the web:

apk update && apk upgrade

and then

apk add --no-cache postgresql-client-common

and finally

apk add --no-cache postgresql-client

Only the last of the two installs I tried worked (the one without common) but I still won't have pg_dump or pg_dumpall in my binaries.


Solution

  • Each alpine version has different postgresql-client. For myself I wrote those logic:

    ARG PSQL_VERSION=0
    RUN if [ "$PSQL_VERSION" = "13" ]; then \
            echo "http://dl-cdn.alpinelinux.org/alpine/v3.14/main" >> /etc/apk/repositories; \
        elif [ "$PSQL_VERSION" = "12" ]; then \
            echo "http://dl-cdn.alpinelinux.org/alpine/v3.12/main" >> /etc/apk/repositories; \
        elif [ "$PSQL_VERSION" = "11" ]; then \
            echo "http://dl-cdn.alpinelinux.org/alpine/v3.10/main" >> /etc/apk/repositories; \
        elif [ "$PSQL_VERSION" = "10" ]; then \
                echo "http://dl-cdn.alpinelinux.org/alpine/v3.8/main" >> /etc/apk/repositories; \
        fi
    RUN apk update
    RUN apk --no-cache add postgresql-client
    

    And now you can pass needed client version:

    docker build -t backuper --build-arg PSQL_VERSION=12 .