17

I'm trying to upgrade Postgresql from 9.2 to 9.3 in Fedora 18 using this command as the postgres user

$ pg_upgrade -b /bin -B /usr/pgsql-9.3/bin -d /var/lib/pgsql/data -D /var/lib/pgsql/9.3/data/ -j 2 -u postgres

The error in the log

command: "/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/var/lib/pgsql/data" -o "-p 50432 -b -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directory='/var/lib/pgsql'" start >> "pg_upgrade_server.log" 2>&1 waiting for server to start....FATAL: unrecognized configuration parameter "unix_socket_directory" .... stopped waiting pg_ctl: could not start server

As pointed by a_horse in the comments that parameter was replaced by unix_socket_directories (plural) in 9.3. But the server version being started is the old one 9.2:

$ /bin/pg_ctl --version
pg_ctl (PostgreSQL) 9.2.4

Any ideas?

3
  • 2
    That parameter has been renamed to unix_socket_directories: postgresql.org/docs/current/static/release-9-3.html#AEN114343
    – user1822
    Commented Sep 18, 2013 at 14:52
  • @a_horse That command tries to start version 9.2. Check the updated question
    – Clodoaldo
    Commented Sep 18, 2013 at 16:01
  • To explicitly see which parameter is being used in your distribution, you can run postgres --describe-config | grep -o 'unix_socket_director\w*'
    – Randall
    Commented Feb 6, 2017 at 22:55

2 Answers 2

31

I hacked the problem by running (as root):

mv /usr/bin/pg_ctl{,-orig}
echo '#!/bin/bash' > /usr/bin/pg_ctl
echo '"$0"-orig "${@/unix_socket_directory/unix_socket_directories}"' >> \
     /usr/bin/pg_ctl
chmod +x /usr/bin/pg_ctl

Run pg_upgrade as intended, then undo the hack:

    mv -f /usr/bin/pg_ctl{-orig,}

The problem is that pg_upgrade executes the program pg_ctrl with arguments that specify files in the old "unix_socket_directory" rather than the new "unix_socket_directories" (note the second is plural). This hack renames the original /usr/bin/pg_ctl to /usr/bin/pg_ctl-orig, and then creates a shell script in its place that simply calls the original pg_ctl program, passing all arguments with any strings "unix_socket_directory" changed to "unix_socket_directories".

In bash, one can change a portion of a string, say from bar to baz in a variable $foo, by using ${foo/bar/baz} (note this does not change the variable, but rather returns the variable's modified contents). Arrays can also be used with ${x/y/z} to retrieve an array with all of its contents replaced, all at once. The variable $@ is an array that contains all arguments passed to the program/script/function, so the new pg_ctl script executes the old one with all arguments changed from the old directory name to the new one.

6
  • 4
    this really allowed me to upgrade postgres 9.2 to 9.6 on Centos 7! Thanks! Commented Dec 8, 2017 at 19:17
  • 3
    Worked great for me going from 9.2 to 9.6. Thanks so much! No idea what I would have done without this answer!
    – SebK
    Commented May 15, 2018 at 8:18
  • 1
    Worked for me too, going from 9.2 to 9.6 on Centos 7 Commented Jul 19, 2018 at 8:40
  • 1
    Maybe explaining the trickery of the bash hack could help others deal with similar problems in future. This is some serious bash twisting :-)
    – xor007
    Commented Nov 30, 2018 at 14:27
  • 1
    Excellent & elegant solution, worked flawlessly for going from PostgreSQL 9.2 to 10.7 on CentOS 7
    – wfgeo
    Commented Feb 15, 2019 at 14:37
6

I've got the same problem. I was upgrading from Fedora Repo's 9.2.4 to PGDG 9.3. The source of the problem is that Fedora backports changes of parameter unix_socket_directory to unix_socket_directories (see https://bugzilla.redhat.com/show_bug.cgi?id=853353).

My solution is to rebuild the pg_upgrade from sources, with update to file contrib/pg_upgrade/server.c:199 where pg_upgrade checks for server version:

199:       (GET_MAJOR_VERSION(cluster->major_version) < 903) ?

, in my case i change it to:

199:       (GET_MAJOR_VERSION(cluster->major_version) < 900) ?

(see my patch file here).

2
  • Could you please explain why does this fix the issue (to the likes of myself, who are not overly familiar with the sources (beware of the understatement!))? Commented Sep 29, 2013 at 7:44
  • 4
    As per @a_horse comment above, upstream PostgreSQL have changed the parameter unix_socket_directory to unix_socket_directories in version 9.3. But the Fedora maintainer backports it to lower version. So, pg_upgrade from PGDG (PostgreSQL Global Development Group) YUM Repository expects that the 9.2.4 version accepts unix_socket_directory, but actually the 9.2.4 from Fedora YUM Repository accepts unix_socket_directories. In this case, because Fedora backports it into version 9.0 onwards, i changed it to use unix_socket_directories for version >= 9.0.
    – Ali Akbar
    Commented Sep 29, 2013 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.