2012-07-09 9 views
43
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 सेट किया है, तो मैं इसे छोड़ने में सक्षम हूं, लेकिन मुझे यह नहीं पता कि इसे कैसे सेट किया जाए।पोस्टग्रेएसक्यूएल से टेम्पलेट डेटाबेस कैसे छोड़ता है?

उत्तर

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 "अद्यतन था pg_database SET datistemplate =' true 'जहां डेटानाम =' template_postgis ';" '। – dbkaplun

+0

इससे और समस्याएं आती हैं। मैंने उबंटू पर 9.1 -> 9.2 से अपग्रेड किया। इसने टेम्पलेट 1 को स्पष्ट रूप से बनाया। मैंने फिर आपके आदेश को निष्पादित किया और ऐसा लगता है कि यह काम करता है। हालांकि, अब मैंने phpPgAdmin स्थापित किया है और मैं लॉगिन नहीं कर सकता, यह कहता है: 'FATAL: डेटाबेस "टेम्पलेट 1" मौजूद नहीं है' – hek2mgl

+0

टेम्पलेट को फिर से बनाने के लिए 1: 'डेटाबेस टेम्पलेट 1 टेम्पलेट टेम्पलेट 0 बनाएं;' 'अद्यतन करें pg_database SET datistemplate =' true 'WHERE डेटानाम =' टेम्पलेट 1 '; ' यह भी देखें: http://pgsql.inb4.se/2009/april/rebuild-template1.html –

4

आप डेटाबेस डेटाबेस कमांड का उपयोग कर सकते हैं। मेटाडेटा को परेशान करने से कहीं अधिक सरल और सुरक्षित।

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

+1

यह है> = 9.5 केवल .. – amoe

+0

@amoe ग्रेट स्पॉट। प्रलेखन लिंक जोड़ने के लिए संपादित किया गया – Mokadillion

संबंधित मुद्दे