Why does restoring postgresql database from dump produce errors I did the following commands:

pg_dumpall --clean | gzip &gt; db.gz
gunzip db.gz
psql &lt; db


I expected the third command (loading the database back) to just run with zero errors, but I got some errors:

ERROR:  multiple primary keys for table "pga_exception" are not allowed
ERROR:  multiple primary keys for table "pga_job" are not allowed


There are more errors than those listed, but they are a combination of primary key violations, constraints already existing, and triggers already existing.  Why would recreating a database from a backup sql dump produce errors?
pg_dumpall --clean will not issue DROP DATABASE statements for databases like template1 or postgres that have been created by initdb at cluster initialization time.

However it will dump the contents of these databases if you created any objects in it (by default they're empty). So when restoring the result of pg_dumpall --clean into the same instance, it's likely that such errors will occur if these databases happen to have contents.