数据库
数据库#
OushuDB 在初始化完成后,会默认生成三个数据库,可以使用 l 命令查看,或者查看 pg_database 系统表。
1postgres=# \l
2 List of databases
3 Name | Owner | Encoding | Access privileges
4-----------+----------+----------+-------------------
5 postgres | oushu | UTF8 |
6 template0 | oushu | UTF8 |
7 template1 | oushu | UTF8 |
8(4 rows)
其中 template0 和 template1 为模版数据库。template1 为系统默认用来创建新数据库的模版数据库,用户可以修改。template0 默认不接受连接,所以不可更改,目的是始终保存一个干净的模版数据库。
创建一个数据库的时候,可以指定一个数据库的模版数据库。缺省为 template1,现在 OushuDB 只支持以 template0,template1 和 postgres 数据库为模版数据库。例如:
1postgres=# create database tdb; # 创建一个新数据库,默认以 template1 为模版
2CREATE DATABASE
3
4postgres=#\c postgres # 连接 postgres
5postgres=# create table test(i int); # 在 postgres 数据库中创建表 test
6CREATE TABLE
7
8postgres=# create table test_orc(i int) with (appendonly=true, orientation=orc); # 在 postgres 数据库中创建 ORC 格式表
9CREATE TABLE
10
11postgres=# create database dbnew template postgres;
12CREATE DATABASE
13
14postgres=#\c dbnew # 连接 dbnew
可以看到,dbnew中现在包含 test 表
1dbnew=#\d
2 List of relations
3 Schema | Name | Type | Owner | Storage
4--------+------+-------+----------+-------------
5 public | test | table | oushu | append only
6(1 row)