如何从 PostgreSQL 中删除模板数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11388786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does one drop a template database from PostgreSQL?
提问by dbkaplun
postgres=# DROP DATABASE template_postgis;
ERROR: cannot drop a template database
http://www.postgresql.org/docs/9.1/static/manage-ag-templatedbs.htmlmakes 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.
http://www.postgresql.org/docs/9.1/static/manage-ag-templatedbs.html看起来好像如果我设置了template_postgis.datistemplate = false
,我就可以删除它,但我不知道如何设置.
回答by dbkaplun
postgres=# UPDATE pg_database SET datistemplate='false' WHERE datname='template_postgis';
UPDATE 1
postgres=# DROP DATABASE template_postgis;
DROP DATABASE
postgres=#
回答by VynlJunkie
You can use the alter database command. Much simpler and safer than upsetting metadata.
您可以使用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=#
回答by dba
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
----------------