GP里面和PG不同的是,多了个filespace概念,在GP里面tablespace必须建立在filespace上面,所以建立表空间之前,先要有指定的filespace
filespace可以认为是多个文件目录的集合,可以对应一个或者多个tablespace
下面介绍一下创建filespace的实例:
1. su - gpadmin
2. 创建新的目录赋予权限
192-168-101-115
192-168-101-116
mkdir -p /data01/gpadmin/gpdata/master_hank
192-168-100-217
192-168-100-225
mkdir -p /data01/gpadmin/gpdata/primary_hank
mkdir -p /data01/gpadmin/gpdata/mirror_hank
赋予权限
chown -R gpadmin.gpadmin /data01/gpadmin/gpdata/master_hank /data01/gpadmin/gpdata/primary_hank /data01/gpadmin/gpdata/mirror_hank
3.生成配置文件
gpfilespace -o filespace_hank
20170317:17:05:13:020913 gpfilespace:db-192-168-101-115:gpadmin-[INFO]:-getting config
Enter a name for this filespace
> hank
Checking your configuration:
Your system has 2 hosts with 1 primary and 1 mirror segments per host.
Your system has 2 hosts with 0 primary and 0 mirror segments per host.
Configuring hosts: [db-192-168-100-225.sky-mobi.com, db-192-168-100-217.sky-mobi.com]
Please specify 1 locations for the primary segments, one per line:
primary location 1> /data01/gpadmin/gpdata/primary_hank
Please specify 1 locations for the mirror segments, one per line:
mirror location 1> /data01/gpadmin/gpdata/mirror_hank
Configuring hosts: [db-192-168-101-116.sky-mobi.com, db-192-168-101-115.sky-mobi.com]
Enter a file system location for the master
master location> /data01/gpadmin/gpdata/master_hank
20170317:17:05:34:020913 gpfilespace:db-192-168-101-115:gpadmin-[INFO]:-Creating configuration file...
20170317:17:05:34:020913 gpfilespace:db-192-168-101-115:gpadmin-[INFO]:-[created]
20170317:17:05:34:020913 gpfilespace:db-192-168-101-115:gpadmin-[INFO]:-
To add this filespace to the database please run the command:
gpfilespace --config /home/gpadmin/filespace_hank
创建filespace
gpfilespace -c filespace_hank
20170317:17:06:09:021026 gpfilespace:db-192-168-101-115: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.
20170317:17:06:09:021026 gpfilespace:db-192-168-101-115:gpadmin-[INFO]:-getting config
Reading Configuration file: 'filespace_hank'
20170317:17:06:09:021026 gpfilespace:db-192-168-101-115:gpadmin-[INFO]:-Performing validation on paths
..............................................................................
20170317:17:06:10:021026 gpfilespace:db-192-168-101-115:gpadmin-[INFO]:-Connecting to database
20170317:17:06:10:021026 gpfilespace:db-192-168-101-115:gpadmin-[INFO]:-Filespace "hank" successfully created
其实这里就是执行的create filespace语句
CREATE FILESPACE hank
(
1: '/data01/gpadmin/gpdata/master_hank/gpseg-1',
2: '/data01/gpadmin/gpdata/primary_hank/gpseg0',
3: '/data01/gpadmin/gpdata/primary_hank/gpseg1',
4: '/data01/gpadmin/gpdata/mirror_hank/gpseg0',
5: '/data01/gpadmin/gpdata/mirror_hank/gpseg1',
6: '/data01/gpadmin/gpdata/master_hank/gpseg-1'
);
postgres=# select * from pg_filespace;
fsname | fsowner
-----------+---------
pg_system | 10
hank | 10
postgres=# create TABLESPACE tbs_hank FILESPACE hank;
CREATE TABLESPACE
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 pgts.spcfsoid=pgfse.fsefsoid
AND pgfse.fsefsoid=pgfs.oid
ORDER BY tblspc, seg_dbid;
tblspc | filespc | seg_dbid | datadir
------------+-----------+----------+--------------------------------------------
pg_default | pg_system | 1 | /data01/gpadmin/gpdata/master/gpseg-1
pg_default | pg_system | 2 | /data01/gpadmin/gpdata/primary/gpseg0
pg_default | pg_system | 3 | /data01/gpadmin/gpdata/primary/gpseg1
pg_default | pg_system | 4 | /data01/gpadmin/gpdata/mirror/gpseg0
pg_default | pg_system | 5 | /data01/gpadmin/gpdata/mirror/gpseg1
pg_default | pg_system | 6 | /data01/gpadmin/gpdata/master/gpseg-1
pg_global | pg_system | 1 | /data01/gpadmin/gpdata/master/gpseg-1
pg_global | pg_system | 2 | /data01/gpadmin/gpdata/primary/gpseg0
pg_global | pg_system | 3 | /data01/gpadmin/gpdata/primary/gpseg1
pg_global | pg_system | 4 | /data01/gpadmin/gpdata/mirror/gpseg0
pg_global | pg_system | 5 | /data01/gpadmin/gpdata/mirror/gpseg1
pg_global | pg_system | 6 | /data01/gpadmin/gpdata/master/gpseg-1
tbs_hank | hank | 1 | /data01/gpadmin/gpdata/master_hank/gpseg-1
tbs_hank | hank | 2 | /data01/gpadmin/gpdata/primary_hank/gpseg0
tbs_hank | hank | 3 | /data01/gpadmin/gpdata/primary_hank/gpseg1
tbs_hank | hank | 4 | /data01/gpadmin/gpdata/mirror_hank/gpseg0
tbs_hank | hank | 5 | /data01/gpadmin/gpdata/mirror_hank/gpseg1
tbs_hank | hank | 6 | /data01/gpadmin/gpdata/master_hank/gpseg-1
建库,赋予权限,建表实例:
CREATE ROLE hank LOGIN ENCRYPTED PASSWORD 'hank' nosuperuser noinherit nocreatedb nocreaterole ;
CREATE DATABASE hank
WITH OWNER = gpadmin
TEMPLATE = template0
ENCODING = 'UTF8'
TABLESPACE = tbs_hank;
grant all on database hank to hank with grant option;
grant all on tablespace tbs_hank to hank;
\c hank hank
create schema hank;
grant usage on schema hank to hank;
create table tb1 (a bigint,b text) tablespace tbs_hank distributed by (a);
insert into tb1 select generate_series(1,10000),'hank'||generate_series(1,10000);