GreenPlum database to create users, file space, table space, database

The previous articles describes the installation GreenPlum database, startup, shutdown, status check, log and other operations, the database has been created, then describes how to use the database. By convention, we need to create a test user, table space, database. Create a test user dbdream.

1 postgres=# create role dbdream password 'dbdream' createdb login;
2 NOTICE:  resource queue required -- using default resource queue "pg_default"
3 CREATE ROLE

Users typically create, given login privileges basic enough, create a user syntax can \ h create role command to see, do not make records. You can see the open database of user information by pg_roles dictionary.

1 postgres=# select rolname,oid from pg_roles;
2  rolname |  oid 
3 ---------+-------
4  gpadmin |    10
5  dbdream | 17197
6 (2 rows)

After creating a user, you also need to modify pg_hba.conf file to give users remote login privileges.

1 [gpadmin@mdw gpseg-1]$ vi pg_hba.conf
2 增加以下内容
3 host    all     dbdream         10.9.15.20/32   md5

After reloading the configuration file gpstop -u command to bring it into force, dbdream users can remotely access the database.

1 [gpadmin@mdw gpseg-1]$ psql -d postgres -U dbdream -h 10.9.15.20 -p 5432
2 Password for user dbdream:
3 psql (8.2.15)
4 Type "help" for help.

You can use \ c command or \ conninfo command to view the current login information.

1 postgres=> \c
2 You are now connected to database "postgres" as user "dbdream".

Create a table space need to create a file space file space is created in the operating system layer, create a control file need to specify the directory already exists, usually need to plan and create a directory. Master Segment and all nodes need to be created. You can use the following command to view the current database table space and file space correspondence.

1 postgres=# select a.spcname,b.fsname from pg_tablespace a,pg_filespace b where spcfsoid=b.oid;
2   spcname   |  fsname  
3 ------------+-----------
4  pg_default | pg_system
5  pg_global  | pg_system

Only pg_segment a current database file space, there are two tables pg_default and pg_global space above. The following create directories Master node.

1 [gpadmin@mdw ~]$ mkdir -p /gpdb/gpdata/fspc_master

Then create a directory Segment node by gpssh command Master node.

1 [gpadmin@mdw ~]$ gpssh -f /gpdb/app/config/seg_host -e 'mkdir -p /gpdb/gpdata/fspc_segment'
2 [sdw1] mkdir -p /gpdb/gpdata/fspc_segment
3 [sdw2] mkdir -p /gpdb/gpdata/fspc_segment
4 [sdw3] mkdir -p /gpdb/gpdata/fspc_segment

After creating the directory, you can create a file space by gpfilespace command.

1 gpadmin@mdw gpdata]$ gpfilespace
2 20160116:11:25:31:004066 gpfilespace:mdw:gpadmin-[INFO]:-
3 A tablespace requires a file system location to store its database
4 files. A filespace is a collection of file system locations for all components
5 in a Greenplum system (primary segment, mirror segment and master instances).
6 Once a filespace is created, it can be used by one or more tablespaces.
7  
8 20160116:11:25:31:004066 gpfilespace:mdw:gpadmin-[INFO]:-getting config
9 Enter a name for this filespace

Enter the name of the table space, just from the name, but can not be used at the beginning gp_.

01 > fspc1
02  
03 Checking your configuration:
04 Your system has 1 hosts with 0 primary and 0 mirror segments per host.
05 Your system has 3 hosts with 1 primary and 0 mirror segments per host.
06  
07 Configuring hosts: [mdw]
08  
09 Configuring hosts: [sdw1, sdw2, sdw3]
10  
11 Please specify 1 locations for the primary segments, one per line:
12 primary location 1>

Here Segment input node file space directory.

1 primary location 1> /gpdb/gpdata/fspc_segment
2  
3 Enter a file system location for the master
4 master location>

Enter here a few Master file space directory.

1 master location> /gpdb/gpdata/fspc_master
2 20160116:11:27:21:004066 gpfilespace:mdw:gpadmin-[INFO]:-Creating configuration file...
3 20160116:11:27:21:004066 gpfilespace:mdw:gpadmin-[INFO]:-[created]
4 20160116:11:27:21:004066 gpfilespace:mdw:gpadmin-[INFO]:-
5 To add this filespace to the database please run the command:
6    gpfilespace --config /gpdb/gpdata/gpfilespace_config_20160116_112531

After gpfilespace command is completed, will generate a configuration file, which is above the last row, / gpdb / gpdata / gpfilespace_config_20160116_112531, view the contents of this file are found, above gpfilespace command is only created a configuration file space, and not really create the file space.

1 [gpadmin@mdw gpdata]$ cat /gpdb/gpdata/gpfilespace_config_20160116_112531
2 filespace:fspc1
3 mdw:1:/gpdb/gpdata/fspc_master/gpseg-1
4 sdw1:2:/gpdb/gpdata/fspc_segment/gpseg0
5 sdw2:3:/gpdb/gpdata/fspc_segment/gpseg1
6 sdw3:4:/gpdb/gpdata/fspc_segment/gpseg2

