I just want to upgrade to the OS and Postgres that is supported.If I just stop the service on both VMs and upgrade Ubuntu, then start Postgres, will it work or I should go with clean install and dump/restore?
Personally I find the concept of upgrading an O/S to be distasteful, especially when using VMs. Build out the new environment, migrate the data, then destroy the old one. In any case I would hope upgrading to 18.04 wouldn’t automatically upgrade PostgreSQL.
For me, the two main questions are whether to use pg_dump or pg_upgrade, and whether to upgrade PostgreSQL before or after upgrading the OS. Upgrading both simultaneously isn’t a valid choice, even if you could figure out a way to actually make that possible. Either way a pg_basebackup and restoring that is probably the simplest way to get the database itself moved from one server to the other.
David J.