学习目标
学习 openGauss 体系结构,了解实例(集簇或服务)和数据库的关系
课程学习
在一个 openGauss DBMS 上,一个数据库集簇(Database Cluster)中,可以创建、管理多个数据库。
1.创建表空间,并在该表空间上创建多个数据库
–进入数据库omm,创建表空间、测试数据库
CREATE TABLESPACE test_tbs RELATIVE LOCATION 'tablespace/test_ts';
CREATE DATABASE testdb WITH TABLESPACE = test_tbs;
CREATE DATABASE testdb1 WITH TABLESPACE = test_tbs;
CREATE DATABASE testdb2 WITH TABLESPACE = test_tbs;
CREATE DATABASE testdb3 WITH TABLESPACE = test_tbs;
2.执行\db命令,查看openGauss数据库上有哪些表空间:
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+--------------------
pg_default | omm |
pg_global | omm |
test_tbs | omm | tablespace/test_ts
(3 rows)
3.执行 \l 命令,查看 openGauss 实例中有哪些数据库:
--\l命令,元命令\l的作用是显示openGauss数据库集簇中,目前有哪些数据库。
omm=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
finance | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
omm | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
school | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm +
| | | | | omm=CTc/omm
test | openg | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
testdb | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
testdb1 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
testdb2 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
testdb3 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(11 rows)
4.查看 openGauss 数据库上实例的进程、线程
--查看实例中的进程
\! ps -ef|grep gaussdb
--查看实例中的线程
\! ps -Tp 1646
omm=# \! ps -ef|grep gaussdb
omm 1646 1 7 22:52 ? 00:01:31 /opt/openGauss/bin/gaussdb
omm 5084 1961 0 23:13 pts/0 00:00:00 sh -c ps -ef|grep gaussdb
omm 5086 5084 0 23:13 pts/0 00:00:00 grep gaussdb
omm=# \! ps -Tp 1646
PID SPID TTY TIME CMD
1646 1646 ? 00:00:04 gaussdb
1646 1647 ? 00:00:00 jemalloc_bg_thd
1646 1652 ? 00:00:00 gaussdb
1646 1653 ? 00:00:00 syslogger
1646 1654 ? 00:00:00 alarm
1646 1655 ? 00:00:00 jemalloc_bg_thd
1646 1656 ? 00:00:00 reaper
1646 1657 ? 00:00:00 jemalloc_bg_thd
1646 1658 ? 00:00:00 jemalloc_bg_thd
1646 1682 ? 00:00:00 gaussdb
1646 1683 ? 00:00:00 gaussdb
1646 1684 ? 00:00:00 gaussdb
1646 1686 ? 00:00:00 checkpointer
1646 1687 ? 00:00:00 Spbgwriter
1646 1688 ? 00:00:00 pagewriter
1646 1689 ? 00:00:00 pagewriter
1646 1690 ? 00:00:11 pagewriter
1646 1691 ? 00:00:00 pagewriter
1646 1692 ? 00:00:00 pagewriter
1646 1693 ? 00:00:00 WALwriter
1646 1694 ? 00:00:00 WALwriteraux
1646 1695 ? 00:00:00 AVClauncher
1646 1696 ? 00:00:00 Jobscheduler
1646 1697 ? 00:00:00 asyncundolaunch
1646 1698 ? 00:00:00 globalstats
1646 1699 ? 00:00:00 applylauncher
1646 1700 ? 00:00:01 statscollector
1646 1701 ? 00:00:01 txnsnapcapturer
1646 1702 ? 00:00:00 CfsShrinker
1646 1703 ? 00:00:08 percentworker
1646 1704 ? 00:00:07 ashworker
1646 1705 ? 00:00:04 TrackStmtWorker
1646 1706 ? 00:00:00 auditor
1646 1707 ? 00:00:00 2pccleaner
1646 1708 ? 00:00:00 faultmonitor
1646 1709 ? 00:00:00 WLMworker
1646 1710 ? 00:00:04 WLMmonitor
1646 1711 ? 00:00:00 WLMarbiter
1646 1712 ? 00:00:08 undorecycler
课程作业
1.创建表空间 test_tbs 和多个数据库 testdb、testdb1、testdb2、testdb3
CREATE TABLESPACE test_tbs RELATIVE LOCATION 'tablespace/test_ts';
CREATE DATABASE testdb WITH TABLESPACE = test_tbs;
CREATE DATABASE testdb1 WITH TABLESPACE = test_tbs;
CREATE DATABASE testdb2 WITH TABLESPACE = test_tbs;
CREATE DATABASE testdb3 WITH TABLESPACE = test_tbs;
2.查看数据库上的表空间
omm=# \db
List of tablespaces
Name | Owner | Location
------------+-------+--------------------
pg_default | omm |
pg_global | omm |
test_tbs | omm | tablespace/test_ts
(3 rows)
3.查看 openGauss 实例上有哪些数据库
omm=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
finance | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
omm | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
school | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm +
| | | | | omm=CTc/omm
test | openg | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
testdb | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
testdb1 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
testdb2 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
testdb3 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(11 rows)
4.使用操作系统命令,查看 openGauss 实例的进程、线程
--不退出数据库 直接在命令行运行操作系统命令,类似于 Oracle SQLPLUS 中运行 !top 或者 host top 之类的命令。
\! ps -ef | grep gaussdb
\! ps -Tp 1646