创建与管理模式

  • 概述:DB内组织对象的一种逻辑结构。一个DB内能够有多个模式。在未指定模式时默认放置在public中。能够通过”\dn”方式查看数据库中现有模式。

testdw=# \dn

List of schemas

Name        |  Owner

--------------------+---------

gp_toolkit         | gpadmin

information_schema | gpadmin

pg_aoseg           | gpadmin

pg_bitmapindex     | gpadmin

pg_catalog         | gpadmin

pg_toast           | gpadmin

public             | gpadmin

(7 rows)

  • 创建模式:使用CREATESCHEMA命令。通过查看帮助例如以下所看到的:

testdw=# \h CREATE SCHEMA

Command:     CREATE SCHEMA

Description: define a new schema

Syntax:

CREATE SCHEMA schemaname [ AUTHORIZATION username ] [ schema_element [ ... ] ]   将全部者设置为其它角色通过AUTHORIZTION

CREATE SCHEMA AUTHORIZATION username [ schema_element [ ... ] ]

  • 訪问模式的对象:schema.table

testdw=# CREATE SCHEMA sc01;

CREATE SCHEMA

testdw=# \dn

List of schemas

Name        |  Owner

--------------------+---------

gp_toolkit         | gpadmin

information_schema | gpadmin

pg_aoseg           | gpadmin

pg_bitmapindex     | gpadmin

pg_catalog         | gpadmin

pg_toast           | gpadmin

public             | gpadmin

sc01               | gpadmin

(8 rows)

testdw=# create schema sc02 authorization mavshuang;

ERROR:  permission denied for database testdw  (seg1 slave2:40000 pid=5424) 
提示testdw数据库中权限拒绝

testdw=# grant all on database testdw to mavshuang;            将testdw数据库的全部权限赋给mavshuang

GRANT

testdw=# create schema sc02 authorization mavshuang;

CREATE SCHEMA

testdw=# \dn

List of schemas

Name        |   Owner

--------------------+-----------

gp_toolkit         | gpadmin

information_schema | gpadmin

pg_aoseg           | gpadmin

pg_bitmapindex     | gpadmin

pg_catalog         | gpadmin

pg_toast           | gpadmin

public             | gpadmin

sc01               | gpadmin

sc02               | mavshuang                   
此时用户是mavshuang

(9 rows)

  • 模式搜索路径:若不想通过指定模式名称的方式来搜索须要的对象。能够通过设置search_path的方式来实现。第一个模式为缺省。

testdw=# show search_path;

search_path

----------------

"$user",public

(1 row)

  • 通过ALTERDATABASE改动DB的模式搜索路径

testdw-# \h alter database

Command:     ALTER DATABASE

Description: change a database

Syntax:

ALTER DATABASE name [ [ WITH ] option [ ... ] ]

where option can be:

CONNECTION LIMIT connlimit

ALTER DATABASE name SET parameter { TO | = } { value | DEFAULT }    通过此命令来改动DB的模式搜索路径

ALTER DATABASE name RESET parameter

ALTER DATABASE name RENAME TO newname

ALTER DATABASE name OWNER TO new_owner

testdw=# alter database testdw set search_path to sc01,public,pg_catalog;   设置testdw数据库的搜索路径为sc01,public,pg_catalog;

ALTER DATABASE

testdw=# \q                                  改动完毕后通过\q退出testdw数据库后又一次登录

[gpadmin@master ~]$ psql -d testdw

psql (8.2.15)

Type "help" for help.

testdw=# show search_path;

search_path

--------------------------

sc01, public, pg_catalog

(1 row)

  • 通过ALTER ROLE改动ROLE(User)的模式搜索路径:

testdw-# \h alter role

Command:     ALTER ROLE

Description: change a database role

Syntax:

ALTER ROLE name RENAME TO newname

ALTER ROLE name SET config_parameter {TO | =} {value | DEFAULT}

ALTER ROLE name RESET config_parameter

ALTER ROLE name RESOURCE QUEUE {queue_name | NONE}

ALTER ROLE name [ [WITH] option [ ... ] ]

where option can be:

SUPERUSER | NOSUPERUSER

| CREATEDB | NOCREATEDB

| CREATEROLE | NOCREATEROLE

| CREATEEXTTABLE | NOCREATEEXTTABLE

[ ( attribute='value'[, ...] ) ]

where attributes and values are:

type='readable'|'writable'

protocol='gpfdist'|'http'|'gphdfs'

