每日一练:openGauss数据库在线实训课程 ## 第七天作业

0.表空间

在openGauss中,表空间是一个目录,可以存在多个,里面存储的是它所包含的数据库的各种物理文件。由于表空间是一个目录,仅是起到了物理隔离的作用,其管理功能依赖于文件系统。

在这里插入图片描述

1.创建表空间,表空间tspc1使用相对路径指定所在目录,表空间tspc2指定owner为Lucy

\db
create tablespace tspc1 relative location 'tablespace/tablespace';
create tablespace tspc2 owner lucy relative location 'tablespace/tablespace2'; --ERROR:  role "lucy" does not exist
create role lucy password 'lucy@1234';
create tablespace tspc2 owner lucy relative location 'tablespace/tablespace2';
\db+ tspc2
select * from pg_tablespace;

2.在表空间tspc1中建表,并使用视图pg_tables查看信息

create table customer(id int, name varchar2(20)) tablespace tspc1;
insert into customer values(1, 'bpx');
\d+ pg_tables;

select * from pg_tables where tablename='customer';

3.重命名tspc1,修改tspc2的用户为Lily,使用\db查看表空间信息

\db 
alter tablespace tspc1 rename to tspc11;
\db
create role lily password 'lily@1234';
alter tablespace tspc2 owner to lily;
\db

4.删除表空间

drop tablespace if exists tspc11; -- ERROR:  tablespace "tspc1" is not empty
select tablename, tablespace from pg_tables where tablespace='tspc11';
drop table customer;
drop tablespace if exists tspc11;

猜你喜欢

转载自blog.csdn.net/hezuijiudexiaobai/article/details/121800419