Greenplum+Hadoop学习笔记-14-定义数据库对象之创建与管理数据库,hadoop-14-
6.定义数据库对象
6.1.创建与管理数据库
通过\h命令查看创建数据库的语法,如下所示:
|
testdw-# \h create database Command: CREATE DATABASE Description: create a new database Syntax: CREATE DATABASE name [ [ WITH ] [ OWNER [=] dbowner ] [ TEMPLATE [=] template ] [ ENCODING [=] encoding ] [ LC_COLLATE [=] lc_collate ] [ LC_CTYPE [=] lc_ctype ] [ TABLESPACE [=] tablespace ] [ CONNECTION LIMIT [=] connlimit ] ] 连接限制 |
说明:
- 一个GPDB系统可以有多个数据库;
- 关于数据库模版:可以基于模版创建数据库,缺省数据库模版为template1,GP系统内部使用模板:template0和postgres;
- 创建数据库应该具备CREATEDB权限或者SUPERUSER身份;
- 通过CREATEDATABASE 命令创建;
|
template1=# create database devdw; CREATE DATABASE |
- 克隆一个数据库
|
template1=#\c devdw 使用\c连接数据库 You are now connected to database "devdw" as user "gpadmin". devdw=# create table tab_01(id int); 创建表 NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'id' as the Greenplum Database data distribution key for this table. HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. CREATE TABLE devdw=# \d 使用\d查看表信息 List of relations Schema | Name | Type | Owner | Storage --------+--------+-------+---------+--------- public | tab_01 | table | gpadmin | heap (1 row) devdw=# insert into tab_01 values(101); 向表中插入数据 INSERT 0 1 devdw=# select * from tab_01; 查询表中信息 id ----- 101 (1 row) template1=# create database col_devdw template devdw; 使用devdw作为模板创建克隆数据库 CREATE DATABASE template1=# \l 使用\l命令查看当前所有数据库 List of databases Name | Owner | Encoding | Access privileges -----------+---------+----------+--------------------- col_devdw | gpadmin | UTF8 | devdw | gpadmin | UTF8 | postgres | gpadmin | UTF8 | template0 | gpadmin | UTF8 | =c/gpadmin : gpadmin=CTc/gpadmin template1 | gpadmin | UTF8 | =c/gpadmin : gpadmin=CTc/gpadmin testdw | gpadmin | UTF8 | (6 rows)
template1=# \c col_devdw You are now connected to database "col_devdw" as user "gpadmin". col_devdw=# \l List of databases Name | Owner | Encoding | Access privileges -----------+---------+----------+--------------------- col_devdw | gpadmin | UTF8 | devdw | gpadmin | UTF8 | postgres | gpadmin | UTF8 | template0 | gpadmin | UTF8 | =c/gpadmin : gpadmin=CTc/gpadmin template1 | gpadmin | UTF8 | =c/gpadmin : gpadmin=CTc/gpadmin testdw | gpadmin | UTF8 | (6 rows)
col_devdw=# \d List of relations Schema | Name | Type | Owner | Storage -------- 您可能想查找下面的文章:最近更新的内容
|

