1、创建表空间t_tbspace、用户test,并使用test,在这个表空间上创建表t1
--进入数据库omm,创建测试表空间t_tbspace [omm@ogdb1 ~]$ gsql -d omm -p 40000 -r gsql ((openGauss 3.1.0 build 4e931f9a) compiled at 2022-09-29 14:19:24 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. --创建测试表空间t_tbspace omm=# create tablespace t_tbspace relative location 'tablespace/t_tbspace_01'; CREATE TABLESPACE --再次查询当前表空间 omm=# \db List of tablespaces Name | Owner | Location ------------+-------+------------------------- pg_default | omm | pg_global | omm | t_tbspace | omm | tablespace/t_tbspace_01 (3 rows) --创建用户test,授予数据库系统的SYSADMIN权限: omm=# create user test identified by 'aabb@123'; CREATE ROLE omm=# alter user test sysadmin; ALTER ROLE --数据库系统管理员执行如下命令将“t_tbspace”表空间的访问权限赋予数据用户jack。 omm=# grant create on tablespace t_tbspace to test; GRANT --执行如下命令,使用test用户在指定表空间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=> create table t1 (i int)tablespace t_tbspace; CREATE TABLE omm=>
复制
2、查看表空间t_tbspace的oid和大小
--查看表空间t_tbspace的oid omm=> select oid,* from pg_tablespace where spcname='t_tbspace'; oid | spcname | spcowner | spcacl | spcoptions | spcmaxsize | relative -------+-----------+----------+------------------------+------------+------------+---------- 16496 | t_tbspace | 10 | {omm=C/omm,test=C/omm} | | | t (1 row) --查看表空间t_tbspace大小 omm=> select pg_tablespace_size('t_tbspace'); pg_tablespace_size -------------------- 25
复制
3、查看数据库在默认表空间下有哪些对象
with objectInDefaultTS as ( select relname, relkind, relpages,pg_size_pretty(pg_relation_size(a.oid)), reltablespace,relowner from pg_class a where a.relkind in ('r', 'i') and reltablespace='0' ) select * from objectInDefaultTS where relname not like 'pg_%' and relname not like 'gs_%' and relname not like 'sql_%' order by relpages desc;
复制
4、查看数据库在非默认表空间下有哪些对象
--执行下面的SQL语句,查询数据库omm的非默认表空间t_tbspace下有哪些对象: select relname,relkind,relpages,pg_size_pretty(pg_relation_size(a.oid)), reltablespace,relowner from pg_class a, pg_tablespace tb where a.relkind in ('r', 'i') and a.reltablespace=tb.oid and tb.spcname='t_tbspace' order by a.relpages desc; relname | relkind | relpages | pg_size_pretty | reltablespace | relowner ---------+---------+----------+----------------+---------------+---------- t1 | r | 0 | 0 bytes | 16496 | 16497 (1 row)
复制
5、重命名表空间
--命名表空间t_tbspace为app_tbs omm=> ALTER TABLESPACE t_tbspace RENAME TO app_tbs; ALTER TABLESPACE --执行下面的gsql命令,查看数据库当前的表空间信息: omm=> \db List of tablespaces Name | Owner | Location ------------+-------+------------------------- app_tbs | omm | tablespace/t_tbspace_01 pg_default | omm | pg_global | omm | (3 rows) omm=>
复制
6、删除表空间
--用户必须是表空间的owner或者系统管理员才能删除表空间。需要先删除表空间的对象,再删除表空间app_ts: omm=> drop table test.t1 ; DROP TABLE omm=> omm=> DROP TABLESPACE app_tbs; DROP TABLESPACE omm=> \db List of tablespaces Name | Owner | Location ------------+-------+---------- pg_default | omm | pg_global | omm | (2 rows)
复制
最后修改时间:2022-12-03 17:08:46
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论

2年前

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