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

时间:2012-07-09 03:31:44

标签: postgresql postgresql-9.1 database-template

postgres=# DROP DATABASE template_postgis;
ERROR:  cannot drop a template database

http://www.postgresql.org/docs/9.1/static/manage-ag-templatedbs.html让我觉得如果我设置template_postgis.datistemplate = false,我就可以放弃它,但我不知道如何设置它。

3 个答案:

答案 0 :(得分:76)

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

答案 1 :(得分:13)

您可以使用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

答案 2 :(得分:-1)

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