数据库环境
openGauss:2.0.0 - 数据库实训平台
学习目标
学习openGauss表空间
学习笔记
- 创建表空间
omm=# CREATE TABLESPACE ds_location1 RELATIVE LOCATION 'tablespace/tablespace_1';
CREATE TABLESPACE
- 查看表空间信息
omm=# \db
List of tablespaces
Name | Owner | Location
--------------+-------+-------------------------
ds_location2 | jay | tablespace/tablespace_2
ds_location3 | omm | tablespace/tablespace_1
pg_default | omm |
pg_global | omm |
(4 rows)
- 通过视图查看表所在的表空间
omm=# select * from pg_tables where tablename = 'ds_t1';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | tablecreator | created | last_ddl_time
------------+-----------+------------+--------------+------------+----------+-------------+--------------+-------------------------------+-------------------------------
public | ds_t1 | omm | ds_location2 | f | f | f | omm | 2021-12-13 22:10:33.541779+08 | 2021-12-13 22:10:33.541779+08
(1 row)
课后作业
1.创建表空间,表空间tspc1使用相对路径指定所在目录,表空间tspc2指定owner为Lucy
omm=# create tablespace tspc1 relative location 'tablespace/ts1';
CREATE TABLESPACE
omm=# create role Lucy identified by 'lucy-role-demo1';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# create tablespace tspc2 owner Lucy relative location 'tablespace/ts2';
CREATE TABLESPACE
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+----------------
pg_default | omm |
pg_global | omm |
tspc1 | omm | tablespace/ts1
tspc2 | lucy | tablespace/ts2
(4 rows)
omm=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------------------------------------------------------------+-----------
gaussdb | Sysadmin | {}
lucy | Cannot login | {}
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {}
2.在表空间tspc1中建表,并使用视图pg_tables查看信息
omm=# create table customer(customer_id integer,customer_name char(30)) tablespace tspc1;
CREATE TABLE
omm=# select * from pg_tables where tablename='customer';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | tablecreator | created | last_ddl_time
------------+-----------+------------+------------+------------+----------+-------------+--------------+-------------------------------+-------------------------------
public | customer | omm | tspc1 | f | f | f | omm | 2021-12-13 22:29:07.778034+08 | 2021-12-13 22:29:07.778034+08
(1 row)
3.重命名tspc1,修改tspc2的用户为Lily,使用\db查看表空间信息
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+----------------
pg_default | omm |
pg_global | omm |
tspc1 | omm | tablespace/ts1
tspc2 | lucy | tablespace/ts2
(4 rows)
omm=# alter tablespace tspc1 rename to tspc10;
ALTER TABLESPACE
omm=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------------------------------------------------------------+-----------
gaussdb | Sysadmin | {}
lucy | Cannot login | {}
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {}
omm=# create role Lily identified by 'lily-demo-pwd1';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------------------------------------------------------------+-----------
gaussdb | Sysadmin | {}
lily | Cannot login | {}
lucy | Cannot login | {}
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {}
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+----------------
pg_default | omm |
pg_global | omm |
tspc10 | omm | tablespace/ts1
tspc2 | lucy | tablespace/ts2
(4 rows)
omm=# alter tablespace tspc2 owner to Lily;
ALTER TABLESPACE
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+----------------
pg_default | omm |
pg_global | omm |
tspc10 | omm | tablespace/ts1
tspc2 | lily | tablespace/ts2
(4 rows)
4.删除表空间
omm=# drop table customer;
DROP TABLE
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+----------------
pg_default | omm |
pg_global | omm |
tspc10 | omm | tablespace/ts1
tspc2 | lily | tablespace/ts2
(4 rows)
omm=# drop tablespace if exists tspc10;
DROP TABLESPACE
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+----------------
pg_default | omm |
pg_global | omm |
tspc2 | lily | tablespace/ts2
(3 rows)
omm=# drop tablespace tspc2;
DROP TABLESPACE
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+----------
pg_default | omm |
pg_global | omm |
(2 rows)
学习体会
位置、角色、权限和用户,这四个概念要做好区分。
路径分为绝对路径和相对路径。
关于opengauss是否区分大小写的问题,可以参考如下内容
我把解答附在这里了,方便其他的同学查阅
您好,未加""的话,默认是不区分大小写的,都会按照小写处理,因此创建出的数据库是db_stumis,而gsql命令的参数是区分大小写的,因此报不存在db_stuMis数据库。
建议可以通过 create database “db_stuMis”; 强制区分大小写。或者gsql连接时全部使用小写。
学习资源
- openGauss SQL学习参考资料
- 每日一练:openGauss数据库在线实训课程
- openGauss每日一练 | 21期养成好习惯,提升技术能力!
- 墨天轮Markdown编辑器使用介绍
- 墨天轮数据库在线实训平台V1.0操作手册
- 墨天轮数据社区
欢迎各位同学一起来交流学习心得!
最后修改时间:2021-12-16 18:37:34
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




