做網(wǎng)站需提供什么資料鄭州百度推廣公司
PostgreSQL模板數(shù)據(jù)庫(kù)
PostgreSQL有兩個(gè)模板數(shù)據(jù)庫(kù):template0和template1,template0是不可修改的,而template1是可以修改的。
那模板數(shù)據(jù)庫(kù)有什么作用呢?顧名思義,當(dāng)做模板。
其實(shí)我們創(chuàng)建數(shù)據(jù)庫(kù) CREATE DATABASE
其實(shí)就是復(fù)制template1模板庫(kù),命名為新庫(kù)。
那兩個(gè)模板庫(kù)有什么區(qū)別呢?
template0模板庫(kù)
- template0是不可修改的,是PG的最后一道防線!因?yàn)?template1模板庫(kù))可以改,可以進(jìn)行定制化;而同時(shí)也意味著可能會(huì)改錯(cuò),如果改錯(cuò)了,就創(chuàng)建不了數(shù)據(jù)庫(kù)了;所以template0是最后的保險(xiǎn),是不能修改的。
- 使用template0可指定字符集和本地化collate屬性。
create database dbname with encoding 'UTF-8' template template0
lc_collate='zh_CN.utf8' lc_ctype='zh_CN.utf8';
template1模板庫(kù)
- template1是可以修改的,可以定制化一些特定的功能,比如:定制一個(gè)dba模式,創(chuàng)建一些運(yùn)維常用的視圖等,這樣創(chuàng)建新數(shù)據(jù)庫(kù)時(shí),都會(huì)自帶這個(gè)dba模式。
- 使用template1創(chuàng)建數(shù)據(jù)庫(kù)時(shí)不可指定新的字符集和本地化collate屬性,即只能和它的規(guī)則保持一致。
create database dbname with template template1;
參考:https://www.postgresql.org/docs/current/manage-ag-templatedbs.html