签到成功

知道了

CNDBA社区CNDBA社区

Oracle 18c 必须掌握的新特性 Sharding系列(8) -- GDSCTL 命令使用说明

2019-10-30 17:12 2635 0 原创 Oracle 18c
作者: dave

GDSCTL 工具是Sharding最主要的管理工具。https://www.cndba.cn/cndba/dave/article/3765

[dave@www.cndba.cn ~]$ gdsctl
GDSCTL: Version 18.0.0.0.0 - Production on Wed Oct 10 21:14:22 CST 2018

Copyright (c) 2011, 2018, Oracle.  All rights reserved.

Welcome to GDSCTL, type "help" for information.

Current GSM is set to SHARDDIRECTOR1
GDSCTL> help

add brokerconfig              add cdb                       add credential
add database                  add file                      add gdspool
add gsm                       add invitednode               add invitedsubnet
add region                    add service                   add shard
add shardgroup                add shardspace                alter move
config                        config cdb                    config chunks
config credential             config database               config file
config gdspool                config gsm                    config region
config sdb                    config service                config shard
config shardgroup             config shardspace             config vncr
configure                     connect                       create catalog
create gdscatalog             create shard                  create shardcatalog
databases                     delete catalog                deploy
disable service               enable service                exit
export catalog                help                          import catalog
modify catalog                modify cdb                    modify credential
modify database               modify file                   modify gdspool
modify gsm                    modify region                 modify service
modify shard                  modify shardgroup             modify shardspace
move chunk                    quit                          recover shard
relocate service              remove brokerconfig           remove cdb
remove credential             remove database               remove file
remove gdspool                remove gsm                    remove invitednode
remove invitedsubnet          remove region                 remove service
remove shard                  remove shardgroup             remove shardspace
routing                       services                      set dataguard_property
set gsm                       set inbound_connect_timeout   set log_status
set outbound_connect_timeout  set trace_level               set trc_level
show ddl                      split chunk                   sql
start gsm                     start observer                start service
status                        status database               status gsm
status routing                status service                stop gsm
stop service                  sync brokerconfig             sync database
synchronize brokerconfig      synchronize database          validate
validate catalog
GDSCTL>

这些命令主要分为以下几种功能:add,config,create,modify, remove, set, start,stop,status, 然后每个功能可以操作相关的对象,比如:database,gsm,region,service,shard,shardgroup,shardspace,chunks,sdb等。命令比较多,但也不需要刻意的去记忆,只要知道怎么分类的,怎么查看帮助就可以了。 https://www.cndba.cn/cndba/dave/article/3765

一般向config类的查看信息的命令,是不需要添加参数的,直接执行即可:https://www.cndba.cn/cndba/dave/article/3765

GDSCTL> config chunks
Chunks
------------------------
Database                      From      To        
--------                      ----      --        
sh1                           1         12        
sh22                          1         12        

GDSCTL> config shard
Name                Shard Group         Status    State       Region    Availability 
----                -----------         ------    -----       ------    ------------ 
sh1                 primary_grp         Ok        Deployed    region1   ONLINE       
sh22                standby_grp         Ok        Deployed    region2   READ ONLY    

GDSCTL> config shardgroup
Shard Group         Chunks Region              Shard space         
-----------         ------ ------              -----------         
primary_grp         12     region1             shardspaceora       
standby_grp         12     region2             shardspaceora       

GDSCTL> config shardspace
Shard space                   Chunks                        
-----------                   ------                        
shardspaceora                 12                            

GDSCTL> config service

Name           Network name                  Pool           Started Preferred all 
----           ------------                  ----           ------- ------------- 
oltp_ro_servci  oltp_ro_servcie.cust_sdb.orad cust_sdb       Yes     Yes           
e              bcloud                                                             
oltp_rw_servci oltp_rw_servcie.cust_sdb.orad cust_sdb       Yes     Yes           
e              bcloud

其他的功能命令可以在后面加-h来查看具体的使用方法,比如:

GDSCTL> remove shard -h
Syntax
REMOVE SHARD {-SHARD {shard_name_list | ALL} | -SHARDSPACE shardspace_list |    
-SHARDGROUP shardgroup_list} [-FORCE]                                           

Purpose
Removes one or more shards from the sharded database.                           

