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

openGauss每日一练第 8 天-实训作业

原创 Carton 2022-12-01
314

本文为第二届openGauss每日一练,21天打卡计划第8天的作业部分,课程内容总结如下openGauss每日一练第 8 天-表空间

作业1

创建表空间newtbs1、 ds_location1,查看表空间

CREATE TABLESPACE newtbs1 RELATIVE LOCATION 'tablespace/tablespace_1'; CREATE TABLESPACE ds_location1 RELATIVE LOCATION 'tablespace/tablespace_2';

image.png

作业2

创建一个数据库newdb1,默认表空间为newtbs1

create database newdb1 with tablespace = newtbs1; --另一种做法 set default_tablespace = 'newtbs1'; create database newdb1;

image.png
image.png

作业3

创建用户user5,并授予SYSADMIN权限,访问数据库newdb1,在表空间ds_location1上,创建一个表newt1(表结构自定义)

create table newt1 (col char(20)) tablespace ds_location1;

image.png

作业4

查看表所在的表空间

select tablespace from pg_tables where tablename = 'newt1';

image.png

作业5

查看表空间newtbs1、 ds_location1上的对象

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='newtbs1' order by a.relpages desc; 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='ds_location1' order by a.relpages desc;

image.png
image.png
pg_class 存储数据库对象信息及其之间的关系。
pg_tablespace 系统表存储表空间信息。
pg_size_pretty(), pg_relation_size()

image.png
image.png

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

文章被以下合辑收录

评论