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

openGauss每日一练第10天|学习表空间管理

原创 Heming 2022-12-04
921

openGauss每日一练第10天

学习表空间管理

学习表空间的管理,如表空间的创建、生成、重命名、查询等,完成课后作业

创建一个表空间tbs1

在omm用户下通过gsql -r连接数据库后,创建一个名为tps1的表空间位于tablespace/t1

omm=# create tablespace tbs1 relative location 'tablespace/t1'; CREATE TABLESPACE
复制

创建新用户test并把tbs1的create权限赋予test

omm=# create user test identified by 'Test@123'; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE omm=# grant create on tablespace tbs1 to test; GRANT
复制

这样我们的test用户就可以在tbs1上创建数据库对象了

在tbs1上使用test用户创建t1表

通过\c omm test切换到test用户

omm=> create table t1(name char(100)) tablespace tbs1; CREATE TABLE
复制

查看表空间tbs1的oid和大小

omm=> select t.oid, spcname from pg_tablespace t where spcname = 'tbs1'; oid | spcname -------+--------- 16416 | tbs1 omm=> select pg_tablespace_size('tbs1'); pg_tablespace_size -------------------- 32472476
复制

查看omm数据库在tbs1表空间下有那些对象

omm=> select relname,relkind,relpages,pg_size_pretty(pg_relation_size(a.oid)), omm-> reltablespace,relowner omm-> from pg_class a, pg_tablespace tb omm-> where a.relkind in ('r', 'i') omm-> and a.reltablespace=tb.oid omm-> and tb.spcname='tbs1' omm-> order by a.relpages desc; relname | relkind | relpages | pg_size_pretty | reltablespace | relowner ---------+---------+----------+----------------+---------------+---------- t1 | r | 0 | 0 bytes | 16416 | 16420
复制

重命名表空间tbs1为tbspace1

omm=# alter tablespace tbs1 rename to tbspace1; ALTER TABLESPACE omm=# select t.oid, spcname from pg_tablespace t; oid | spcname -------+-------------- 1663 | pg_default 1664 | pg_global 16406 | newtbs1 16407 | ds_location1 16416 | tbspace1
复制

注意此操作要切花到omm用户,test用户并没有修改表空间的权限。

删除表空间tbspace1

omm=# drop tablespace tbspace1; DROP TABLESPACE
复制

注意必须是表空间的owner或者系统管理员才能删除表空间,还需要先删除表空间的对象(如数据库,表等),再删除表空间

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

评论

墨天轮-雪宝君
暂无图片
2年前
评论
暂无图片 0
作业审核合格,一起参与21天openGauss学习打卡活动! 活动详情:https://www.modb.pro/db/551619
2年前
暂无图片 点赞
评论