Usage Notes
-SHARD ALL removes all shards from sharded pool.                                

Keywords and Parameters
force:      remove specified shard(s) even if they are inaccessible and/or contain
            chunks. No resharding will be initiated when using this option. It may
            result in a lower number of replicas or total unavailability for a certain
            range of data.
shard:      a comma-delimited list of shards.
shardgroup: a comma-delimited list of shardgroups.
shardspace: a comma-delimited list of shardspaces.

Examples
REMOVE SHARD -SHARDGROUP group1

1 Oracle 18c Sharding 删除catalog 步骤

在Oracle Sharding 中删除shard分片是要非常谨慎,如果shard中还存在chunks,那么删除时会报错,如下:

[dave@www.cndba.cn ~]$ gdsctl
GDSCTL: Version 18.0.0.0.0 - Production on Sat Oct 13 11:08:22 CST 2018

Copyright (c) 2011, 2018, Oracle.  All rights reserved.

Welcome to GDSCTL, type "help" for information.

Current GSM is set to SHARDDIRECTOR
GDSCTL> config shard
Name                Shard Group         Status    State       Region    Availability 
----                -----------         ------    -----       ------    ------------ 
sh101               normal_grp          Ok        Deployed    region1   READ ONLY    
sh102               primary_grp         Ok        Deployed    region1   ONLINE       
sh103               standby_grp         Ok        Deployed    region2   READ ONLY    

GDSCTL> remove shard -shard sh101
GSM-45029: SQL error
ORA-02659: cannot remove a shard which contains chunks
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 13392
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 13174
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 12973
ORA-06512: at line 1

可以将这些chunk转移走,或者用force强制来进行删除,但注意,在使用force时,会删掉所有shard,而不是我们指定的那个, 如下:https://www.cndba.cn/cndba/dave/article/3765

GDSCTL> remove shard -h
Syntax
REMOVE SHARD {-SHARD {shard_name_list | ALL} | -SHARDSPACE shardspace_list |    
-SHARDGROUP shardgroup_list} [-FORCE]                                           

Purpose
Removes one or more shards from the sharded database.                           

Usage Notes
-SHARD ALL removes all shards from sharded pool.                                

Keywords and Parameters
force:      remove specified shard(s) even if they are inaccessible and/or contain
            chunks. No resharding will be initiated when using this option. It may
            result in a lower number of replicas or total unavailability for a certain
            range of data.
shard:      a comma-delimited list of shards.
shardgroup: a comma-delimited list of shardgroups.
shardspace: a comma-delimited list of shardspaces.

Examples
REMOVE SHARD -SHARDGROUP group1

GDSCTL> remove shard -shard sh101 -force
GSM Warnings: 
CATALOG:ORA-03713: Shard 'sh101' contained 12 chunks.
CATALOG:ORA-02660: Shard 'sh102' was also removed.
CATALOG:ORA-03713: Shard 'sh102' contained 12 chunks.
CATALOG:ORA-02660: Shard 'sh103' was also removed.
CATALOG:ORA-03713: Shard 'sh103' contained 12 chunks.

GDSCTL> config shard
Name                Shard Group         Status    State       Region    Availability 
----                -----------         ------    -----       ------    ------------ 

此时如果在将这些shard添加到catalog中,会提示shard已经存在,所以这里可以先将catalog也删除掉,在重新添加:
GDSCTL> delete catalog
There are still some gsms connected to catalog. Do you want to continue? (Y/N)y
GDSCTL>
因为sharding 在deploy时会在每个shard上创建数据库实例,所以这里还需要将这些数据库和监听一起关闭,否则添加时还会报错。每天添加后,产生的数据库实例名都不相同,所以还要注意修改环境变量:
[oracle@shard1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 18.0.0.0.0 - Production on Sat Oct 13 13:10:28 2018
Version 18.3.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.


Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0

SQL> shutdown abort
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
[oracle@shard1 ~]$ lsnrctl stop

LSNRCTL for Linux: Version 18.0.0.0.0 - Production on 13-OCT-2018 13:12:18

Copyright (c) 1991, 2018, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
The command completed successfully
[oracle@shard1 ~]$

最后是删除gsm参数中的director的信息。https://www.cndba.cn/cndba/dave/article/3765

[dave@www.cndba.cn admin]$ pwd
/u01/app/oracle/product/18.3.0/dbhome_1/network/admin
[dave@www.cndba.cn admin]$ cat gsm.ora 
# gsm.ora Network Configuration File: /u01/app/oracle/product/18.3.0/dbhome_1/network/admin/gsm.ora
# Generated by Oracle configuration tools.
SQLNET.WALLET_OVERRIDE = TRUE
WALLET_LOCATION =
  (SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
      (DIRECTORY = /u01/app/oracle/product/18.3.0/dbhome_1/network/admin/gsmwallet)
    )
  )

