创建与管理模式
- 概述: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=# |