-
1
、创建用户
命令行
createuser -P
user1
SQL
命令
create user user1 with password 'user1'
nosuperuser;
使用新建的用户连接数据库必须
修改
pg_
文件,重启数据库服务
2
、创建角色
create role users;
--
将用户加入角色
grant users to user1;
3
、创建表空间
GreePlum
创建表空间要先创建目录,再创建文件空间,最后在文件空间的基
础上创建表空
间
查看目录情况
gpstate
-s|grep -e Datadir -e Address
检查有多少个
SEGMENT
,每个
SEGMENT
上有几个
primary
目录和
mirror
目录
p>
先找到
hostlist
文件,这个文件记
录了当前集群的所有数据节点列表,一行一个机器名称
gpssh -f hostlist
进入所有节点
进入后,键入
pwd,
确认能够正常连接
< br>
创建目录
,
目录位置必须当前操作系统用户能够访问
mkdir primary1 primary2 mirror1 mirror2
exit
退出
gpssh
创建主节点目录
gpssh -h mdw -h sdw1 //sdw1
为
standby
节点
mkdir master1
exit
创建文件空间
gpfilespace -o gpfs_
p>
//gpfs_
这个文件将存在当前工作目录下
[gpadmin@mdw ~]$$
gpfilespace -o gpfs_
20180110:13:52:45:026272
gpfilespace:mdw:gpadmin-[INFO]:-
A
tablespace requires a file system location to
store its database
files. A filespace
is a collection of file system locations for all
components
in a Greenplum system
(primary segment, mirror segment and master
instances).
Once a filespace is
created, it can be used by one or more
tablespaces.
20180110:13:52:45:026272
gpfilespace:mdw:gpadmin-[INFO]:-getting config
Enter a name for this filespace
> fs_test
Checking your configuration:
Your system has 1 hosts with 0 primary
and 0 mirror segments per host.
Your
system has 3 hosts with 2 primary and 2 mirror
segments per host.
Configuring hosts: [mdw]
Configuring hosts: [sdw3, sdw1, sdw2]
Please specify 2 locations
for the primary segments, one per line:
primary location 1>
/home/gpadmin/primary1
primary location
2> /home/gpadmin/primary2
Please specify 2 locations for the
mirror segments, one per line:
mirror
location 1> /home/gpadmin/mirror1
mirror location 2>
/home/gpadmin/mirror2
Enter
a file system location for the master
master location> /home/gpadmin/master1
20180110:13:54:05:026272
gpfilespace:mdw:gpadmin-[INFO]:-Creating
configuration file...
20180110:13:54:05:026272
gpfilespace:mdw:gpadmin-[INFO]:-[created]
20180110:13:54:05:026272
gpfilespace:mdw:gpadmin-[INFO]:-
To add
this filespace to the database please run the
command:
gpfilespace --config /home/gpadmin/
[gpadmin@mdw ~]$$
gpfilespace --config /home/gpadmin/
20180110:13:54:42:026362
gpfilespace:mdw:gpadmin-[INFO]:-
A
tablespace requires a file system location to
store its database
files. A filespace
is a collection of file system locations for all
components
in a Greenplum system
(primary segment, mirror segment and master
instances).
Once a filespace is
created, it can be used by one or more
tablespaces.
20180110:13:54:42:026362
gpfilespace:mdw:gpadmin-[INFO]:-getting config
Reading Configuration file:
'/home/gpadmin/'
20180110:13:54:43:026362
gpfilespace:mdw:gpadmin-[INFO]:-Performing
validation on paths
...................
..................................................
.........
20180110:13:54:43:026362
gpfilespace:mdw:gpadmin-[INFO]:-Connecting to
database
20180110:13:54:44:026362
gpfilespace:mdw:gpadmin-[INFO]:-Filespace
successfully
created
查看文件空间
select
oid,* from pg_filespace;
select * from
pg_filespace_entry;
可以重命名
alter
filespace fs_test rename to new_name;
创建表空间
必须是由超级用户创建,且在
Master
节点进行创建;<
/p>
使用
CREATE
TABLESPACE
命令;
创建完成后授予使用权限给普通用户;
create tablespace ts_test
filespace fs_test;
可以重命名
alter
tablespace ts_test rename to new_name;
授权使用
grant create
on tablespace testspace to user1;
查看表空间情况
db
使用表空间存储
DB
对象
使用指定表空间创建对象;
使用缺省
表空间参数
default_tablespace
来设定:<
/p>
SET default_tablespace = testspace
后创建表,
此时不需要指定表空间;
如果一个表空间与
DB
关联,那么其将存储所有该<
/p>
DB
的系统日志
.
临时文件等;
转移临时文件或事务文件的位置
作用
改善
DB
的查询性能
.
备份性能
.
连续存储数据的性能;
关于临时文件和事务文件
只有具备超级管理员权限的用户才可以移动位置,只有
gpfilesp
ace
工具可以写该文件;
只能为临
时文件或事务文件指定一个文件空间;
在生产系统中规划存储时,
需要专门为临时
文件或者事务文件创建固定的分区;
如果文件空间被临时文件使用,不能删除;
< br>使用
gpfilespace
移动临时文件
确保文件空间存在,
且与存储其他用户数据的文件空间不同;
但如果空间有限也可以
相同;
停止
GPDB
;
将
GPDB
启动为限制模式:
$$gpfilespace
–
movetempfilespace test_fs
p>
,
限制模式是为了保证
没有任何用户可以连
接到
GP
数据库中;
movetempfilespace
参数会检查当前
GP
数据库是否为限制模式,如果是启动状态
会重新启
动到限制模式;
如果是停止状态则启动到限制模式;
注意:
临时文件位置在
Instanc
e
中配合共享内存使用,
在创建、
打开
、
删除临时文件用到;
使用<
/p>
gpfilespace
移动事务文件
确保文件空间存在,且与存储其他用户数据的文件空间不同
停止
GPDB
将
GPDB
启动为限制模式:
$$g
pfilespace
–
movetransfilespace test_fs
注意:
事务文件位置在
Instance
中配合共享内存使用,
在创建
p>
打开
删除事务文件
时用到。
查看现有的表空间和文件空间
p>
2
个缺省表空间和
1
个缺省文件空间:
pg_global
:存储系统日志信息
pg_default
:存储
template1
和
template0
模版
DB
pg
_system
:系统初始化时使用的数据目录
获取文件空间的信息,查询语句如下所示:
SELECT spcname as tblspc, fsname as
filespc, fsedbid as seg_dbid, fselocation as
datadir
FROM
pg_tablespace pgts, pg_filespace pgfs,
pg_filespace_entry pgfse
WHERE id=id
AND id=
ORDER BY tblspc, seg_dbid;
删除表空间和文件空间
对象被删除前
,
表空间不能被删除,
表空间不能进行级联删除,
需要先删除该表空间中的对
象;
表空间被删除前,文件空间不能被删除;
通过
DROP
TABLESPACE
命令删除表空间;
通过
DROP FILESPACE
命令删除文件空间
4
、创建数据库
命令行
createdb
hsc;
sql
命令
create database gp_test Tablespace
ts_test;
5
、授权
GRANT ALL PRIVILEGES ON DATABASE
gp_test TO user1;
6
、创建
schema
DROP SCHEMA IF EXISTS user1 CASCADE;
CREATE SCHEMA user1 --
默认
owner
是登录用户
官方建议:
在管理员创建一个
具体数据库后,
应该为所有可以连接到该数据库的用户分别创
建
一个与用户名相同的模式,
然后,将
search_path
设置为
,这样
,任何当某个用户连接上来后,会默认将查找或
者定义的对象都定位到与之同名的模式中
。
修改
owner
alter
schema user1 owner to user1;
创建一个他人拥有的
schema
CREATE SCHEMA schemaname AUTHORIZATION
username;
甚至可以省略模式名字,这时模式名将和用户名同名。
以
pg_
开头的模式名是保留给系统使用的,
用户不能创建这样的名字
7
、修改
search_path
show search_path;
--session
级别修改
SET SEARCH_PATH TO user1, public;
--database
级别修改
ALTER ROLE user1 SET search_path TO
user1, public;
8
、建表
create table
t_test (datakey varchar(32),
dataversion varchar(30)) distributed
by (datakey);
DISTRIBUTED
RANDOMLY
查看表的大小
select
pg_size_pretty(pg_relation_size('t_test'));
查看数据库大小:
查看服务器配置:
-
-
-
-
-
-
-
-
-
上一篇:煤炭专业英语词汇
下一篇:PID图例符号介绍要点