The backend doesnot save the name of the template database used by "CREATE DATABASE". pg_dump, pg_dumpall have hard code like this: appendPQExpBuffer(buf, " WITH TEMPLATE = template0"); That's why you found the template database is always `template0`. If the backend saves the name of the template database, and dump the database as "CREATE DATABASE foo WITH TEMPLATE 'bar';", dump and restore should be careful to dump/restore 'bar' before 'foo'. If 'bar' is modified after the "CREATE DATABASE" command, things will be more complicated. If you have not modified system catalogs in template1, using template0 in dump should cause no problem. Regrads, William ZHANG