template0 和 template1 数据库意外删除
template0 and template1 database dropped accidently
我不知道 template0
和 template1
数据库模板是创建空数据库所必需的。我删除了它们以清理 postgres。现在我无法创建任何新数据库。给我这个错误:
ERROR: template database "template1" does not exist
我该怎么做才能让事情重新开始。我将非常感谢任何帮助。
幸运的是我保留了 postgres
数据库,因为 postgres
用户登录 psql
需要它。因此,创建了一个 template0
和 template1
数据库:
create database template0 TEMPLATE postgres;
与模板 1 相同。然后执行:
update pg_database set datistemplate=true where datname='template0';
两个数据库都可以防止我再次不小心删除这些模板。
现在一切正常:)
在我的 CentOS 7 机器上,我还没有幸运地连接到一个数据库。然而:
su postgres -c "initdb /var/lib/pgsql/data"
(作为 root)创建了一个模板 0 和模板 1 来使用。
在我的 debian 机器上,我将一些集群升级到版本 11。
目标集群上的模板 [01] 数据库已被删除,使我使用旧版本的数据库。
作为 root,我用 pg_createcluster 创建了一个新集群。
作为用户 postgres:
使用 pg_dumpall(使用 --clean 标志)转储新集群的数据库。
删除新集群。
使用 psql 在集群中导入结果源。
我会删除 drop 角色 postgres 并创建相同的角色。
此致,
亚历克斯
对于 postgres 12.3
以下对我有用。
我删了template1
不知道是什么。我能够从 template0
创建它。您也可以从 postgres
.
创建它
createdb -T template0 template1
createdb -T postgres template1
这是文档中的建议 -
template1 and template0 do not have any special status beyond the fact that the name template1 is the default source database name for CREATE DATABASE. For example, one could drop template1 and recreate it from template0 without any ill effects.
https://www.postgresql.org/docs/current/manage-ag-templatedbs.html
我不知道 template0
和 template1
数据库模板是创建空数据库所必需的。我删除了它们以清理 postgres。现在我无法创建任何新数据库。给我这个错误:
ERROR: template database "template1" does not exist
我该怎么做才能让事情重新开始。我将非常感谢任何帮助。
幸运的是我保留了 postgres
数据库,因为 postgres
用户登录 psql
需要它。因此,创建了一个 template0
和 template1
数据库:
create database template0 TEMPLATE postgres;
与模板 1 相同。然后执行:
update pg_database set datistemplate=true where datname='template0';
两个数据库都可以防止我再次不小心删除这些模板。
现在一切正常:)
在我的 CentOS 7 机器上,我还没有幸运地连接到一个数据库。然而:
su postgres -c "initdb /var/lib/pgsql/data"
(作为 root)创建了一个模板 0 和模板 1 来使用。
在我的 debian 机器上,我将一些集群升级到版本 11。 目标集群上的模板 [01] 数据库已被删除,使我使用旧版本的数据库。
作为 root,我用 pg_createcluster 创建了一个新集群。
作为用户 postgres:
使用 pg_dumpall(使用 --clean 标志)转储新集群的数据库。
删除新集群。
使用 psql 在集群中导入结果源。
我会删除 drop 角色 postgres 并创建相同的角色。
此致, 亚历克斯
对于 postgres 12.3
以下对我有用。
我删了template1
不知道是什么。我能够从 template0
创建它。您也可以从 postgres
.
createdb -T template0 template1
createdb -T postgres template1
这是文档中的建议 -
template1 and template0 do not have any special status beyond the fact that the name template1 is the default source database name for CREATE DATABASE. For example, one could drop template1 and recreate it from template0 without any ill effects.
https://www.postgresql.org/docs/current/manage-ag-templatedbs.html