openGauss的模式是对数据库做一个逻辑分割。所有的数据库对象都建立在模式下面。openGauss的模式和用户是弱绑定的,所谓的弱绑定是指虽然创建用户的同时会自动创建一个同名模式,但用户也可以单独创建模式,并且为用户指定其他的模式。

在一个数据库中,可以有多个模式。模式可以把一组对象组织在一起。这样组织机构有多少个应用,我们可以将数据库对象组织成几个模式;组织机构有几个部门,也可以为该部门创建单独的模式。默认情况下,用户将访问数据库的public模式。

学习目标

模式管理包括为数据库创建模式、删除模式、查看和设置模式的搜索路径、查看模式中的信息。

1.创建一个名为testsm、testsm1的模式
--进入数据库omm,创建testsm、testsm1的模式
[omm@ogdb1 ~]$ gsql -d omm -p 40000 -romm=# create schema testsm;
CREATE SCHEMA
omm=# create schema testsm1;
CREATE SCHEMA
omm=#
2.创建一个用户john, 并将testsm的owner修改为 john,且修改owner前后分别使用\dn+查看模式信息
--创建数据库用户john,并将testsm的owner修改为john
omm=# CREATE USER john IDENTIFIED BY 'aabb@123';
CREATE ROLE
omm=# alter user john sysadmin;
ALTER ROLE--且修改owner前使用\dn+查看模式信息
omm=# \dn+List of schemasName       | Owner | Access privileges |           Description            | WithBlockChain
-----------------+-------+-------------------+----------------------------------+----------------blockchain      | omm   |                   | blockchain schema                | fcstore          | omm   |                   | reserved schema for DELTA tables | fdb4ai           | omm   | omm=UC/omm       +| db4ai schema                     | f|       | =U/omm            |                                  |dbe_perf        | omm   |                   | dbe_perf schema                  | fdbe_pldebugger  | omm   | omm=UC/omm       +| dbe_pldebugger schema            | f|       | =U/omm            |                                  |dbe_pldeveloper | omm   | omm=UC/omm       +| dbe_pldeveloper schema           | f|       | =U/omm            |                                  |dbe_sql_util    | omm   | omm=UC/omm       +| sql util schema                  | f|       | =U/omm            |                                  |john            | john  |                   |                                  | fpkg_service     | omm   |                   | pkg_service schema               | fpublic          | omm   | omm=UC/omm       +| standard public schema           | f|       | =U/omm            |                                  |snapshot        | omm   |                   | snapshot schema                  | fsqladvisor      | omm   | omm=UC/omm       +| sqladvisor schema                | f|       | =U/omm            |                                  |testsm          | omm   |                   |                                  | ftestsm1         | omm   |                   |                                  | f--将testsm的owner修改为john
omm=# alter schema testsm OWNER TO john;
ALTER SCHEMA--修改owner后使用\dn+查看模式信息omm=# \dn+List of schemasName       | Owner | Access privileges |           Description            | WithBlockChain
-----------------+-------+-------------------+----------------------------------+----------------blockchain      | omm   |                   | blockchain schema                | fcstore          | omm   |                   | reserved schema for DELTA tables | fdb4ai           | omm   | omm=UC/omm       +| db4ai schema                     | f|       | =U/omm            |                                  |dbe_perf        | omm   |                   | dbe_perf schema                  | fdbe_pldebugger  | omm   | omm=UC/omm       +| dbe_pldebugger schema            | f|       | =U/omm            |                                  |dbe_pldeveloper | omm   | omm=UC/omm       +| dbe_pldeveloper schema           | f|       | =U/omm            |                                  |dbe_sql_util    | omm   | omm=UC/omm       +| sql util schema                  | f|       | =U/omm            |                                  |john            | john  |                   |                                  | fpkg_service     | omm   |                   | pkg_service schema               | fpublic          | omm   | omm=UC/omm       +| standard public schema           | f|       | =U/omm            |                                  |snapshot        | omm   |                   | snapshot schema                  | fsqladvisor      | omm   | omm=UC/omm       +| sqladvisor schema                | f|       | =U/omm            |                                  |testsm          | john  |                   |                                  | ftestsm1         | omm   |                   |                                  | f
(14 rows)--或SELECT catalog_name, schema_name, schema_owner FROM information_schema.schemata;omm=# select catalog_name, schema_name, schema_owner from information_schema.schemata;catalog_name |    schema_name     | schema_owner
--------------+--------------------+--------------omm          | pg_toast           | ommomm          | cstore             | ommomm          | pkg_service        | ommomm          | dbe_perf           | ommomm          | snapshot           | ommomm          | blockchain         | ommomm          | pg_catalog         | ommomm          | public             | ommomm          | sqladvisor         | ommomm          | dbe_pldebugger     | ommomm          | dbe_pldeveloper    | ommomm          | dbe_sql_util       | ommomm          | information_schema | ommomm          | db4ai              | ommomm          | testsm1            | ommomm          | john               | johnomm          | testsm             | john
(17 rows)
3.重命名testsm为testsm2
--重命名testsm为testsm2
omm=# alter schema testsm rename to testsm2;
ALTER SCHEMA--再次执行下面的gsql元命令\dn,查看openGauss数据库上有哪些模式
\dn+omm=# \dn+List of schemasName       | Owner | Access privileges |           Description            | WithBlockChain
-----------------+-------+-------------------+----------------------------------+----------------blockchain      | omm   |                   | blockchain schema                | fcstore          | omm   |                   | reserved schema for DELTA tables | fdb4ai           | omm   | omm=UC/omm       +| db4ai schema                     | f|       | =U/omm            |                                  |dbe_perf        | omm   |                   | dbe_perf schema                  | fdbe_pldebugger  | omm   | omm=UC/omm       +| dbe_pldebugger schema            | f|       | =U/omm            |                                  |dbe_pldeveloper | omm   | omm=UC/omm       +| dbe_pldeveloper schema           | f|       | =U/omm            |                                  |dbe_sql_util    | omm   | omm=UC/omm       +| sql util schema                  | f|       | =U/omm            |                                  |john            | john  |                   |                                  | fpkg_service     | omm   |                   | pkg_service schema               | fpublic          | omm   | omm=UC/omm       +| standard public schema           | f|       | =U/omm            |                                  |snapshot        | omm   |                   | snapshot schema                  | fsqladvisor      | omm   | omm=UC/omm       +| sqladvisor schema                | f|       | =U/omm            |                                  |testsm1         | omm   |                   |                                  | ftestsm2         | john  |                   |                                  | f
(14 rows)
4.在模式testsm1中建表t1、插入记录和查询记录
--执行下面的SQL语句,创建一个测试表testsm1.t1:
omm=# create table testsm1.t1(area_id number,area_name varchar2(25));
CREATE TABLE
omm=# \d testsm1.t1Table "testsm1.t1"Column   |         Type          | Modifiers
-----------+-----------------------+-----------area_id   | numeric               |area_name | character varying(25) |omm=# INSERT INTO testsm1.t1 (area_ID, area_NAME) VALUES (1, 'Europe');
INSERT 0 1
omm=# INSERT INTO testsm1.t1 (area_ID, area_NAME) VALUES (2, 'Americas');
INSERT 0 1
omm=# INSERT INTO testsm1.t1 (area_ID, area_NAME) VALUES (3, 'Asia');
INSERT 0 1--查询记录
omm=# select area_id, area_name from testsm1.t1;area_id | area_name
---------+-----------1 | Europe2 | Americas3 | Asia
(3 rows)omm=# \dt testsm1.t1List of relationsSchema  | Name | Type  | Owner |             Storage
---------+------+-------+-------+----------------------------------testsm1 | t1   | table | omm   | {orientation=row,compression=no}
5.在会话级设置模式搜索顺序
--会话级设置模式搜索顺序
在gsql客户端会话中,执行命令SET SEARCH_PATH TO testsm1可以修改模式搜索路径,但只在gsql客户端会话的持续过程中起作用,一旦退出gsql客户端会话,这个设置就丢失了。重新登录gsql会话将模式搜索路径恢复为默认值"$user",public。omm=# set search_path to testsm1;
SET
omm=# show search_path;search_path
-------------testsm1
(1 row)omm=# select * from t1;area_id | area_name
---------+-----------1 | Europe2 | Americas3 | Asia
(3 rows)--退出,重新查看状态omm=# \q
[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=# show search_path;search_path
----------------"$user",public
(1 row)发现又回归原状态
6.在数据库级设置模式搜索顺序
--创建测试数据库tdb,并在数据库级别设置模式搜索顺序
omm=# create database tdb;
CREATE DATABASE
omm=# alter database tdb set search_path to testm1;
ALTER DATABASE
omm=#
omm=# \c tdb john
Password for user john:
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "tdb" as user "john".
tdb=> show search_path;search_path
-------------testm1
(1 row)tdb=>--退出,重新查看搜索顺序
[omm@ogdb1 ~]$ gsql -d tdb -p 40000  john -r
Password for user john:
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.tdb=> show search_path;search_path
-------------testm1
(1 row)
7.在用户级设置模式搜索顺序
--设置数据库的用户john的模式搜索顺序为模式testsm1:
omm=# alter user john set search_path to testsm1;
ALTER ROLE--退出,重新查看搜索顺序
omm=# \q
[omm@ogdb1 ~]$ gsql -d omm -p 40000 john
Password for user john:
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=> show search_path;search_path
-------------testsm1
(1 row)omm=>

openGauss逻辑结构:模式管理相关推荐

  1. webpack 开发模式管理 Development

    webpack 开发模式管理 Development GitHub 学习 Demo. 接下来将一些开发时的 webpack 配置. warnning : 本指南中的工具仅用于开发,请避免在生产中使用它 ...

  2. AUTOSAR从入门到精通100讲(二十七)-AutoSar模式管理总揽

    介绍下AUTOSAR中的模式管理(Mode Manager)的机理.了解模式管理之前,先解释下三个重要的概念:模式.状态和阶段. Mode(模式) 模式是运行在车辆中的各种状态机(不仅仅是ECU状态管 ...

  3. mysql数据库管理系统模式_MYSQL命令行模式管理MySql的一点心得

    MYSQL命令行模式管理MySql的一点心得 MYSQL命令行模式管理MySql的一点心得 MySql数据库是中小型网站后台数据库的首选,因为它对非商业应用是免费的.网站开发者可以搭建一个" ...

  4. Autosar模式管理系列介绍01-BswM

    本文框架 1.概述 2. BswM属性介绍 2.1 模式仲裁 2.1.1 Rules 2.1.2 LogicalExpression 2.2 模式控制 2.3 基本控制过程 3. BswM功能介绍 3 ...

  5. openGauss数据库权限管理模型(下)

    openGauss数据库采用基于角色的权限访问控制模型,除了在openGauss数据库权限管理模型(上)中介绍的基本系统权限和对象权限的划分外,还有一些高阶的权限管理机制用来满足客户的业务诉求. 1 ...

  6. 以上帝模式管理Windows系统

    上帝模式,,即"God Mode",或称为"完全控制面板".是Windows Vista/7系统中隐藏的一个简单的文件夹窗口,但包含了几乎所有Windows系统 ...

  7. 使用Git子模块和开发模式管理Python项目

    目录 挑战 什么是开发模式? 什么是Git子模块? 设置项目 设置commonlib的Git存储库 设置myproj的Git存储库 设置Git子模块 将存储库添加为子模块 更新子模块 使用Git子模块 ...

  8. STM8电源模式管理及功耗控制

    一.功耗控制调整 1.硬件功能调整 2.软件功能调整 3.经验 3.3V供电比5V更省电 HSI比HSE更省电 晶振频率越低越省电 读写RAM比FLASH更省电 片上资源会影响功耗,不用的应该用PCG ...

  9. AUTOSAR专项 : 模式管理(3) -- ComM

    1.1 ComM概述 ComM最容易被误解为管理Com层的模块,同时由于在配置时该模块所需要配置的内容少之又少,所以很多工程师对这个模块也是一知半解: 思考一下这个问题:针对不同的通讯协议(CAN\L ...

最新文章

  1. lotus php,LotusPhp框架目录_PHP教程
  2. Windows服务器部分告一段落,开始转入Linux
  3. 没有找到 html 模板,Spring Boot and Thymeleaf:找不到HTML模板
  4. Apache NIO 框架 Mina 使用中出现 too many open files 有关...
  5. linux source 子shell,Linux------source
  6. mac虚拟机vm屏幕一直闪烁_VM虚拟机VMware Fusion Pro 11
  7. SpringBoot AOP 理解和用途
  8. 轻量级MVC框架(自行开发)
  9. 国家标准《软件工程 软件开发成本度量规范》GB/T 36964-2018正式发布
  10. 张勋说:溢流型棒磨机在水煤浆气化中的应用及技改(图文)
  11. 【目标检测】|数据增强 Copy-Paste
  12. input输入框对伪类(after,before)支持情况
  13. 3.1 WTL概述,简单使用和ATL概述,简单使用
  14. 在字符串中输入回车换行或其它特殊字符
  15. 地税计算机发展,当前我省地税信息化数据应用的现实状况和发展趋势
  16. ASCII转十六进制小工具
  17. 5 6c语言上机作业答案,(完整版)C语言考试题库及答案
  18. Spring捕获AOP抛出的异常
  19. 整理了4000字的Google数据可视化指南!
  20. 一行代码解决网站防挂IFRAME木马方案,小鸽子序列(灵儿)

热门文章

  1. 致态TiPro7000固件Firmware更新+升级软件(英韧IG5236主控)
  2. PHP生成二维码并添加文字(phpqrcode类)
  3. SQL中NVL函数的使用
  4. 过审AppStore到底有多痛,经历过就知道了!
  5. java入门学习笔记(二)—— Eclipse入门学习之快捷键、java语言基础知识之各类关键字及其用法简析
  6. minperpoly.m
  7. 游戏摄影师修炼手册第1期《原神》带上镜头,前往奇幻的提瓦特大陆
  8. Spring Boot 实现万能文件在线预览-开源学习一
  9. 2023第十七届证卡票签安全识别技术展览会暨高峰论坛
  10. Tainted kernels