第 9 天学习打卡。周末了,赶一赶学习进度,开启周六第二课。
本节课的学习目标是“进一步学习表空间与数据库对象的关系,了解 oid 的含义”,在线手册中对于 OID 的描述如下:
openGauss 在内部使用对象标识符(OID)作为各种系统表的主键。系统不会给用户创建的表增加一个 OID 系统字段,OID 类型代表一个对象标识符。
目前 OID 类型用一个四字节的无符号整数实现。因此不建议在创建的表中使用 OID 字段做主键。
示例如下:
openGauss=# SELECT oid FROM pg_class WHERE relname = 'pg_type';
oid
------
1247
(1 row)
作业实操内容如下。
作业
- 创建表空间 newtbs1
root@modb:~# su - omm
omm@modb:~$ gsql -r
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm=# CREATE TABLESPACE newtbs1 RELATIVE LOCATION 'tablespace/newtbs1';
CREATE TABLESPACE
omm=#
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+--------------------
newtbs1 | omm | tablespace/newtbs1
pg_default | omm |
pg_global | omm |
(3 rows)
omm=#
- 创建 3 个数据库 newdb1、newdb2、newdb3,默认表空间为 newtbs1
omm=# CREATE DATABASE newdb1 WITH TABLESPACE = newtbs1;
CREATE DATABASE
omm=# CREATE DATABASE newdb2 WITH TABLESPACE = newtbs1;
CREATE DATABASE
omm=# CREATE DATABASE newdb3 WITH TABLESPACE = newtbs1;
CREATE DATABASE
omm=#
- 使用 sql 查看表空间 newtbs1 上有几个数据库
omm=# select datname,dattablespace,spcname from pg_database d, pg_tablespace t where d.dattablespace=t.oid order by datname;
datname | dattablespace | spcname
-----------+---------------+------------
newdb1 | 16389 | newtbs1
newdb2 | 16389 | newtbs1
newdb3 | 16389 | newtbs1
omm | 1663 | pg_default
postgres | 1663 | pg_default
template0 | 1663 | pg_default
template1 | 1663 | pg_default
(7 rows)
- 在文件系统中查看表空间 newtbs1 中的多个数据库
omm=# \q
omm@modb:~$ cd /var/lib/opengauss/data/pg_tblspc
omm@modb:/var/lib/opengauss/data/pg_tblspc$ ls
16389
omm@modb:/var/lib/opengauss/data/pg_tblspc$ cd 16389
omm@modb:/var/lib/opengauss/data/pg_tblspc/16389$ ls
PG_9.2_201611171_gaussdb
omm@modb:/var/lib/opengauss/data/pg_tblspc/16389$ cd PG_9.2_201611171_gaussdb/
omm@modb:/var/lib/opengauss/data/pg_tblspc/16389/PG_9.2_201611171_gaussdb$ ls
16390 16391 16392 pgsql_tmp
omm@modb:/var/lib/opengauss/data/pg_tblspc/16389/PG_9.2_201611171_gaussdb$
命令汇总
- 查看数据库所在的表空间
select datname,dattablespace,spcname from pg_database d, pg_tablespace t where d.dattablespace=t.oid;
- 在文件系统中查看表空间中的多个数据库
-- 查看数据库、表空间的 oid
select oid,datname from pg_database;
select oid,* from pg_tablespace;
select datname,dattablespace,spcname from pg_database d, pg_tablespace t where d.dattablespace=t.oid;
-- 在操作系统中指定路径查看
cd /var/lib/opengauss/data/pg_tblspc/
总结
OID 是 openGauss 内部对象的标识符,我们可以在数据库中或操作系统路径来对其信息进行查看。
历史打卡记录:
openGauss 每日一练第 1 天|openGauss 数据库状态查看
openGauss 每日一练第 2 天|学习 openGauss 客户端工具 gsql 的使用
openGauss 每日一练第 3 天|openGauss 中一个数据库集簇对应多个数据库
openGauss 每日一练第 4 天|openGauss 中一个数据库可以被多个用户访问
openGauss 每日一练第 5 天|openGauss 中一个用户可以访问多个数据库
openGauss 每日一练第 6 天|openGauss 中用户一次只能连接到一个数据库
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