| INHERIT | NOINHERIT

| LOGIN | NOLOGIN

| CONNECTION LIMIT connlimit

| [ENCRYPTED | UNENCRYPTED] PASSWORD 'password'

| VALID UNTIL 'timestamp'

testdw=# select * from pg_roles;    查询pg_roles字典表

rolname  | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcatupdate | rolcanlogin | rolconnlimit | rolpassword | rolvaliduntil | rolconfig | rolresqueue |  oid  | rolcreaterextgpfd | rolcreaterexthttp | rolcreatewextgpfd | rolcreaterexthdfs |

olcreatewexthdfs

-----------+----------+------------+---------------+-------------+--------------+-------------+--------------+-------------+---------------+-----------+-------------+-------+-------------------+-------------------+-------------------+-------------------+-

-----------------

mavshuang | f        | t          | f             | f           | f            | t           |           -1 | ********    |               |           |        6055 | 16384 | f                 | f                 | f                 | f                 |

admin     | f        | t          | t             | t           | f            | f           |           -1 | ********    |               |           |        6055 | 16385 | f                 | f                 | f                 | f                 |

gpadmin   | t        | t          | t             | t           | t            | t           |           -1 | ********    |               |           |        6055 |    10 | t                 | t                 | t                 | t                 |

(3 rows)

testdw=# alter role mavshuang set search_path to public,sc01,pg_catalog;      改动mavshuang角色的搜索路径为public,sc01,pg_catalog;

ALTER ROLE

testdw=# select * from pg_roles;                                          再次查询显示

rolname  | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcatupdate | rolcanlogin | rolconnlimit | rolpassword | rolvaliduntil |                rolconfig                 | rolresqueue |  oid  | rolcreaterextgpfd | rolcreaterexthttp | rolcreate

extgpfd | rolcreaterexthdfs | rolcreatewexthdfs

-----------+----------+------------+---------------+-------------+--------------+-------------+--------------+-------------+---------------+------------------------------------------+-------------+-------+-------------------+-------------------+----------

--------+-------------------+-------------------

admin     | f        | t          | t             | t           | f            | f           |           -1 | ********    |               |                                          |        6055 | 16385 | f                 | f                 | f

| f                 | f

gpadmin   | t        | t          | t             | t           | t            | t           |           -1 | ********    |               |                                          |        6055 |    10 | t                 | t                 | t

| t                 | t

mavshuang | f        | t          | f             | f           | f            | t           |           -1 | ********    |               |{"search_path=public, sc01, pg_catalog"}|        6055 | 16384 | f                
| f                 | f

| f                 | f

(3 rows)

  • 查看当前的模式:通过current_schema()函数或者SHOW命令来查看:

testdw=# select current_schema();    仅仅能显示一个模式

current_schema

----------------

sc01

(1 row)

testdw=# show search_path;   显示当前数据库全部的模式

search_path

--------------------------

sc01, public, pg_catalog

(1 row)

  • 删除模式:使用DROPSCHEMA命令(空模式)

testdw=# \h drop schema

Command:     DROP SCHEMA

Description: remove a schema

Syntax:

DROP SCHEMA [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]  当该模式下有对象时能够使用CASCADE命令

testdw=# drop schema sc01;

DROP SCHEMA

  • 系统模式

pg_catalog模式存储系统日志表.内置类型.函数和运算符。

Information_schem模式由一个标准化视图构成。当中包括DB中对象的信息。

pg_toast模式是存储大对象(系统内部使用)

pg_bitmapindex模式存储bitmap index对象(系统内部使用)

pg_aoseg存储append-only表(系统内部使用)

gp_toolkit是管理用的模式,能够查看和检索系统日志文件和其它系统信息。

