openGauss表空间的相关操作;
openGauss表空间的形式跟oracle不一样,openGauss表空间实际上对应的是文件夹目录,而oracle是文件形式;
openGauss自带了两个表空间:pg_default和pg_global。
- 默认表空间pg_default:用来存储非共享系统表、用户表、用户表index、临时表、临时表index、内部临时表的默认表空间。对应存储目录为实例数据目录下的base目录。
- 共享表空间pg_global:用来存放共享系统表的表空间。对应存储目录为实例数据目录下的global目录。
创建语法:
CREATE TABLESPACE tablespace_name
[ OWNER user_name ] [RELATIVE] LOCATION 'directory' [ MAXSIZE 'space_size' ]
[with_option_clause];
with_option_clause:
WITH ( {filesystem= { 'general'| "general" | general} |
random_page_cost = { 'value ' | value } |
seq_page_cost = { 'value ' | value }}[,...])
https://opengauss.org/zh/docs/2.1.0/docs/Developerguide/CREATE-TABLESPACE.html
这一练的一些命令:
\db:查看所有表空间
课程作业
1.创建表空间,表空间tspc1使用相对路径指定所在目录,表空间tspc2指定owner为Lucy
openGauss=# create tablespace tspc1 relative location 'tablespace/tspc1';
CREATE TABLESPACE
openGauss=# create user Lucy password 'abcd@123';
CREATE ROLE
openGauss=# create tablespace tspc2 owner Lucy relative location 'tablespace/tspc2';
CREATE TABLESPACE
openGauss=# \db
List of tablespaces
Name | Owner | Location
--------------+-------+-------------------------
pg_default | omm |
pg_global | omm |
tspc1 | omm | tablespace/tspc1
tspc2 | lucy | tablespace/tspc2
2.在表空间tspc1中建表,并使用视图pg_tables查看信息
openGauss=# create table customer (id int,name char(20)) tablespace tspc1;
CREATE TABLE
openGauss=# select * from pg_tables where tablename='customer';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | tablecreator | created | last_dd
l_time
------------+-----------+------------+------------+------------+----------+-------------+--------------+-------------------------------+----------------
---------------
public | customer | omm | tspc1 | f | f | f | omm | 2021-12-08 16:08:55.407223+08 | 2021-12-08 16:0
8:55.407223+08
(1 row)
openGauss=#
3.重命名tspc1,修改tspc2的用户为Lily,使用\db查看表空间信息
openGauss=# alter tablespace tspc1 rename to tspc10;
ALTER TABLESPACE
openGauss=# create user Lily password 'abcd@123';
CREATE ROLE ^
openGauss=# alter tablespace tspc2 owner to Lily;
ALTER TABLESPACE
openGauss=# \db
List of tablespaces
Name | Owner | Location
--------------+-------+-------------------------
pg_default | omm |
pg_global | omm |
tspc10 | omm | tablespace/tspc1
tspc2 | lily | tablespace/tspc2
(4 rows)
openGauss=#
4.删除表空间
openGauss=# drop tablespace tspc10;
ERROR: tablespace "tspc10" is not empty
openGauss=# drop table customer;
DROP TABLE
openGauss=# drop tablespace tspc10;
DROP TABLESPACE
openGauss=# drop tablespace tspc2;
DROP TABLESPACE
openGauss=# \db
List of tablespaces
Name | Owner | Location
--------------+-------+-------------------------
pg_default | omm |
pg_global | omm |
(2 rows)
openGauss=# 最后修改时间:2021-12-09 21:33:28
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




