Why changing the database owner doesn't change the owner in PostgreSQL dump? I was exporting a database using pg_dump command when I realized that the owner of the database had to be changed. So I change it, and make extra sure that the newuser is correct. Then try the command again:

pg_dump -h localhost -U postgres database_name -f mydb.dump


But this didn't work. The output file still identified the owner as the olduser. Why could this be happening? How can I make sure this doesn't happen?
The way you are invoking pg_dump (without -C), the database metadata is not dumped at all.

Use this:

pg_dump -h localhost -U postgres database_name -C -f mydb.dump


This will add CREATE DATABASE and ALTER DATABASE ... OWNER TO to your dump.