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

openGauss每日一练第9天 | 学习心得体会

原创 郭栋 2022-12-02
259

1.创建表空间 newtbs1

--创建表空间 newtbs1
CREATE TABLESPACE newtbs1 RELATIVE LOCATION 'tablespace/newtbs1';

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

CREATE DATABASE newdb1  WITH TABLESPACE = newtbs1;
CREATE DATABASE newdb2  WITH TABLESPACE = newtbs1;
CREATE DATABASE newdb3  WITH TABLESPACE = newtbs1;
omm=# \l
                         List of databases
   Name    | Owner | Encoding | Collate | Ctype | Access privileges 
-----------+-------+----------+---------+-------+-------------------
 newdb1    | omm   | UTF8     | C       | C     | 
 newdb2    | omm   | UTF8     | C       | C     | 
 newdb3    | omm   | UTF8     | C       | C     | 
 omm       | omm   | UTF8     | C       | C     | 
 postgres  | omm   | UTF8     | C       | C     | 
 template0 | omm   | UTF8     | C       | C     | =c/omm           +
           |       |          |         |       | omm=CTc/omm
 template1 | omm   | UTF8     | C       | C     | =c/omm           +
           |       |          |         |       | omm=CTc/omm
(7 rows)

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

omm=# select spcname,datname 
omm-# from pg_database d, pg_tablespace t 
omm-# where 
omm-# d.dattablespace=t.oid
omm-# and spcname='newtbs1';
 spcname | datname 
---------+---------
 newtbs1 | newdb1
 newtbs1 | newdb2
 newtbs1 | newdb3
(3 rows)

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

--查看数据库oid
omm=# select oid,datname from pg_database;
  oid  |  datname  
-------+-----------
     1 | template1
 16384 | omm
 16393 | newdb1
 14555 | template0
 16401 | newdb2
 16402 | newdb3
 14560 | postgres
--查看表空间oid
omm=# select oid,* from pg_tablespace ;
  oid  |   spcname    | spcowner | spcacl | spcoptions | spcmaxsize | relative 
-------+--------------+----------+--------+------------+------------+----------
  1663 | pg_default   |       10 |        |            |            | f
  1664 | pg_global    |       10 |        |            |            | f
 16391 | newtbs1      |       10 |        |            |            | t
 16392 | ds_location1 |       10 |        |            |            | t
(4 rows)

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
 newdb1    |         16391 | newtbs1
 template0 |          1663 | pg_default
 newdb2    |         16391 | newtbs1
 newdb3    |         16391 | newtbs1
 postgres  |          1663 | pg_default
(7 rows)

--从文件系统,查看newtbs1表空间oid,可以看到一个表空间可以有多个数据库
$ cd /var/lib/opengauss/data/pg_tblspc/16391/
$ ls
PG_9.2_201611171_gaussdb
$ cd * 
$ ls -lrt
total 48
drwx------ 2 omm omm 16384 Dec  2 09:56 16393
drwx------ 2 omm omm 16384 Dec  2 10:22 16401
drwx------ 2 omm omm 16384 Dec  2 10:22 16402
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论