设置gsmcatuser密码
SQL> alter user gsmcatuser identified by oracle;

最后再次确认删除干净,就可以重新开始sharding的创建工作了:
GDSCTL> config
Regions
------------------------
GSMs
------------------------
GDS pools
------------------------
Databases
------------------------
Services
------------------------
GDSCTL pending requests
------------------------
Command                       Object                        Status                        
-------                       ------                        ------                        
Global properties
------------------------
GDSCTL>

2 Oracle 18c Sharding GSM 的配置文件gsm.ora

因为之前环境Sharding 出现错误,把整个catalog都delete掉了。 然后重新创建的,创建完之后,发现gdsctl连接时会提示当前连接的GSM:https://www.cndba.cn/cndba/dave/article/3765

https://www.cndba.cn/cndba/dave/article/3765

[dave@www.cndba.cn ~]$ gdsctl
GDSCTL: Version 18.0.0.0.0 - Production on Thu Oct 11 15:20:50 CST 2018

Copyright (c) 2011, 2018, Oracle.  All rights reserved.

Welcome to GDSCTL, type "help" for information.

Current GSM is set to SHARDDIRECTOR1
GDSCTL> create shardcatalog -database shardcatalog:1521:shardcatalog -chunks 12 -user sdbadmin/oracle -sdb cust_sdb -region region1,region2 -agent_port 8080 -agent_password oracle
Catalog is created

GDSCTL> connect sdbadmin/oracle
Catalog connection is established
GDSCTL> add gsm -gsm sharddirector -listener 1571 -pwd oracle -catalog shardcatalog:1521:shardcatalog -region region1
GSM-45029: SQL error
ORA-01017: invalid username/password; logon denied

这里报用户名和密码不对,在SQLPLUS里修改一下:
SQL> alter user gsmcatuser identified by oracle; 

然后继续操作:
GDSCTL> add gsm -gsm sharddirector -listener 1571 -pwd oracle -catalog shardcatalog:1521:shardcatalog -region region1

GSM successfully added
GDSCTL> 
GDSCTL> config gsm
Name      Region    ENDPOINT                                                    
----      ------    --------                                                    
sharddire region1   (ADDRESS=(HOST=shardcatalog)(PORT=1571)(PROTOCOL=tcp))      
ctor                                                                            

退出来GDSCTL重新连接,就提示我们有2个GSM实体:
[dave@www.cndba.cn ~]$ gdsctl
GDSCTL: Version 18.0.0.0.0 - Production on Thu Oct 11 15:25:12 CST 2018

Copyright (c) 2011, 2018, Oracle.  All rights reserved.

Welcome to GDSCTL, type "help" for information.

Warning:  gsm.ora contain several GSM entries: 
 SHARDDIRECTOR, SHARDDIRECTOR1
Current GSM is set to SHARDDIRECTOR
GDSCTL>

这里的信息实际上来自$ORACLE_HOME/network/admin/gsm.ora文件:
[dave@www.cndba.cn ~]$ cat /u01/app/oracle/product/18.3.0/dbhome_1/network/admin/gsm.ora
# gsm.ora Network Configuration File: /u01/app/oracle/product/18.3.0/dbhome_1/network/admin/gsm.ora
# Generated by Oracle configuration tools.

SQLNET.WALLET_OVERRIDE = TRUE

SHARDDIRECTOR =
  (configuration =
    (listener =
      (ADDRESS = (HOST = shardcatalog)(PORT = 1571)(PROTOCOL = tcp))
    )
    (cloud = oradbcloud)
  )

WALLET_LOCATION =
  (SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
      (DIRECTORY = /u01/app/oracle/product/18.3.0/dbhome_1/network/admin/gsmwallet)
    )
  )

