当前位置:网站首页>Greenplum 6.x common statements
Greenplum 6.x common statements
2022-07-07 08:47:00 【xcSpark】
One . Create directory
root Users log in to four servers , Each machine performs the following operations
[[email protected] tmp]# mkdir -p /datax/tbs_tmp
[[email protected] tmp]# mkdir -p /datax/tbs_tmp2
# Grant authority
[[email protected] tmp]# chown gpadmin:gpadmin /datax/*
Two . Create a library
gpadmin The user login master machine
[[email protected] ~]$ psql -d postgres
psql (9.4.24)
Type "help" for help.
postgres=# create database gpdb encoding='UTF8';
CREATE DATABA
gpdb=# SELECT datname from pg_database;
datname
-----------
template1
template0
postgres
gpperfmon
gpdb
(5 rows)
postgres=# \q
3、 ... and . Table space
gpadmin The user login master machine
Every Greenplum Database systems have the following default table spaces .
pg_global For sharing system directories .
pg_default, Default tablespace . from template1 and template0 Database usage . These tablespaces use the default system location , That is, the location of the data directory created during system initialization .
To view tablespace information , Please use pg_tablespace The table of contents gets the object of the table space ID(OID), And then use gp_tablespace_location() Function to display the table space directory . This is an example of listing a user-defined table space myspace:
[[email protected] tmp]# su - gpadmin
# Get into gpdb library
[[email protected] ~]$ psql -d gpdb
psql (9.4.24)
Type "help" for help.
# Create tablespace
gpdb=# create tablespace tbs_tmp location '/datax/tbs_tmp';
CREATE TABLESPACE
gpdb=# create tablespace tbs_tmp2 location '/datax/tbs_tmp2';
CREATE TABLESPACE
gpdb=#
########################## View tablespaces #####################
gpdb=# SELECT oid, * FROM pg_tablespace ;
oid | spcname | spcowner | spcacl | spcoptions
-------+------------+----------+-------------------------------------+------------
1663 | pg_default | 10 | |
1664 | pg_global | 10 | |
16658 | tbs_tmp2 | 10 | |
16657 | tbs_tmp | 10 | {
gpadmin=C/gpadmin,guser=C/gpadmin} |
(4 rows)
# Table space OID myspace yes 16657 . function gp_tablespace_location() To display the tablespace location of the system consisting of two segment instances and the primary instance
gpdb=# SELECT * FROM gp_tablespace_location(16657);
gp_segment_id | tblspc_loc
---------------+----------------
0 | /datax/tbs_tmp
7 | /datax/tbs_tmp
2 | /datax/tbs_tmp
4 | /datax/tbs_tmp
1 | /datax/tbs_tmp
6 | /datax/tbs_tmp
5 | /datax/tbs_tmp
3 | /datax/tbs_tmp
-1 | /datax/tbs_tmp
(9 rows)
gpdb=#
# This query uses gp_tablespace_location() Catalog gp_segment_configuration Table to display segment instance information and myspace File system location of the tablespace .
gpdb=# WITH spc AS (SELECT * FROM gp_tablespace_location(16657)) SELECT seg.role, spc.gp_segment_id as seg_id, seg.hostname, seg.datadir, tblspc_loc FROM spc, gp_segment_configuration AS seg WHERE spc.gp_segment_id = seg.content ORDER BY seg_id;
role | seg_id | hostname | datadir | tblspc_loc
------+--------+----------+-----------------------+----------------
p | -1 | mdw | /datax/master/gpseg-1 | /datax/tbs_tmp
m | -1 | smdw | /datax/master/gpseg-1 | /datax/tbs_tmp
p | 0 | sdw1 | /datax/primary/gpseg0 | /datax/tbs_tmp
m | 0 | sdw2 | /datax/mirror/gpseg0 | /datax/tbs_tmp
m | 1 | sdw2 | /datax/mirror/gpseg1 | /datax/tbs_tmp
p | 1 | sdw1 | /datax/primary/gpseg1 | /datax/tbs_tmp
m | 2 | sdw2 | /datax/mirror/gpseg2 | /datax/tbs_tmp
p | 2 | sdw1 | /datax/primary/gpseg2 | /datax/tbs_tmp
p | 3 | sdw1 | /datax/primary/gpseg3 | /datax/tbs_tmp
m | 3 | sdw2 | /datax/mirror/gpseg3 | /datax/tbs_tmp
m | 4 | sdw1 | /datax/mirror/gpseg4 | /datax/tbs_tmp
p | 4 | sdw2 | /datax/primary/gpseg4 | /datax/tbs_tmp
p | 5 | sdw2 | /datax/primary/gpseg5 | /datax/tbs_tmp
m | 5 | sdw1 | /datax/mirror/gpseg5 | /datax/tbs_tmp
m | 6 | sdw1 | /datax/mirror/gpseg6 | /datax/tbs_tmp
p | 6 | sdw2 | /datax/primary/gpseg6 | /datax/tbs_tmp
m | 7 | sdw1 | /datax/mirror/gpseg7 | /datax/tbs_tmp
p | 7 | sdw2 | /datax/primary/gpseg7 | /datax/tbs_tmp
(18 rows)
gpdb=#
Specify tablespace
SET default_tablespace = tbs_tmp;
CREATE TABLE foo(i int);
gpdb=# SET default_tablespace = tbs_tmp;
SET
gpdb=# CREATE TABLE foo(i int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' 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
gpdb=#
Delete tablespace
Be careful : If the table space is not empty or stores temporary files or transaction files , The tablespace cannot be deleted .
The tablespace owner or superuser has permission to delete tablespaces . Before deleting all objects in the database that use this tablespace , You cannot delete this tablespace .
DROP TABLESPACE xxx
Four . Create and manage patterns schema
establish schema
gpdb=# create schema tmp_schema;
CREATE SCHEMA
To create or access objects in a schema , Write a qualified name consisting of schema name and table name , And separated by a period . for example
myschema.table
for example , You can create patterns owned by others , To limit user activity to a well-defined namespace
CREATE SCHEMA
schemanameAUTHORIZATIONusername;
5、 ... and . User roles
User level roles are considered database roles that can log in to the database and initiate database sessions . therefore , When you use this command to create a new user level role CREATE ROLE, You must specify LOGIN jurisdiction . for example :
CREATE ROLE jsmith WITH LOGIN;
Create the role
# guser No login rights
gpdb=# create ROLE guser password 'guser';
NOTICE: resource queue required -- using default resource queue "pg_default"
CREATE ROLE
gpdb=# grant all on database gpdb to guser;
GRANT
# Have login permission
gpdb=# create ROLE guser2 WITH LOGIN password 'guser2';
NOTICE: resource queue required -- using default resource queue "pg_default"
CREATE ROLE
gpdb=#
Modify the permissions
ALTER ROLE
usernameWITH PASSWORD ‘passwd123’;
ALTER ROLE admin VALID UNTIL ‘infinity’;
ALTER ROLEusernameLOGIN;
ALTER ROLEusernameRESOURCE QUEUE que1;
ALTER ROLEusernameDENY DAY ‘Sunday’;
Role members
It is usually convenient to group users together to simplify the management of object permissions : such , You can grant or revoke permissions to an entire group .
CREATE ROLE admin CREATEROLE CREATEDB;
GRANT After the group role exists , You can use andREVOKE Command to add and remove members ( User roles )
GRANT admin TO user1, user2;
REVOKE admin FROM user3;
To manage object permissions , You will only grant appropriate permissions to group level roles , Then the member user role inherits the object permissions of the group role .
GRANT ALL ON TABLE mytable TO admin;
GRANT ALL ON SCHEMA myschema TO admin;
GRANT ALL ON DATABASE mydb TO admin;
Be careful : Character attributes LOGIN, SUPERUSER, CREATEDB, CREATEROLE,CREATEEXTTABLE and RESOURCE QUEUE It will never be inherited like the normal permissions of database objects .
User members must actually SET ROLE Only a specific role with one of these attributes can use this attribute
SET ROLE admin;
for example
gpdb=# ALTER ROLE guser2 SUPERUSER LOGIN CREATEDB;
ALTER ROLE
gpdb=#
6、 ... and . Grant authority
# Grant tablespace permissions to guser
gpdb=# GRANT CREATE ON TABLESPACE tbs_tmp TO guser;
GRANT
7、 ... and . Create table
CREATE TABLE foo(i int) TABLESPACE tbs_tmp;
8、 ... and . Remote login
Modify file
[[email protected] ~]$ vi /datax/master/gpseg-1/pg_hba.conf
# add to the content
host all guser2 0.0.0.0/0 trust
Make configuration effective
[[email protected] ~]$ gpstop -u
20220703:22:21:58:123477 gpstop:mdw:gpadmin-[INFO]:-Starting gpstop with args: -u
20220703:22:21:58:123477 gpstop:mdw:gpadmin-[INFO]:-Gathering information and validating the environment...
20220703:22:21:58:123477 gpstop:mdw:gpadmin-[INFO]:-Obtaining Greenplum Master catalog information
20220703:22:21:58:123477 gpstop:mdw:gpadmin-[INFO]:-Obtaining Segment details from master...
20220703:22:21:58:123477 gpstop:mdw:gpadmin-[INFO]:-Greenplum Version: 'postgres (Greenplum Database) 6.18.2 build commit:1242aadf0137d3b26ee42c80e579e78bd7a805c7'
20220703:22:21:58:123477 gpstop:mdw:gpadmin-[INFO]:-Signalling all postmaster processes to reload
.
20220703:22:21:59:123477 gpstop:mdw:gpadmin-[INFO]:---------------------------------------------
20220703:22:21:59:123477 gpstop:mdw:gpadmin-[INFO]:-Some segment postmasters were not reloaded
20220703:22:21:59:123477 gpstop:mdw:gpadmin-[INFO]:---------------------------------------------
20220703:22:21:59:123477 gpstop:mdw:gpadmin-[INFO]:- Host Datadir Port Status
20220703:22:21:59:123477 gpstop:mdw:gpadmin-[INFO]:- smdw /datax/master/gpseg-1 5432 u
20220703:22:21:59:123477 gpstop:mdw:gpadmin-[INFO]:---------------------------------------------
[[email protected] ~]$
Invalid login
Re execution of the following is invalid
[[email protected] ~]$ pg_ctl reload -D /datax/master/gpseg-1/
server signaled
[[email protected] ~]$
usage: Use tablespaces to store database objects
# Users with tablespace permissions CREATE You can create database objects in this tablespace , Such as table 、 Index and database
# Format :CREATE TABLE tablename(options) TABLESPACE spacename;
# In tablespace space1 Create a table in
CREATE TABLE foo(i int) TABLESPACE tbs_tmp;
# You can also use this parameter for commands that do not specify a tablespace default_tablespace Specify the default table space :CREATE TABLECREATE INDEX
SET default_tablespace = space1;
CREATE TABLE foo(i int);
Test data
gpadmin user
[[email protected] ~]$ psql -d gpdb
psql (9.4.24)
Type "help" for help.
gpdb=# SET default_tablespace = tbs_tmp;
SET
gpdb=# CREATE TABLE foo(i int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' 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
gpdb=#
# Insert 16 Data
gpdb=# insert into foo values(100000);
INSERT 0
Add data
gpdb=# select count(*) from foo;
count
---------
4854608
(1 row)
Initial data foo surface 16 strip , foo2 by 0 strip .
insert The data volume is as follows 
Change in size 


