I was inspired by the following check:

        # Check that the database name is present
        sudo_psql_and_log(vm, 'postgresql_test_db --command="select datname from pg_database limit 1"')

which is probably wrong too. I'll fix that.