时间:2023-06-09 23:15:01 | 来源:网站运营
时间:2023-06-09 23:15:01 来源:网站运营
openGauss数据库模板:template0和template1: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 |
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
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)
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)
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)
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)
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)
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)
postgres=# create database mydb2 with template=template1;ERROR: template1 is not supported for using here, just support template0
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 |
关键词:模板,数据