第8天 | openGauss中一个数据库可以存储在多个表空间中
接着昨天继续学习openGauss,今天是第8天了。今天学习内容是o一个数据库可以存储在多个表空间中。
老规矩,先登陆墨天轮为我准备的实训实验室
root@modb:~# su - omm
omm@modb:~$ gsql -r
作业要求
1.创建表空间newtbs1、 ds_location1,查看表空间
omm=# CREATE TABLESPACE newtbs1 RELATIVE LOCATION 'tablespace/tablespace_1';
CREATE TABLESPACE
omm=# CREATE TABLESPACE ds_location1 RELATIVE LOCATION 'tablespace/test_ts1';
omm=# CREATE TABLESPACE
–执行下面的命令,查看当前表空间:
omm=# \dbList of tablespacesName | Owner | Location
--------------+-------+-------------------------ds_location1 | omm | tablespace/test_ts1newtbs1 | omm | tablespace/tablespace_1pg_default | omm | pg_global | omm |
(4 rows)
2.创建一个数据库newdb1,默认表空间为newtbs1
omm=# CREATE DATABASE newdb1 WITH TABLESPACE = newtbs1;
CREATE DATABASE
#### 3.创建用户user5,并授予SYSADMIN权限,访问数据库newdb1,在表空间ds_location1上,创建一个表newt1(表结构自定义)
omm=# CREATE USER user5 IDENTIFIED BY 'user5@1234';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# ALTER USER user5 SYSADMIN;
omm=# ALTER ROLE
omm-# \c newdb1 user5
Password for user user5:
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "newdb1" as user "user5".
newdb1=> create table newt1 (col1 char(10)) tablespace ds_location1;
CREATE TABLE
4.查看表所在的表空间
newdb1=> select * from pg_tables where tablename = 'newt1';schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | tablecr
eator | created | last_ddl_time
------------+-----------+------------+--------------+------------+----------+-------------+--------
------+-------------------------------+-------------------------------public | newt1 | user5 | ds_location1 | f | f | f | user5 | 2022-12-01 10:14:27.780919+08 | 2022-12-01 10:14:27.780919+08
(1 row)
5.查看表空间newtbs1、 ds_location1上的对象
查看表空间 ds_location1的对象
newdb1=> select relname, relkind, relpages,pg_size_pretty(pg_relation_size(a.oid)),reltablespace,relowner
newdb1-> newdb1-> from pg_class a, pg_tablespace tb
where a.relkind in ('r', 'i')
newdb1-> and a.reltablespace=tb.oid
newdb1-> and tb.spcname='ds_location1'
newdb1-> order by a.relpages desc;relname | relkind | relpages | pg_size_pretty | reltablespace | relowner
---------+---------+----------+----------------+---------------+----------newt1 | r | 0 | 0 bytes | 16390 | 16392
(1 row)
查看表空间newtbs1的对象
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;
总结
一个数据库可以存储在多个表空间中