master Nodes have tbs_tmp Catalog 
sdw2 Of gpseg0
The final size comparison 
state 
边栏推荐
- The single value view in Splunk uses to replace numeric values with text
- Data type - floating point (C language)
- 2 - 3 arbre de recherche
- Implementation method of data platform landing
- Required String parameter ‘XXX‘ is not present
- [kuangbin] topic 15 digit DP
- Laravel8 uses passport login and JWT (generate token)
- Frequently Asked Coding Problems
- MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)
- Implementation of navigation bar at the bottom of applet
猜你喜欢
![[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology](/img/2a/01db1b84c26502c851786aaca56abe.jpg)
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology

調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error

下载和安装orcale database11.2.0.4

Greenplum6.x常用语句

2-3查找樹

PLSQL的安装和配置

The field value in Splunk subquery fuzzy matching CSV is*

ncs成都新電面試經驗

如何在HarmonyOS应用中集成App Linking服务

NCS Chengdu New Electric interview Experience
随机推荐
Low success rate of unit test report
[kuangbin] topic 15 digit DP
Thirteen forms of lambda in kotlin
All about PDF crack, a complete solution to meet all your PDF needs
2-3查找树
ncs成都新電面試經驗
idea里使用module项目的一个bug
iptables 之 state模块(ftp服务练习)
Opencv learning note 4 - expansion / corrosion / open operation / close operation
Gson converts the entity class to JSON times declare multiple JSON fields named
Count sort (diagram)
POJ - 3784 Running Median(对顶堆)
Input and output of floating point data (C language)
Several ways of lambda used in functions in kotlin (higher-order functions)
[machine learning] watermelon book data set_ data sharing
Greenplum6.x常用语句
23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
Go语言中,函数是一种类型
Routing information protocol rip
Data type - floating point (C language)