Upgrade Postgresql from 9.6 to 11 with different data directory I am trying to upgrade PostgreSQL version from 9.6 to 11. I am following this link. The problem is I have changed my default location of PostgreSQL data directory from /var/lib/postgresql/ to /opt/postgresql/. So when I am using pg_lsclusters it is returning following



When I am running the sudo pg_upgradecluster -m upgrade 9.6 main its returning following error

Error: move_conffile: required configuration file /var/lib/postgresql/11/main/postgresql.conf does not exist
Error: Could not create target cluster
You can specify a custom data_directory as an optional parameter to the command pg_upgradecluster:

pg_upgradecluster [-v newversion] oldversion name [newdatadir]


So for your case, it should be:

sudo pg_upgradecluster -m upgrade 9.6 main /opt/postgresql/11/main


Note that you must first remove any existing cluster at the specified location (/opt/postgresql/11/main) and create an empty directory with the correct owner before running pg_upgradecluster:

sudo pg_dropcluster --stop 11 main
sudo mkdir -p /opt/postgresql/11/main
sudo chown postgres:postgres /opt/postgresql/11/main