SHARDDIRECTOR1 =
  (configuration =
    (listener =
      (ADDRESS = (HOST = shardcatalog)(PORT = 1571)(PROTOCOL = tcp))
    )
    (cloud = oradbcloud)
  )
删掉一个再连接,就剩一个了:
[dave@www.cndba.cn ~]$ gdsctl
GDSCTL: Version 18.0.0.0.0 - Production on Thu Oct 11 15:35:26 CST 2018

Copyright (c) 2011, 2018, Oracle.  All rights reserved.

Welcome to GDSCTL, type "help" for information.

Current GSM is set to SHARDDIRECTOR
GDSCTL>

3 启用Sharding的Trace

Sharding管理中可能会遇到各种问题,可以通过启用Trace来收集更详细的信息,从而帮助分析问题。可以设置GWM_TRACE的级别来启用不同的级别的trace。设置的方式有两种,如下:

1、立即启用trace,重启后失效:https://www.cndba.cn/cndba/dave/article/3765

https://www.cndba.cn/cndba/dave/article/3765

alter system set events ‘immediate trace name gwm_trace level 7’;

https://www.cndba.cn/cndba/dave/article/3765

2、永久启用trace,但是要重启才生效

alter system set event=’10798 trace name context forever, level 7’ scope=spfile;

如果想跟踪Oracle Sharding环境中所有数据库的相关信息,就需要在所有分片上启用trace。 这些也可以通过GDSCTL工具进行设置。

查看命令帮助:

GDSCTL> set trace_level -h
Syntax
SET (TRACE_LEVEL|TRC_LEVEL {off,user,admin,support}| LOG_STATUS ON|OFF          
|INBOUND_CONNECT_TIMEOUT <timeout_value> | OUTBOUND_CONNECT_TIMEOUT             
<timeout_value>) [-gsm <gsm_name>] [-save_config | -config_only]                

Purpose
Alter the parameter values for the GSM listener.By default, parameter values    
changes remain in effect until the GSM is shut down.                            

Usage Notes
See Oracle Database Net Services Reference guide for details                    

Keywords and Parameters
config_only: Update GSM.ORA only without trying to connect to running GSM instance.
gsm:         GSM name.
save_config: Store configuration changes to GSM.ORA .

Examples
SET TRC_LEVEL SUPPORT
SET INBOUND_CONNECT_TIMEOUT 2
SET OUTBOUND_CONNECT_TIMEOUT 3
SET LOG_STATUS ON -save_config

配置完成后可以通过status gsm或status查看trace文件的位置和名称
[dave@www.cndba.cn ~]$ gdsctl
GDSCTL: Version 18.0.0.0.0 - Production on Mon Oct 15 23:56:27 CST 2018

Copyright (c) 2011, 2018, Oracle.  All rights reserved.

Welcome to GDSCTL, type "help" for information.

Current GSM is set to SHARDDIRECTOR
GDSCTL> connect sdbadmin/oracle
Catalog connection is established
GDSCTL> set trace_level support log_status on -save_config
GSM-45068: A valid trace level was not specified 
注:这里这里的级别和启用必须分开执行,一起写会报错。

GDSCTL> set trace_level support 
trace_level is set to SUPPORT
GDSCTL> set log_status on -save_config
log_level is set to on
GDSCTL> status
Alias                     SHARDDIRECTOR
Version                   18.0.0.0.0
Start Date                15-OCT-2018 23:56:17
Trace Level               support
Listener Log File         /u01/app/oracle/diag/gsm/shardcatalog/sharddirector/alert/log.xml
Listener Trace File       /u01/app/oracle/diag/gsm/shardcatalog/sharddirector/trace/ora_20398_140401312668544.trc
Endpoint summary          (ADDRESS=(HOST=shardcatalog)(PORT=1571)(PROTOCOL=tcp))
GSMOCI Version            2.2.1
Mastership                Y
Connected to GDS catalog  Y
Process Id                20401
Number of reconnections   0
Pending tasks.     Total  0
Tasks in  process. Total  0
Regional Mastership       TRUE
Total messages published  3
Time Zone                 +08:00
Orphaned Buddy Regions:   
     None
GDS region                region1

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2239
    原创
  • 3
    翻译
  • 547
    转载
  • 186
    评论
  • 访问:6666270次
  • 积分:4249
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