pg_upgrade doesn't find config file I'm trying to upgrade PostgreSQL on Ubuntu Server from 9.6 to 10. This is the first time I'm doing this. The server doesn't contain any useful data yet but I want to make sure I can do this properly next time.

I followed the instructions in the manual. Here's what I did:


Installed the new packages for version 10
Stopped both versions on the server
Ran the pg_upgrade script:

sudo -u postgres /usr/lib/postgresql/10/bin/pg_upgrade -b /usr/lib/postgresql/9.6/bin -B /usr/lib/postgresql/10/bin -d /var/lib/postgresql/9.6/main/ -D /var/lib/postgresql/10/main/


This is the console output:

Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok

*failure*
Consult the last few lines of "pg_upgrade_server.log" for
the probable cause of the failure.

connection to database failed: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/lib/postgresql/.s.PGSQL.50432"?

could not connect to source postmaster started with the command:
"/usr/lib/postgresql/9.6/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/var/lib/postgresql/9.6/main/" -o "-p 50432 -b  -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directories='/var/lib/postgresql'" start
Failure, exiting


This is the contents of pg_upgrade_server.log:

command: "/usr/lib/postgresql/9.6/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/var/lib/postgresql/9.6/main/" -o "-p 50432 -b  -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directories='/var/lib/postgresql'" start &gt;&gt; "pg_upgrade_server.log" 2&gt;&amp;1
waiting for server to start....postgres: could not access the server configuration file "/var/lib/postgresql/9.6/main/postgresql.conf": No such file or directory
 stopped waiting
pg_ctl: could not start server
Examine the log output.


I'm totally confused now. What should I do?
You know what they say about the word assume

I assumed the config dir and data dir was the same.

Answer 1:

Change your command to this and it will work.

sudo -u postgres /usr/lib/postgresql/10/bin/pg_upgrade \
-b /usr/lib/postgresql/9.6/bin -B /usr/lib/postgresql/10/bin \
-d /var/lib/postgresql/9.6/main/ -D /var/lib/postgresql/10/main/
-o 'config_file=/etc/postgresql/9.6/main/postgresql.conf' \
-O 'config_file=/etc/postgresql/10/main/postgresql.conf'


we can provide the special config file location as an option

Also, I believe you have identified a default install issue or the documentation needs to be updated

The default install should create the config files in the datadir 

Answer 2:

Since this is play, try this too:  

sudo -u postgres pg_dropcluster 10 main
sudo -u postgres pg_upgradecluster 9.6 main


Keeping this, since it might help someone else.

The empty databases seem to have not been created yet. Or are in a different directory. That's why postgresql.conf is not found in the error message.

ls -l /var/lib/postgresql/9.6/main/postgresql.conf /var/lib/postgresql/10/main/postgresql.conf 

should show two files.

The equivalent initdb command for both versions should be run

pg_ctl -D /var/lib/postgresql/9.6/main initdb

pg_ctl -D /var/lib/postgresql/10/main initdb