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

dbk*_*lun 49 postgresql database-template postgresql-9.1

postgres=# DROP DATABASE template_postgis;
ERROR:  cannot drop a template database
Run Code Online (Sandbox Code Playgroud)

http://www.postgresql.org/docs/9.1/static/manage-ag-templatedbs.html看起来好像我设置了template_postgis.datistemplate = false,我可以放弃它,但我不知道如何设置.

dbk*_*lun 77

postgres=# UPDATE pg_database SET datistemplate='false' WHERE datname='template_postgis';
UPDATE 1
postgres=# DROP DATABASE template_postgis;
DROP DATABASE
postgres=# 
Run Code Online (Sandbox Code Playgroud)

  • 这会导致进一步的问题。我在 ubuntu 上从 9.1 -> 9.2 进行了升级。这隐式地创建了 template1。然后我执行了你的命令,它似乎有效。但是,现在我安装了 phpPgAdmin 并且无法登录,它说:'致命:数据库“template1”不存在' (2认同)

Vyn*_*kie 15

您可以使用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=# 
Run Code Online (Sandbox Code Playgroud)

文档

  • 该解决方案有效且远没有所选解决方案那么复杂。 (2认同)
  • 这可行,但请确保在“false”周围添加单引号 *POSTGRES v10* (2认同)