Upgrade PostgreSQL 9.5 to 9.6 with PostGIS - pg_upgrade
The problem is that the postgis extension version in the old cluster is not the same as the library version in the new one. So when it tries to migrate the database, it can't find the older version of the extension.
To fix this, for each my_database
that has the postgis extension installed, run:
psql my_database postgres -c 'ALTER EXTENSION postgis UPDATE TO "2.3.2";'
in the old cluster. Then run pg_update.