这个文件可以自己创建并修改,真正创建文件空间需要运行刚才gpfilespace命令后的最后一行。

01 gpadmin@mdw gpdata]$ gpfilespace --config /gpdb/gpdata/gpfilespace_config_20160116_112531
02 20160116:11:29:19:004180 gpfilespace:mdw:gpadmin-[INFO]:-
03 A tablespace requires a file system location to store its database
04 files. A filespace is a collection of file system locations for all components
05 in a Greenplum system (primary segment, mirror segment and master instances).
06 Once a filespace is created, it can be used by one or more tablespaces.
07  
08 20160116:11:29:19:004180 gpfilespace:mdw:gpadmin-[INFO]:-getting config
09 Reading Configuration file: '/gpdb/gpdata/gpfilespace_config_20160116_112531'
10 20160116:11:29:19:004180 gpfilespace:mdw:gpadmin-[INFO]:-Performing validation on paths
11 ..............................................................................
12 20160116:11:29:19:004180 gpfilespace:mdw:gpadmin-[INFO]:-Connecting to database
13 20160116:11:29:19:004180 gpfilespace:mdw:gpadmin-[INFO]:-Filespace "fspc1" successfully created

这样才是真正创建完成文件空间,才能在数据库中查询到新建的文件空间信息。

1 postgres=# select * from pg_filespace;
2   fsname   | fsowner
3 -----------+---------
4  pg_system |      10
5  fspc1     |      10
6 (2 rows)

创建完文件空间,即可在文件空间上创建表空间,创建表空间必须使用support权限用户。

1 postgres-> \c postgres gpadmin
2 You are now connected to database "postgres" as user "gpadmin".
3  
4 postgres=# create tablespace tbs1 filespace fspc1;
5 CREATE TABLESPACE

非support权限用户要使用新建的表空间,必须要使用support用户对其授予操作权限才可以,否则会遇到下面的错误。

1 postgres=# \c dbdream dbdream
2 Password for user dbdream:
3 You are now connected to database "dbdream" as user "dbdream".
4  
5 dbdream=> create table t_test(id int,name varchar(10)) DISTRIBUTED BY(id);
6 ERROR:  permission denied for tablespace tbs1

要使用户默认就使用新建的表空间,需要设置用户的默认表空间。

1 postgres=# alter role dbdream set default_tablespace='tbs1';
2 ALTER ROLE

授权后,即可使用新建的表空间。

01 postgres-> \c postgres gpadmin
02 You are now connected to database "postgres" as user "gpadmin".
03  
04 dbdream=# grant all on tablespace tbs1 to dbdream;
05 GRANT
06  
07 dbdream=> create table t_test(id int,name varchar(10)) DISTRIBUTED BY(id);
08 CREATE TABLE
09 dbdream=> \d t_test
10            Table "public.t_test"
11  Column |         Type          | Modifiers
12 --------+-----------------------+-----------
13  id     | integer               |
14  name   | character varying(10) |
15 Distributed by: (id)
16 Tablespace: "tbs1"

具有createdb权限的用户,都可以创建数据库了,语法可以通过\h create database命令来查看,非常简单。比如下面这条命令就可以创建一个数据库。

1 postgres=> create database dbdream;
2 CREATE DATABASE

也可以在创建数据库时,指定数据库使用的默认表空间。

1 dbdream=# create database tt tablespace tbs1;
2 CREATE DATABASE

创建数据库的用户必须要有createdb权限或者support用户权限,这也是之前创建用户是为什么直接赋予了createdb权限,可以通过pg_database字典来查看数据库信息。

1 dbdream=# select datname,datdba,dattablespace from pg_database;
2   datname  | datdba |  dattablespace |
3 -----------+--------+----------------+
4  dbdream   |  17197 |           1663 |
5  postgres  |     10 |           1663 |
6  tt        |     10 |          17199 |
7  template1 |     10 |           1663 |
8  template0 |     10 |           1663 |
9 (5 rows)

datdba字段表示的是数据库的所有者(创建者),这里存的是用户的oid,10是gpadmin用户,17191是dbdream用户,可以通过pg_role字典来查看。dattablespace字段表示的是表空间。存的也是表空间的ID,1663是pg_default表空间,17199是新建的tbs1表空间,可以通过pg_tablespace字典开查看。

Permalink article: http://www.dbdream.com.cn/2016/01/greenplum%e6%95%b0%e6%8d%ae%e5%ba%93%e5%88%9b%e5%bb% ba% e7% 94% a8% e6% 88% b7% e3% 80% 81% e6% 96% 87% e4% bb% b6% e7% a9% ba% e9% 97% b4% e3% 80% 81% e8% a1% a8% e7% a9% ba% e9% 97% b4% e3% 80% 81% e6% 95% b0% e6% 8d% ae% e5% ba% 93 / | letter Chun, system stability, and closed line does not roll back the eye!

The log from the dbdream January 1 2016

Guess you like

Origin www.cnblogs.com/xibuhaohao/p/11131064.html
Recommended