如何从PostgreSQL中删除模板数据库?

如何从PostgreSQL中删除模板数据库?,postgresql,postgresql-9.1,database-template,Postgresql,Postgresql 9.1,Database Template,使它看起来像是如果我设置了template\u postgis.datistemplate=false,我就可以删除它,但我不知道如何设置它。您可以使用alter database命令。比破坏元数据更简单、更安全 postgres=# DROP DATABASE template_postgis; ERROR: cannot drop a template database postgres=# UPDATE pg_database SET datistemplate='false' WHE

使它看起来像是如果我设置了
template\u postgis.datistemplate=false,我就可以删除它,但我不知道如何设置它。

您可以使用alter database命令。比破坏元数据更简单、更安全

postgres=# DROP DATABASE template_postgis;
ERROR:  cannot drop a template database
postgres=# UPDATE pg_database SET datistemplate='false' WHERE datname='template_postgis';
UPDATE 1
postgres=# DROP DATABASE template_postgis;
DROP DATABASE
postgres=# 

我查看了创建模板时使用的脚本。有一行
psql-d postgres-c“UPDATE pg_database SET datistemplate='true'WHERE datname='template_postgis';”
。这会导致进一步的问题。我在ubuntu上升级了9.1->9.2。这将隐式创建template1。然后我执行了你的命令,它似乎起作用了。但是,现在我安装了phpPgAdmin,无法登录,它说:“致命:数据库“template1”不存在”以重新创建template1:
create database template1 template0
更新PGU数据库集datistemplate='true'其中datname='template1'另请参见:此解决方案有效,并且远没有所选解决方案复杂。@amoe Great spot。编辑添加文档链接谢天谢地,你存在的人。所有其他的解决方案都不起作用。谢谢这是可行的,但请确保在
'false'
postgresv10周围添加单引号
postgres=# create database tempDB is_template true;
CREATE DATABASE
postgres=# drop database tempDB;
ERROR:  cannot drop a template database
postgres=# alter database tempDB is_template false;
ALTER DATABASE
postgres=# drop database tempDB;
DROP DATABASE
postgres=# 
update pg_database set datistemplate=false where datname='template0';
update pg_database set datistemplate=false where datname='template1';

....

Creating script to analyze new cluster                      ok
Creating script to delete old cluster                       ok
Checking for hash indexes                                   ok

Upgrade Complete
----------------