创建与管理模式

  • 概述: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. 自定义标签 Unable to find setter method for attribute

    变量的首字母不能大写 http://blog.csdn.net/looksun/article/details/7690601

  2. hdoj--1301--Jungle Roads(克鲁斯卡尔)

    Jungle Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  3. CURRENMONTH TAG in Automation Framework

    /** * @param input * <CURRENTMONTH><CURRENTMONTH+1> * @return Month "MM" */ pr ...

  4. java9新特性-8-语法改进:钻石操作符(Diamond Operator)使用升级

    1.使用说明 我们将能够与匿名实现类共同使用钻石操作符(diamond operator) 在java8中如下的操作是会报错的:   编译报错信息:'<>' cannot be used ...

  5. PDO 拿出來的 Float 數據跟数据库中的数据不匹配

    数据库中的价格字段是 float 类型的,在 Laravel 中取出会出现这样的情况 数据库:71.9 -> 程序打印:72.0 数据库:75.2 -> 程序打印:75.3 在另外一个测试 ...

  6. DAG-背包九解-01背包

    饭卡:   电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够 ...

  7. laravel5.0 自定义服务类

    一.创建加密服务类 在 app\services 目录下创建 Encrypt.php <?php namespace App\Services; class Encrypt { } 二.注册服务 ...

  8. session 存入 redis

    <?php header('content-type:text/html;charset=utf-8'); /* * 更改 session 存储位置及存储方式. */ ini_set('sess ...

  9. TCP学习前的准备——可靠数据传输协议

    由于传输层所依赖的网络层是不可靠的,通过逐渐考虑实际情况不断引入新技术来实现可靠数据传输. 完全可信的信道 有比特差错的信道 新的协议功能: 1.    差错检测:检验和 2.    接收方反馈:序号 ...

  10. django-debug-toolbar 使用

    https://pypi.org/project/django-debug-toolbar/ https://django-debug-toolbar.readthedocs.io/en/latest ...