? template1可以連接" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁(yè) > 營(yíng)銷資訊 > 網(wǎng)站運(yùn)營(yíng) > openGauss數(shù)據(jù)庫(kù)模板:template0和template1

openGauss數(shù)據(jù)庫(kù)模板:template0和template1

時(shí)間:2023-06-09 23:15:01 | 來源:網(wǎng)站運(yùn)營(yíng)

時(shí)間:2023-06-09 23:15:01 來源:網(wǎng)站運(yùn)營(yíng)

openGauss數(shù)據(jù)庫(kù)模板:template0和template1:

openGauss數(shù)據(jù)庫(kù)模板:template0和template1

????初始化之后, 就有了template0, template1模板庫(kù),開始時(shí)這兩個(gè)庫(kù)的內(nèi)容是一樣的,但這兩個(gè)庫(kù)有什么區(qū)別?
? template1可以連接并創(chuàng)建對(duì)象,template0 不可以連接;
? 正因?yàn)閠emplate1可以創(chuàng)建對(duì)像,相比template0被稱為非干凈數(shù)據(jù)庫(kù),而template0被稱為干凈的數(shù)據(jù)庫(kù);
? 使用template1 模板庫(kù)建庫(kù)時(shí)不可指定新的 encoding 和 locale,而 template0 可以;
? Template0、Template1 庫(kù)默認(rèn)都不可刪除,且建庫(kù)時(shí)template參數(shù)只能指定template0。
??和PGSQL有所區(qū)別:PGSQL默認(rèn)使用template1,手動(dòng)可以指定template0,并且PGSQL可以使用模板進(jìn)行數(shù)據(jù)庫(kù)克隆。

??本文檔通過間接修改的方式,分別在template0數(shù)據(jù)庫(kù)中創(chuàng)建表t0,在template1數(shù)據(jù)庫(kù)中創(chuàng)建表t1。以此區(qū)別這兩個(gè)模板數(shù)據(jù)庫(kù)內(nèi)的數(shù)據(jù),驗(yàn)證新建數(shù)據(jù)庫(kù)到底使用哪個(gè)模板數(shù)據(jù)庫(kù)。
最終測(cè)試結(jié)果顯示:無論是默認(rèn)建庫(kù),還是指定template建庫(kù),均只能使用template0模板。

postgres=# /l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges-----------+-------+-----------+---------+-------+------------------- postgres | omm | SQL_ASCII | C | C | =Tc/omm + | | | | | omm=CTc/omm template0 | omm | SQL_ASCII | C | C | template1 | omm | SQL_ASCII | C | C |

1. 修改template1(新建表t1) [普通用戶沒有權(quán)限登錄]

postgres=# /c template1Non-SSL connection (SSL connection is recommended when requiring high-security)You are now connected to database "template1" as user "omm".template1=# create table t1(id int,name varchar(20));CREATE TABLEtemplate1=# insert into t1 values(1,'Jerry');INSERT 0 1template1=# select * from t1; id | name----+------- 1 | Jerrytemplate1=# select schemaname,relname from pg_stat_user_tables; schemaname | relname------------+--------- public | t1

2. 重建 template0 (新建表t0)

2.1 備份template0為temp0,并創(chuàng)建表t0

template1=# create database temp0 template=template0; ## 備份template0CREATE DATABASEtemplate1=# select datname from pg_database; datname----------- template0 postgres template1 temp0 template1=# /c temp0Non-SSL connection (SSL connection is recommended when requiring high-security)You are now connected to database "temp0" as user "omm".temp0=# create table t0(id int,name varchar(20));CREATE TABLEtemp0=# insert into t0 values(0,'Tom');INSERT 0 1temp0=# select * from t0; id | name----+------ 0 | Tom(1 row)temp0=# select schemaname,relname from pg_stat_user_tables; schemaname | relname------------+--------- public | t0(1 row)

2.2 刪除 template0

temp0=# update pg_database set datistemplate=false where datname='template0';UPDATE 1temp0=# drop database template0;DROP DATABASEtemp0=# select datname from pg_database; datname----------- postgres template1 temp0(3 rows)

2.3 重命名數(shù)據(jù)庫(kù)為template0,并標(biāo)識(shí)為模板數(shù)據(jù)庫(kù)

temp0=# /c postgresNon-SSL connection (SSL connection is recommended when requiring high-security)You are now connected to database "postgres" as user "omm".postgres=# alter database temp0 rename to template0;ALTER DATABASEpostgres=# update pg_database set datistemplate=true where datname='template0';UPDATE 1postgres=# select datname from pg_database; datname----------- postgres template1 template0(3 rows)

3. 創(chuàng)建數(shù)據(jù)庫(kù)測(cè)試驗(yàn)證模板的使用

3.1 默認(rèn)創(chuàng)建數(shù)據(jù)庫(kù)(結(jié)果顯示:默認(rèn)使用template0模板)

postgres=# create database mydb;CREATE DATABASEpostgres=# /c mydbNon-SSL connection (SSL connection is recommended when requiring high-security)You are now connected to database "mydb" as user "omm".mydb=# select schemaname,relname from pg_stat_user_tables; schemaname | relname------------+--------- public | t0(1 row)mydb=# select * from t0; id | name----+------ 0 | Tom(1 row)

3.2 創(chuàng)建數(shù)據(jù)庫(kù)并指定字符集(結(jié)果顯示:默認(rèn)使用template0模板)

postgres=# create database mydb3 with encoding='UTF-8';CREATE DATABASEpostgres=# /c mydb3Non-SSL connection (SSL connection is recommended when requiring high-security)You are now connected to database "mydb3" as user "omm".mydb3=# select schemaname,relname from pg_stat_user_tables; schemaname | relname------------+--------- public | t0(1 row)

3.3 使用template0創(chuàng)建數(shù)據(jù)庫(kù)(結(jié)果顯示:默認(rèn)使用template0模板)

postgres=# create database mydb1 with template=template0;CREATE DATABASEmydb=# /c mydb1Non-SSL connection (SSL connection is recommended when requiring high-security)You are now connected to database "mydb1" as user "omm".mydb1=# select schemaname,relname from pg_stat_user_tables; schemaname | relname------------+--------- public | t0(1 row)mydb1=# select * from t0; id | name----+------ 0 | Tom(1 row)

3.4 使用template1創(chuàng)建數(shù)據(jù)庫(kù)(不允許手動(dòng)指定使用template1模板)

postgres=# create database mydb2 with template=template1;ERROR: template1 is not supported for using here, just support template0

4. 重建template1示例

mydb4=# update pg_database set datistemplate = false where datname='template1';UPDATE 1mydb4=# drop database template1;DROP DATABASEmydb4=# create database template1 template=template0;CREATE DATABASEmydb4=# update pg_database set datistemplate = true where datname='template1';UPDATE 1mydb4=# /l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges-----------+-------+-----------+---------+-------+------------------- postgres | omm | SQL_ASCII | C | C | =Tc/omm + | | | | | omm=CTc/omm template0 | omm | SQL_ASCII | C | C | =c/omm + | | | | | omm=CTc/omm template1 | omm | SQL_ASCII | C | C |

關(guān)鍵詞:模板,數(shù)據(jù)

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