Greenplum中定义数据库对象之创建与管理模式的更多相关文章

  1. Greenplum+Hadoop学习笔记-14-定义数据库对象之创建与管理模式

    6.3.创建与管理模式 概述:DB内组织对象的一种逻辑结构.一个DB内能够有多个模式.在未指定模式时默认放置在public中.能够通过"\dn"方式查看数据库中现有模式: test ...

  2. MySQL笔记(二)数据库对象的创建和管理

    学校用 sqlserver ,记录数据移植到 mysql 过程中的一些问题(对应数据类型,主键外键等). 索引: 查看数据的物理路径 查看表相关的信息(SHOW CREATE TABLE.DESC) ...

  3. Hibernate数据库对象的创建与导出

    Hibernate 与数据库的关系是ORM关系,对象映射数据库. 那么如何通过对象对数据库进行各种对象的ddl与dml操作呢? 数据库对象操作的〈database-object /〉+ SchemaE ...

  4. MySQL中的数据库对象

    1.数据库中一般包含下列对象 表.约束.索引.触发器.序列.视图: 可以使用图形用户界面或通过显式执行语句来创建这些数据库对象.用于创建这些数据库对象的语句称为“数据定义语言”(DDL),它们通常以关 ...

  5. VB 中定义FileSystemObject对象,要先添加对象

     存取文件的方法有很多种,可以使用上述VB提供的函数,使用Windows API函数等等,但是最简单的方法是使用FileSystemObject对象. 1.使用FileSystemObject对象 F ...

  6. spring中容器和对象的创建流程

    容器和对象的创建流程 1.先创建容器 2.加载配置文件,封装成BeanDefinition 3.调用执行BeanFactoryPostProcessor 准备工作: 准备BeanPostProcess ...

  7. javascript 对象的创建与继承模式

    针对JS高级程序设计这本书,主要是理解概念,大部分要点源自书内.写这个主要是当个笔记加总结 存在的问题请大家多多指正! 6.1理解对象 创建对象的两个方法(暂时) //第一种,通过创建一个Object ...

  8. python类与对象-如何创建可管理的对象属性

    如何创建可管理的对象属性 问题举例 在面向对象编程中, 我们把方法看作对象的接口, 直接访问对象的属性可能是不安全的,或设计上不够灵活. 但是使用调用方法在形式上不如访问属性简洁. circle.ge ...

  9. 使用 HPC Pack 为 Azure 中的 Windows HPC 工作负荷创建和管理群集的选项

    利用 Microsoft HPC Pack 和 Azure 的计算与基础结构服务,创建和管理基于云的高性能计算 (HPC) 群集. HPC Pack 是在 Azure 和 Windows Server ...

随机推荐

  1. spark 从RDD createDataFrame 的坑

    Scala: import org.apache.spark.ml.linalg.Vectors val data = Seq( (7, Vectors.dense(0.0, 0.0, 18.0, 1 ...

  2. Metasploit渗透测试实验报告

    Metasploit渗透测试实验报告

  3. java操作文件的创建、删除、遍历

    java操作文件的创建.删除.遍历: package test; import java.io.File; import java.io.IOException; import java.util.A ...

  4. PostgreSQL Replication之第八章 与pgbouncer一起工作(1)

    当您在使用大规模的设施工作,可能有时候,您必须处理许多并发打开的连接.没有人会使用十台服务器来为两个并发用户提供服务--在许多情况下,这根本没有意义.大量的设施通常会处理成百上千的并发连接.引入连接池 ...

  5. 微星(MSI)新主板B150M MORTAR U盘装win7的坎坷经历

    新买的微星主板,热心的同事帮忙装好了win10,但是显卡驱动没装好,屏幕都快看瞎了眼,再者,楼主非常不喜欢win10的花哨,所以就装回了win7.下面来说一下我装win7的痛苦经历. 我是用UItra ...

  6. caioj 1086 动态规划入门(非常规DP10:进攻策略)

    一开始看到题目感觉很难 然后看到题解感觉这题贼简单,我好像想复杂了 就算出每一行最少的资源(完全背包+二分)然后就枚举就好了. #include<cstdio> #include<a ...

  7. Vue2.0组件实现动态搜索引擎(一)

    原文链接:https://blog.csdn.net/qwezxc24680/article/details/74550556 从github上看到一个不错的开源项目:https://github.c ...

  8. HDFS 文件系统流程图。PB级文件存储时序图。

    大小文件通吃, 热点hash功能. 全局唯一KV索引. 百度网盘模式.断点续传功能.MR分析功能. 来自为知笔记(Wiz)

  9. iOS开发之软键盘使用小技巧

    在iOS开发过程中,有时候须要弹出软键盘进行输入,有时候又须要在某些情况下隐藏软键盘,以提高用户体验. 今天有几个关于软键盘的小技巧和大家分享. (1)仅仅弹出数字键盘 有某些需求中,要求用户仅仅能在 ...

  10. 如何在IDEA中创建web项目并且部署到Tomcat中

    步骤1:File->New Project, 步骤2:选择Project SDK为1.7 -> Next -> Finish(JDK)我自己的是1.7(这里的project,跟ecl ...