创建与管理模式

  • 概述: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. bzoj1029: [JSOI2007]建筑抢修(堆+贪心)

    1029: [JSOI2007]建筑抢修 题目:传送门 题解: 一道以前就做过的水题(找个水题签个到嘛...) 很明显就是一道贪心题,这里我们用一个堆来维护 具体看代码吧,很容易YY所以不讲 代码: ...

  2. BZOJ 4551 HEOI 2016 树 (并查集)

    思路: 考虑时光倒流 这不就是并查集裸题了-----. //By SiriusRen #include <cstdio> #include <cstring> #include ...

  3. POJ 2528 线段树

    坑: 这道题的坐标轴跟普通的坐标轴是不一样的-- 此题的坐标轴 标号是在中间的-- 线段树建树的时候就不用[l,mid][mid,r]了(这样是错的) 直接[l,mid][mid+1,r]就OK了 D ...

  4. 查询目标的ip地址和详细地理信息(多种方法)

    不多说,直接上干货! 至于这里怎FQ,很简单,请见我下面的博客! kali 2.0安装 lantern(成功FQ) shadowsocks(简称SSFQ软件)步骤详解 FQ软件lantern-inst ...

  5. 监控rman备份

    1.服务会话关联通道设置 set COMMAND ID 命令 2.查询V$PROCESS和V$SESSION 决定会话对应的RMAN的通道 3.查询V$session_LONGGOPS监控备份集和复制 ...

  6. Python常用目录操作(Python2)

    Python获取当前路径   Python查看指定路径下的文件和文件夹 Python修改当前工作目录(在读取文件等时需要) Python添加import路径(有时候为了import自己写的py文件,且 ...

  7. ajax发送请求的数据类型

    1.如果要传给后台的是json形式的数据 2.如果要传给后台的是formdata形式的数据

  8. HDU-2303 The Embarrassed Cryptographer 高精度算法(大数取模)

    题目链接:https://cn.vjudge.net/problem/HDU-2303 题意 给一个大数K,和一个整数L,其中K是两个素数的乘积 问K的是否存在小于L的素数因子 思路 枚举素数,大数取 ...

  9. [HNOI2004]高精度开根

    题目:洛谷P2293.BZOJ1213. 题目大意:给你$n,k(n\leq 10^{10000},k\leq 50)$,求$\lfloor \sqrt[k]{n}\rfloor$. 解题思路:高精度 ...

  10. BNUOJ 4049 四叉树

    四叉树 Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Ma ...