暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第10天 | 随堂笔记

原创 Eddie 2022-12-04
292

表空间是数据的容器。掌握表空间的管理,包括创建表空间、删除表空间、重命名表空间、查看表空间的情况。

通过使用表空间,管理员可以控制一个数据库安装的磁盘布局。

表空间对应于一个文件系统目录,假定数据库节点数据目录/pg_location/mount1/path1是用户拥有读写权限的空目录。

openGauss自带了两个表空间:pg_default和pg_global。

默认表空间pg_default:用来存储非共享系统表、用户表、用户表index、临时表、临时表index、内部临时表的默认表空间。对应存储目录为实例数据目录下的base目录。

共享表空间pg_global:用来存放共享系统表的表空间。对应存储目录为实例数据目录下的global目录。

1.登录opengauss数据库,利用gsql -r命令。

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.

2.创建表空间t_tbspace,及用户test,并授予此用户使用此表空间的权限

omm=# create tablespace t_tbspace relative location 'tablespace/tbs1';
CREATE TABLESPACE
omm=# create user test identified by 'Dongyunyun1!';
NOTICE:  The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# grant create on tablespace t_tbspace to test;
GRANT

3.利用用户test登录数据库omm,并在表空间t_tbspace下创建表t1

omm=# \c omm test;
Password for user test: 
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "omm" as user "test".
omm=> 
omm=> create table t1(id int) tablespace t_tbspace;
CREATE TABLE

4.查询此表空间占用的空间有多大

omm=> select pg_tablespace_size('t_tbspace');
omm=>  pg_tablespace_size 
--------------------
               8192
(1 row)

5.查看此表空间的oid。我们看到的是16389

omm=> select oid,t.* from pg_tablespace t ;
  oid  |  spcname   | spcowner |         spcacl         | spcoptions | spcmaxsize | relative 
-------+------------+----------+------------------------+------------+------------+----------
  1663 | pg_default |       10 |                        |            |            | f
  1664 | pg_global  |       10 |                        |            |            | f
 16389 | t_tbspace  |       10 | {omm=C/omm,test=C/omm} |            |            | t
(3 rows)

6.重命名表空间,并删除此表空间(我们发现删除表空间前需要先删除其中的表)

omm=# alter tablespace t_tbspace rename to tbstest;
ALTER TABLESPACE
omm=# drop tablespace tbstest;
ERROR:  tablespace "tbstest" is not empty
复制
omm=# drop table test.t1;
DROP TABLE
omm=# drop tablespace tbstest;
DROP TABLESPACE

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论