testdw=# \dnsql List of schemas數據庫 Name | Owner api --------------------+---------app gp_toolkit | gpadmin函數 information_schema | gpadminspa pg_aoseg | gpadmin日誌 pg_bitmapindex | gpadminorm pg_catalog | gpadmin對象 pg_toast | gpadminip public | gpadmin (7 rows) |
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 [ ... ] ] |
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) |
testdw=# show search_path; search_path ---------------- "$user",public (1 row) |
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) |
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) |
testdw=# select current_schema(); 僅僅能顯示一個模式 current_schema ---------------- sc01 (1 row)
testdw=# show search_path; 顯示當前數據庫所有的模式 search_path -------------------------- sc01, public, pg_catalog (1 row) |
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是管理用的模式,可以查看和檢索系統日誌文件和其它系統信息。