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年前

评论
相关阅读
openGauss荣获中国软件行业协会多奖项,技术升级再创行业新高度
openGauss
563次阅读
2025-04-30 14:30:58
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
309次阅读
2025-04-17 10:41:41
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
203次阅读
2025-04-16 09:52:02
GitCode 成 openGauss 新归宿,国产开源数据库里程碑事件
严少安
178次阅读
2025-04-27 11:37:53
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
165次阅读
2025-04-23 17:39:13
单个执行机并行执行MySQL到openGauss数据迁移子任务
Clipnosis
151次阅读
2025-04-30 16:39:58
Postgresql数据库单个Page最多存储多少行数据
maozicb
97次阅读
2025-04-23 16:02:19
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
97次阅读
2025-04-18 10:49:53
openGauss新特性 | openGauss-DataVec向量数据库特性介绍
openGauss
68次阅读
2025-04-17 10:41:47
RISC-V 首迎 openGauss 7.0.0-RC1 全量版适配!数据库核心功能完整落地开源架构
openGauss
51次阅读
2025-04-16 10:33:59