template0和template1数据库意外丢失

Dan*_*uze 8 postgresql

我不知道template0template1数据库模板,以创建空数据库所需.我删除它们是为了清理postgres.现在我无法创建任何新数据库.给我这个错误:

ERROR:  template database "template1" does not exist
Run Code Online (Sandbox Code Playgroud)

我该怎样做才能让事情再次发生.我会非常感谢任何帮助.

Dan*_*uze 19

幸运的是我postgres保留了数据库,因为postgres用户需要登录psql.于是,创建了一个template0template1数据库:

create database template0 TEMPLATE postgres;
Run Code Online (Sandbox Code Playgroud)

和template1相同.然后执行:

update pg_database set datistemplate=true  where datname='template0';
Run Code Online (Sandbox Code Playgroud)

两个数据库都阻止我自己再次意外删除这些模板.

现在一切正常:)