暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第9天 | openGauss中一个表空间可以存储多个数据库

原创 计议 2022-12-04
818

学习目标
进一步学习表空间与数据库对象的关系,了解oid的含义。

课程作业

1.1 创建表空间newtbs1

root@modb:~# su - omm
omm@modb:~$ gsql -r
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

omm=# CREATE TABLESPACE newtbs1 RELATIVE LOCATION 'tablespace/newtbs1_ts1';
CREATE TABLESPACE

1.2 创建3个数据库newdb1、newdb2、newdb3,默认表空间为newtbs1

omm=# CREATE DATABASE newdb1  WITH TABLESPACE = newtbs1;
CREATE DATABASE
omm=# CREATE DATABASE newdb2 WITH TABLESPACE = newtbs1;
CREATE DATABASE
omm=# CREATE DATABASE newdb3 WITH TABLESPACE = newtbs1;
CREATE DATABASE
omm=# 

##1.3 使用sql查看表空间newtbs1上有几个数据库

omm=#  select oid,datname from pg_database;
  oid  |  datname  
-------+-----------
     1 | template1
 16384 | omm
 16390 | newdb1
 14555 | template0
 16391 | newdb2
 16392 | newdb3
 14560 | postgres
(7 rows)

1.4 在文件系统中查看表空间newtbs1中的多个数据库

omm=# select oid,* from pg_tablespace ;
  oid  |  spcname   | spcowner | spcacl | spcoptions | spcmaxsize | relative 
-------+------------+----------+--------+------------+------------+----------
  1663 | pg_default |       10 |        |            |            | f
  1664 | pg_global  |       10 |        |            |            | f
 16389 | newtbs1    |       10 |        |            |            | t
(3 rows)

omm=# select datname,dattablespace,spcname from pg_database d, pg_tablespace t wre d.dattablespace=t.oid; 
  datname  | dattablespace |  spcname   
-----------+---------------+------------
 template1 |          1663 | pg_default
 omm       |          1663 | pg_default
 newdb1    |         16389 | newtbs1
 template0 |          1663 | pg_default
 newdb2    |         16389 | newtbs1
 newdb3    |         16389 | newtbs1
 postgres  |          1663 | pg_default
(7 rows)

omm@modb:/var/lib/opengauss/data$ cd /var/lib/opengauss/data/pg_tblspc
omm@modb:/var/lib/opengauss/data/pg_tblspc$ ls -lrt
total 0
lrwxrwxrwx 1 omm omm 58 Dec  4 17:29 16389 -> /var/lib/opengauss/data/pg_location/tablespace/newtbs1_ts1
omm@modb:/var/lib/opengauss/data/pg_tblspc$ cd 16389
omm@modb:/var/lib/opengauss/data/pg_tblspc/16389$ ls -lrt
total 4
drwx------ 6 omm omm 4096 Dec  4 17:31 PG_9.2_201611171_gaussdb
omm@modb:/var/lib/opengauss/data/pg_tblspc/16389$ cd PG_9.2_201611171_gaussdb/
omm@modb:/var/lib/opengauss/data/pg_tblspc/16389/PG_9.2_201611171_gaussdb$ ls -lrt
total 52
drwx------ 2 omm omm  4096 Dec  4 17:29 pgsql_tmp
drwx------ 2 omm omm 16384 Dec  4 17:31 16390
drwx------ 2 omm omm 16384 Dec  4 17:31 16391
drwx------ 2 omm omm 16384 Dec  4 17:31 16392
omm@modb:/var/lib/opengauss/data/pg_tblspc/16389/PG_9.2_201611171_gaussdb$ 
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论