Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres template0 template1 both removed

I mistakenly dropped both postgres's template0 and template1 and now am unable to create databases. I am currently running postgres 9.5.3 on OSX 10.11. Can I get help restoring these two templates; I have already tried an uninstall/re-install using homebrew with no luck.

like image 764
user6504702 Avatar asked Oct 28 '25 17:10

user6504702


1 Answers

you cannot to drop database template0 - not with any legal method. What you can do? Now, your database cluster is broken, there are two possibilities:

  1. backup your current databases with pg_dump. Create new database cluster with initdb. New database cluster will have correct template0, template1

  2. You can try to create template1 from any existing database - you can use clause TEMPLATE of statement CREATE DATABASE:

postgres=# create database template1 template postgres;
ERROR:  database "template1" already exists
postgres=# create database template0 template postgres;
ERROR:  database "template0" already exists

First method should be preferred, because nobody knows, what is broken in your cluster.

like image 58
Pavel Stehule Avatar answered Oct 30 '25 13:10

Pavel Stehule