1.创建表空间newtbs1
--进入数据库omm,创建测试表空间newtbs1
[omm@ogdb1 ~]$ gsql -d omm -p 40000 -r
gsql ((openGauss 3.1.0 build 4e931f9a) compiled at 2022-09-29 14:19:24 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+----------
pg_default | omm |
pg_global | omm |
(2 rows)
--创建测试表空间newtbs1
omm=# create tablespace newtbs1 relative location 'tablespace/newtbs1_01';
CREATE TABLESPACE
omm=#
--再次查询当前表空间
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+-----------------------
newtbs1 | omm | tablespace/newtbs1_01
pg_default | omm |
pg_global | omm |
(3 rows)
2.创建3个数据库newdb1、newdb2、newdb3,默认表空间为newtbs1
--创建测试数据库newdb1,并查看当前数据库
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=# \l+
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
-----------+-------+-----------+---------+-------+-------------------+-------+------------+--------------------------------------------
newdb1 | omm | SQL_ASCII | C | C | | 13 MB | newtbs1 |
newdb2 | omm | SQL_ASCII | C | C | | 13 MB | newtbs1 |
newdb3 | omm | SQL_ASCII | C | C | | 13 MB | newtbs1 |
omm | omm | SQL_ASCII | C | C | | 13 MB | pg_default |
postgres | omm | SQL_ASCII | C | C | | 17 MB | pg_default | default administrative connection database
template0 | omm | SQL_ASCII | C | C | =c/omm +| 13 MB | pg_default | default template for new databases
| | | | | omm=CTc/omm | | |
template1 | omm | SQL_ASCII | C | C | =c/omm +| 13 MB | pg_default | unmodifiable empty database
| | | | | omm=CTc/omm | | |
(7 rows)
3.使用sql查看表空间newtbs1上有几个数据库
--查看数据库所在的表空间,可以看到一个表空间可以有多个数据库
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
postgres | 1663 | pg_default
newdb1 | 16492 | newtbs1
newdb2 | 16492 | newtbs1
newdb3 | 16492 | newtbs1
(7 rows)
4.在文件系统中查看表空间newtbs1中的多个数据库
--查看数据库、表空间的oid
omm=# select oid,datname from pg_database;
oid | datname
-------+-----------
1 | template1
16384 | omm
15621 | template0
15626 | postgres
16493 | newdb1
16494 | newdb2
16495 | newdb3
(7 rows)
--从文件系统,查看newtbs1表空间oid:16492,可以看到一个表空间可以有多个数据库
#说明:16492是表空间newtbs1的oid
[omm@ogdb1 ~]$ cd /og01/og3.1.0/install/data/dn01/pg_tblspc/
[omm@ogdb1 pg_tblspc]$ ls
16492
[omm@ogdb1 pg_tblspc]$ cd 16492/
[omm@ogdb1 16492]$ ls
PG_9.2_201611171_dn_6001
[omm@ogdb1 16492]$ cd PG_9.2_201611171_dn_6001/
[omm@ogdb1 PG_9.2_201611171_dn_6001]$ ls
16493 16494 16495 pgsql_tmp
[omm@ogdb1 PG_9.2_201611171_dn_6001]$ cd 16493/
[omm@ogdb1 16493]$ ls