This example upgrades PostgreSQL 9.4 to 9.6. Substitute the versions you're upgrading to/from as needed below.
Run the following command to make a backup of all postgres data in a local file:
docker exec -i hqservice_postgres_1 pg_dumpall -U commcarehq | gzip > pg-backup.sql.gz