"Josh Berkus" <josh@agliodbs.com> writes:
> Trying to remove template1 to restore it using an undamaged template0
> seems to be a catch-22 with no way out. Help!
There are defenses in place that are intended to prevent you from
accidentally shooting yourself in the foot. Quoting from the source:
* Disallow dropping a DB that is marked istemplate. This is just to * prevent people from accidentally dropping
template0or template1; * they can do so if they're really determined ...
Offhand I think you have to (a) make sure you have a spare database
available to issue the DROP DATABASE from, and (b) clear the
datistemplate flag from template1's pg_database row.
("Ensign, engage primary destructor beam" ... "Engaged" ... "Fire!")
After you recreate a fresh template1 you should of course set
datistemplate for it, else non-superusers will have difficulty
creating new databases.
regards, tom lane