How does one drop a template database from PostgreSQL?

天涯浪子 提交于 2019-12-20 08:35:13

问题


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

http://www.postgresql.org/docs/9.1/static/manage-ag-templatedbs.html makes it seem like if I set template_postgis.datistemplate = false, I'll be able to drop it, but I don't know how to set that.


回答1:


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



回答2:


You can use the alter database command. Much simpler and safer than upsetting metadata.

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




回答3:


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


来源:https://stackoverflow.com/questions/11388786/how-does-one-drop-a-template-database-from-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!