postgresqlalpine-linuxalpine-package-keeper

Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory)


I'm trying to upgrade postgres locally so I don't get a version mismatch error. This is what i do:

echo "http://dl-5.alpinelinux.org/alpine/v3.5/main" >> /etc/apk/repositories;
apk update

bash-4.3# apk add postgresql-dev
(1/4) Installing libressl2.4-libtls (2.4.4-r0)
(2/4) Installing libressl-dev (2.4.4-r0)
(3/4) Installing postgresql-libs (9.6.5-r0)
(4/4) Installing postgresql-dev (9.6.5-r0)
Executing busybox-1.24.2-r13.trigger
OK: 353 MiB in 108 packages
bash-4.3# pg_dump
bash: /usr/bin/pg_dump: No such file or directory

I'm at a loss - any idea what the problem is please?


Solution

  • Just a guess but I guess you've not installed postgresql. In order to use the pg_dump you must have installed this, or if you do have it already and I'm wrong try reinstalling it like so:

    bash-4.3# apk del postgresql
    (1/4) Purging postgresql (9.6.5-r0)
    (2/4) Purging postgresql-client (9.6.5-r0)
    (3/4) Purging libedit (20170329.3.1-r2)
    (4/4) Purging libxml2 (2.9.4-r4)
    Executing busybox-1.26.2-r5.trigger
    OK: 37 MiB in 25 packages
    bash-4.3# apk add postgresql
    (1/4) Installing libedit (20170329.3.1-r2)
    (2/4) Installing postgresql-client (9.6.5-r0)
    (3/4) Installing libxml2 (2.9.4-r4)
    (4/4) Installing postgresql (9.6.5-r0)
    Executing busybox-1.26.2-r5.trigger
    OK: 53 MiB in 29 packages
    bash-4.3# pg_dump
    pg_dump: [archiver (db)] connection to database "root" failed: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
    bash-4.3# 
    

    As you can see from above pg_dump is working because it is in the postgresql package even though as listed on alpine packages site it should be within the postgresql-client package as shown here but it doesn't work unless postgres is installed. If you can't have a full postgres installation, I recommend this workaround which is a bit unclean, install postgres, backup the pg_dump binary, uninstall postgres then restore pg_dump like so:

    bash-4.3# apk add postgresql
    (1/2) Installing libxml2 (2.9.4-r4)
    (2/2) Installing postgresql (9.6.5-r0)
    Executing busybox-1.26.2-r5.trigger
    OK: 53 MiB in 29 packages
    bash-4.3# cp /usr/bin/pg_dump /usr/bin/pg_dump
    pg_dump     pg_dumpall  
    bash-4.3# cp /usr/bin/pg_dump /usr/bin/pg_dump.back
    bash-4.3# cp /usr/bin/pg_dumpall /usr/bin/pg_dumpall.back
    bash-4.3# apk del postgresql
    (1/2) Purging postgresql (9.6.5-r0)
    (2/2) Purging libxml2 (2.9.4-r4)
    Executing busybox-1.26.2-r5.trigger
    OK: 38 MiB in 27 packages
    bash-4.3# mv /usr/bin/pg_dump.back /usr/bin/pg_dump
    bash-4.3# mv /usr/bin/pg_dumpall.back /usr/bin/pg_dumpall
    bash-4.3# pg_dump
    pg_dump: [archiver (db)] connection to database "root" failed: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
    bash-4.3# 
    

    It is not ideal but it has worked for me in the past