2012-07-09 53 views

回答

72
postgres=# UPDATE pg_database SET datistemplate='false' WHERE datname='template_postgis'; 
UPDATE 1 
postgres=# DROP DATABASE template_postgis; 
DROP DATABASE 
postgres=# 
+0

我看着在我使用的脚本创建的模板。有一行'psql -d postgres -c'UPDATE pg_database SET datistemplate ='true'WHERE datname ='template_postgis';“'。 – dbkaplun 2012-07-09 03:35:02

+0

这会导致更多问题。我在ubuntu上从9.1 - > 9.2进行了升级。这隐含地创建了template1。然后我执行你的命令,它似乎工作。然而,现在我安装了phpPgAdmin,但我无法登录,它说:'致命:数据库'template1'不存在' – hek2mgl 2014-01-13 11:47:46

+0

重新创建template1:​​ 'create database template1 template template0;' 'UPDATE pg_database SET datistemplate ='true 'WHERE datname ='template1';' 另请参阅:http://pgsql.inb4.se/2009/april/rebuild-template1.html – 2015-07-30 06:00:12

4

您可以使用alter database命令。比镦乱元数据更简单也更安全。

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=# 

Documentation

+0

该解决方案的工作原理并不比所选解决方案复杂。 – Brad 2016-10-04 16:26:29

+1

这是> = 9.5只.. – amoe 2017-04-03 15:29:09

+0

@amoe很棒的地方。编辑添加文档链接 – Mokadillion 2017-04-04 08:45:10