【赵渝强老师】高斯数据库(openGauss)的表空间

openGauss是基于PostgreSQL开发的,因此这里可以拿PostgreSQL来比较学习它的体系结构,这样比较容易理解。openGauss的主要结构如下图所示。

openGauss的体系架构中最重要的就是数据的存储结构,而数据存储结构分为逻辑存储结构和物理存储存储。其中,逻辑存储结构是数据库内部的组织和管理数据的方式;而物理存储结构是操作系统中组织和管理数据的方式。
表空间是一个目录,在一个数据库集群中可以存在多个表空间。它里面存储的是数据库的各种物理文件。每个表空间可以对应多个数据库。表空间用作把逻辑上相关的数据结构放在一起。在数据库集群初始化的时候,会自动创建pg_default和pg_global两个表空间。
![]() |
|---|
| 点击这里查看视频讲解:【赵渝强老师】高斯数据库(openGauss)的表空间 |
下面通过具体的操作来演示如何查看OpenGauss中已有的表空间和如何创建自己的表空间。
(1)登录OpenGauss。
bin/gsql -d postgres
(2)查看PostgreSQL中已有的表空间。
openGauss=# \db
# 输出的信息如下:
List of tablespaces
Name | Owner | Location
------------+----------+----------
pg_default | postgres |
pg_global | postgres |
(2 rows)
# 其中:
# pg_global:该表空间用于存放系统表。
# pg_default:创建表时的默认表空间,该表空间的物理文件存储在数据目录中的base目录中,
如:/home/postgres/training/gaussdb/data/single_node/base。
(3)创建自己的表空间。
openGauss=# create tablespace mydemotbs location
'/home/postgres/training/mydemotbs';
CREATE TABLESPACE
(4)在mydemotbs 表空间上创建表。
openGauss=# create table testtable1(tid int primary key,tname text)
tablespace mydemotbs;
(5)再次查看openGauss中已有的表空间。
openGauss=# \db
# 输出的信息如下:
List of tablespaces
Name | Owner | Location
------------+----------+-----------------------------------
mydemotbs | postgres | /home/postgres/training/mydemotbs
pg_default | postgres |
pg_global | postgres |
(3 rows)
(6)将该表空间设置为默认的表空间。
openGauss=# set default_tablespace = mydemotbs;
(7)查询表空间信息
openGauss=# select * from pg_tablespace;
# 输出的信息如下:
spcname | spcowner | spcacl | spcoptions | spcmaxsize | relative
------------+----------+--------+------------+------------+-------
pg_default | 10 | | | | f
pg_global | 10 | | | | f
mydemotbs | 10 | | | | f
(3 rows)
(8)使用\db+命令查看表空间的详细信息,输出的信息如下:
openGauss=# \x
Expanded display is on.
openGauss=# \db+
# 输出的信息如下:
List of tablespaces
-[ RECORD 1 ]-----+----------------------------------
Name | mydemotbs
Owner | postgres
Location | /home/postgres/training/mydemotbs
Access privileges |
Description |
-[ RECORD 2 ]-----+----------------------------------
Name | pg_default
Owner | postgres
Location |
Access privileges |
Description |
-[ RECORD 3 ]-----+----------------------------------
Name | pg_global
Owner | postgres
Location |
Access privileges |
Description |
# 命令中的加号表示显示详细信息。


浙公网安备 33010602011771号