实操作业
实操目的
进一步学习表空间与数据库对象的关系,了解oid的含义。
1.创建表空间newtbs1
--删除表空间,若表空间中有对象 则不能删除
drop tablespace if exists newtbs1;
create tablespace newtbs1 relative location 'tablespace/newtbs1';
--查看表空间
omm=# \db+
List of tablespaces
Name | Owner | Location | Access privileges | Description
------------+-------+--------------------+-------------------+-------------
newtbs1 | omm | tablespace/newtbs1 | |
pg_default | omm | | |
pg_global | omm | | |
(3 rows)
--
omm=# \q
omm@modb:/var/lib/opengauss/data/pg_tblspc$ ls
16389
2.创建3个数据库newdb1、newdb2、newdb3,默认表空间为newtbs1
drop database if exists newdb1;
drop database if exists newdb2;
drop database if exists newdb3;
drop tablespace if exists newtbs1;
--创建表空间 指定用户和绝对路径
create tablespace newtbs1 owner user1 location '/opt/opengauss/data/newtbs1';
--或
--创建表空间 不指定用户,使用相对路径(路径在$PGDATA/pg_tblspc/下)
create tablespace newtbs1 relative location 'tablespace/newtbs1';
--创建数据库newdb1,指定拥有者、默认表空间;
create database newdb1 owner user1 tablespace newtbs1;
----创建数据库newdb2,不指定指定拥有者、,默认表空间,默认为当前用户,默认 表空间为pg_default;
create database newdb2 ;
create database newdb3 ;
3.使用sql查看表空间newtbs1上有几个数据库
--sql查看,可以查看表空间的oid
select oid,datname,dattablespace,datcollate from pg_database ;
select oid,* from pg_tablespace ;
omm=> select datname,dattablespace,spcname from pg_database d, pg_tablespace t where d.dattablespace=t.oid;
datname | dattablespace | spcname
-----------+---------------+------------
template1 | 1663 | pg_default
omm | 1663 | pg_default
template0 | 1663 | pg_default
newdb1 | 16407 | newtbs1
newdb2 | 1663 | pg_default
postgres | 1663 | pg_default
newdb4 | 1663 | pg_default
--元命令查看 不可用查到表空间的oid
omm=> \l+
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
-----------+-------+----------+---------+-------+-------------------+-------+------------+--------------------------------------------
newdb1 | user1 | UTF8 | C | C | | 12 MB | newtbs1 |
newdb2 | omm | UTF8 | C | C | | 12 MB | pg_default |
| | | | | omm=CTc/omm | | |
template1 | omm | UTF8 | C | C | =c/omm +| 12 MB | pg_default | unmodifiable empty database
newdb4 | user1 | UTF8 | C | C | | 12 MB | pg_default |
omm | omm | UTF8 | C | C | | 85 MB | pg_default |
postgres | omm | UTF8 | C | C | | 12 MB | pg_default | default administrative connection database
template0 | omm | UTF8 | C | C | =c/omm +| 12 MB | pg_default | default template for new databases
| | | | | omm=CTc/omm | | |
(7 rows)
4.在文件系统中查看表空间newtbs1中的多个数据库
--默认表空间存储路径为$PGDATA/pg_tblspc/
omm@modb:~$ cd $PGDATA/pg_tblspc/
omm@modb:/var/lib/opengauss/data/pg_tblspc$ ls
16394 16407
omm@modb:/var/lib/opengauss/data/pg_tblspc$
--可以通过如下命令查看表空间的oid
select oid,* from pg_tablespace ;
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




