Quantcast
Channel: 12c – OracleBlog
Viewing all 61 articles
Browse latest View live

12c无法按照预期修改parallel_max_servers

$
0
0

客户有个12c的环境,正在做xtts的迁移,从10g迁移到12c。其中一项要求是12c的一些初始化参数和10g一致,如parallel_max_servers。发现设置后,重启了数据库,还是无法达到预期的修改值。

SQL> show parameter parallel_max_servers
NAME                    TYPE       VALUE
----------------------  -----     ---------
parallel_max_servers    integer    474


SQL> alter system set parallel_max_servers=585 scope=spfile;


shutdown immediate;
startup;


SQL> show parameter parallel_max_servers
NAME                    TYPE       VALUE
----------------------  -----     ---------
parallel_max_servers    integer    474

打开其alertlog中,我们可以看到类似如下的信息:

Adjusting the altered value of parameter parallel_max_servers
from 585 to 474 due to the value of parameter processes (600)
……

我们在Doc ID 1968840.1处看到:

From 11gR2 onwards, there is a new method to compute the default for PARALLEL_MAX_SERVERS.
In 11gR2, the value of  PARALLEL_MAX_SERVERS is capped by PROCESSES - 15.
In 12c, the value of PARALLEL_MAX_SERVERS is capped by PROCESSES - N, where N is the result of an internal calculation that estimates the maximum number of background processes that need to be reserved for the particular database.

parallel_max_servers的最大值,受限制与process,在11gR2中,这个限制是parallel_max_servers=processes-15(另外,在11.2.0.4中变成了30).

而在12c中,是processes-N,这个N是一个内部算法。具体的值可以通过如下来得到:

SQL> select KSBNEEDED_VAL into v_process_reserved from sys.X$KSBDPNEEDED ;
SQL>

所以在12c中的parallel_max_servers可以设置的最大值,为process-(KSBNEEDED_VAL.X$KSBDPNEEDED)。

参考:
How PARALLEL_MAX_SERVERS and PROCESSES Parameters are Related? (Doc ID 1968840.1)
New Default Value of PARALLEL_MAX_SERVERS in Release 11.2.0.2 (Doc ID 1377411.1)
Oracle Community:The value of parallel_max_server adjusted in alertlog of 12c(12.1.0.2) database is not as per the formula mentioned in the (Doc ID 1968840.1)


sharding db的HA架构

$
0
0

sharding database最大的特点是可以横向扩展。但是横向扩展不是RAC的横向扩展,纯sharding db是没有HA架构的。即一个shardcat db,多个shard node db。无论是谁down了,都会造成不可用。

我们从上往下捋一下,看看哪里有单点故障,这个单点可以通过什么方式解决,

我们知道,sharding的架构大致如下,
shard-arcth

(1). 从应用端发起之后,往下是connection pool,这个connection pool,指的是Oracle Integrated connections pools (UCP, OCI, ODP.NET, JDBC)。这个connection pool,不在本文的讨论范围内,这个是涉及到中间件的高可用问题。

(2). 往下是shard director(gsm)和shardcat数据库。这涉及到一个路由的分类。直接路由(direct route)还是代理路由(proxy route)

(2.1). 直接路由是基于sharding key,在connection pool中的connect阶段就实现了。如果在connection pool(以下以UCP为例)有缓存,缓存着sharding key的range,和shard以及chunk的mapping关系,所以直接忽略shard director,直接到某个shard,node;
direct_route_bypass_sharddir
如果在UCP中没有缓存,则到shard director中找一次,再去shard node。且下一次执行的时候,由于已经缓存,就不再需要去shard director中找了。
direct_route_use_sharddir

在直接路由模式下,当连接请求是包含sharding key的,即UCP的连接可以使用sharding相关的API,如pds.createShardingKeyBuilder() 和pds.createConnectionBuilder() ,相关的操作就直接去对应的数据库分片了。

(2.2). 代理路由模式是不基于sharding key的访问,或者是需要查询multi shard的数据,那就需要coordinator database,也就是shardcat数据库。应用就需要通过shardcat数据库,才能找到对应的shard node。
proxy_route_use_shardcat

所以说,对于直接路由模式,我们有可能出现的问题,是shard director进程挂了。对于这个问题的解决,我们可以设置多个shard director,每个region最多可以设置5个shard director。shard director的功能,类似于向listener,你可以认为它是一个region listener。接受来自某一个区域的连接,然后进行路由。

对于代理模式,我们需要经过shardcat数据库,那么就可以使用到shardcat数据库的高可用方案了。如ADG,如RAC。在sharding的高可用方案中,我们是优先考虑ADG,再考虑RAC。

另外在提一下,由于如果不是multi shard的查询,就不经过shardcat数据库,所以如果shardcat down了,但是如果只有某个分片的transaction,那么也是不受到影响的。

(3). 再往下,就是shard node了,每个shard node包含分片数据,当一个shard node挂掉的时候,shard table的其他分片,即使是活的,也是无法查询这个shard table。

所以,我们要对shard node建立ADG,且启用FSFO。(我会写另外一个文章,介绍如何deploy带ADG的shard node)。如果不用ADG,那么OGG也是另外一种高可用的方案。此外,还有RAC,也避免一个shard node主机挂掉,注意,只是防止主机挂掉,不能防止存储挂掉。如果要防止存储挂掉,还是要建ADG。(这也是为什么sharding的最佳实践,是建立ADG,而RAC方案只是optional)

但是由于ADG的FSFO切换影响较大,因此最好的方式,还是RAC+ADG,即如果一个shard node的一个机器挂了,那么在RAC架构下,还有另外一台机器能顶住,不会有问题。如果2个节点都挂了,才FSFO切换到standby。

所以,sharding的HA最佳实践,应该是如下的:
sharding_ha
有2个区域(region),每个region有2个或以上的gsm(shard director),然后shardcat数据库有ADG(可以再加RAC),后面的shard node也是要做ADG+FSFO(可以在加RAC)。

Step by Step建立带ADG的sharding db

$
0
0

上次的文章,我们说到sharding其实是非常需要HA架构的,我们今天来安装一个带ADG的sharding node的sharding database。
(我只是把shard node做成了ADG,且没有加RAC架构,shardcat也没有做ADG,因为……我的虚拟机实在吃不消了!)

1.大致环境介绍:
5台主机:
sdb1装shardcat,
sdb2装shard node,sh1,
sdb3装shard node,sh2,
sdb4装shard node,sh3,
sdb5装shard node,sh4,
其中sh1和sh3互为主备,sh2和sh4互为主备。

sh1和sh2在region1,成为一个primary_shardgroup的shard group
sh3和sh4在region2,成为一个standby_shardgroup的shard group。

2.开始安装

2.1 在5个主机安装12.2数据库软件,在sdb1建立shardcat数据库实例。

2.2 在sdb1的shardcat数据库:

SQL> alter system set db_create_file_dest='/u01/ora12c/app/oracle/oradata' scope=both;
SQL> alter system set open_links=16 scope=spfile;
SQL> alter system set open_links_per_instance=16 scope=spfile;
SQL> startup force
SQL>
SQL> alter user gsmcatuser account unlock;
SQL> alter user gsmcatuser identified by oracle;
SQL> CREATE USER mygdsadmin IDENTIFIED BY oracle;
SQL> GRANT connect, create session, gsmadmin_role to mygdsadmin;
SQL> grant inherit privileges on user SYS to GSMADMIN_INTERNAL;
SQL>
SQL> execute dbms_xdb.sethttpport(8080);
SQL> commit;
SQL> @?/rdbms/admin/prvtrsch.plb
SQL> exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('oracleagent');
SQL> exit

2.3 在各个shard node节点:

schagent -start
echo oracleagent|schagent -registerdatabase sdb1 8080
mkdir -p /u01/ora12c/app/oracle/oradata
mkdir -p /u01/ora12c/app/oracle/fast_recovery_area

2.4 在shardcat节点:

GDSCTL>create shardcatalog -database sdb1:1521:shardcat -chunks 12 -user mygdsadmin/oracle -sdb shardcat -region region1,region2
GDSCTL>
GDSCTL>add gsm -gsm sharddirector1 -listener 1571 -pwd oracle -catalog sdb1:1521:shardcat -region region1
GDSCTL>add gsm -gsm sharddirector2 -listener 1571 -pwd oracle -catalog sdb1:1521:shardcat -region region2
GDSCTL>
GDSCTL>start gsm -gsm sharddirector1
GDSCTL>start gsm -gsm sharddirector2
GDSCTL>
GDSCTL>add credential -credential oracle_cred -osaccount oracle12c -ospassword oracle12c
GDSCTL>
GDSCTL>add shardgroup -shardgroup primary_shardgroup -region region1 -deploy_as primary
GDSCTL>ADD SHARDGROUP -shardgroup standby_shardgroup -region region2 -deploy_as active_standby
GDSCTL>
GDSCTL>add invitednode sdb2
GDSCTL>create shard -shardgroup primary_shardgroup -destination sdb2 -credential oracle_cred
GDSCTL>add invitednode sdb3
GDSCTL>create shard -shardgroup primary_shardgroup -destination sdb3 -credential oracle_cred
GDSCTL>add invitednode sdb4
GDSCTL>create shard -shardgroup standby_shardgroup -destination sdb4 -credential oracle_cred
GDSCTL>add invitednode sdb5
GDSCTL>create shard -shardgroup standby_shardgroup -destination sdb5 -credential oracle_cred




GDSCTL>config

Regions
------------------------
region1
region2

GSMs
------------------------
sharddirector1
sharddirector2

Sharded Database
------------------------
shardcat

Databases
------------------------
sh1
sh2
sh3
sh4

Shard Groups
------------------------
primary_shardgroup
standby_shardgroup

Shard spaces
------------------------
shardspaceora

Services
------------------------

GDSCTL pending requests
------------------------
Command                       Object                        Status
-------                       ------                        ------

Global properties
------------------------
Name: oradbcloud
Master GSM: sharddirector1
DDL sequence #: 0


GDSCTL>
GDSCTL>
GDSCTL>config shard
Name                Shard Group         Status    State       Region    Availability
----                -----------         ------    -----       ------    ------------
sh1                 primary_shardgroup  U         none        region1   -
sh2                 primary_shardgroup  U         none        region1   -
sh3                 standby_shardgroup  U         none        region2   -
sh4                 standby_shardgroup  U         none        region2   -

GDSCTL>
GDSCTL>
GDSCTL>
GDSCTL>deploy

 deploy: examining configuration...
deploy: deploying primary shard 'sh1' ...
deploy: network listener configuration successful at destination 'sdb2'
deploy: starting DBCA at destination 'sdb2' to create primary shard 'sh1' ...
deploy: deploying primary shard 'sh2' ...
deploy: network listener configuration successful at destination 'sdb3'
deploy: starting DBCA at destination 'sdb3' to create primary shard 'sh2' ...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: waiting for 2 DBCA primary creation job(s) to complete...
deploy: DBCA primary creation job succeeded at destination 'sdb2' for shard 'sh1'
deploy: deploying standby shard 'sh3' ...
deploy: network listener configuration successful at destination 'sdb4'
deploy: starting DBCA at destination 'sdb4' to create standby shard 'sh3' ...
deploy: waiting for 1 DBCA primary creation job(s) to complete...
deploy: waiting for 1 DBCA primary creation job(s) to complete...
deploy: DBCA primary creation job succeeded at destination 'sdb3' for shard 'sh2'
deploy: deploying standby shard 'sh4' ...
deploy: network listener configuration successful at destination 'sdb5'
deploy: starting DBCA at destination 'sdb5' to create standby shard 'sh4' ...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: waiting for 2 DBCA standby creation job(s) to complete...
deploy: DBCA standby creation job succeeded at destination 'sdb4' for shard 'sh3'
deploy: waiting for 1 DBCA standby creation job(s) to complete...
deploy: waiting for 1 DBCA standby creation job(s) to complete...
deploy: waiting for 1 DBCA standby creation job(s) to complete...
deploy: DBCA standby creation job succeeded at destination 'sdb5' for shard 'sh4'
deploy: requesting Data Guard configuration on shards via GSM
deploy: shards configured successfully
The operation completed successfully
GDSCTL>GDSCTL>
GDSCTL>
GDSCTL>
GDSCTL>config shard
Name                Shard Group         Status    State       Region    Availability
----                -----------         ------    -----       ------    ------------
sh1                 primary_shardgroup  Ok        Deployed    region1   ONLINE
sh2                 primary_shardgroup  Ok        Deployed    region1   ONLINE
sh3                 standby_shardgroup  Ok        Deployed    region2   READ ONLY
sh4                 standby_shardgroup  Ok        Deployed    region2   READ ONLY

GDSCTL>
GDSCTL>databases
Database: "sh1" Registered: Y State: Ok ONS: N. Role: PRIMARY Instances: 1 Region: region1
Alert: Data Guard observer is not running.
   Registered instances:
     shardcat%1
Database: "sh2" Registered: Y State: Ok ONS: N. Role: PRIMARY Instances: 1 Region: region1
Alert: Data Guard observer is not running.
   Registered instances:
     shardcat%11
Database: "sh3" Registered: Y State: Ok ONS: N. Role: PH_STNDBY Instances: 1 Region: region2
   Registered instances:
     shardcat%21
Database: "sh4" Registered: Y State: Ok ONS: N. Role: PH_STNDBY Instances: 1 Region: region2
   Registered instances:
     shardcat%31

GDSCTL>

我们注意上,上面有个提示:Alert: Data Guard observer is not running. 因为默认安装好之后,observer是没有启动的,(因为没有自动配置好)。

3. 配置observer:

3.1 show configuration显示是observer没有启动

DGMGRL> connect sys/oracle
Connected to "sh1"
Connected as SYSDG.
DGMGRL>
DGMGRL> show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh1 - Primary database
    Warning: ORA-16819: fast-start failover observer not started

    sh3 - (*) Physical standby database
      Warning: ORA-16819: fast-start failover observer not started

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh3
  Observer:           (none)
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
WARNING

DGMGRL>

3.2 尝试手工启动:

DGMGRL>  START OBSERVER
[W000 11/12 11:40:51.83] FSFO target standby is sh3
[P001 11/12 11:40:54.22] Authentication failed.
DGM-16979: Unable to log on to the primary or standby database as SYSDBA
Failed to start the observer.

原因是不能使用sys/oracle登录。需要用sys/oracle@sh1登录。

3.3 由于是gsm创建的sys用户,你不知道sys用户密码是什么,所以需要修改:

SQL> alter user sys identified by oracle;

3.4 observer需要第三方节点做为observer site。我们选择shardcat节点作为obsever,在shardcat主机,配置tnsnames如下:

[oracle12c@sdb1 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/ora12c/app/oracle/product/12.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

LISTENER_SHARDCAT =
  (ADDRESS = (PROTOCOL = TCP)(HOST = sdb1)(PORT = 1521))


SHARDCAT =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = sdb1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = shardcat)
    )
  )

SH1_OBSRV =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = sdb2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sh1)
    )
  )


SH2_OBSRV =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = sdb3)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sh2)
    )
  )


SH3_OBSRV =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = sdb4)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sh3)
    )
  )

SH4_OBSRV =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = sdb5)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sh4)
    )
  )



SH1_OBSRV_DGMGRL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = sdb2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sh1_DGMGRL)
    )
  )


SH2_OBSRV_DGMGRL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = sdb3)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sh2_DGMGRL)
    )
  )


SH3_OBSRV_DGMGRL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = sdb4)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sh3_DGMGRL)
    )
  )

SH4_OBSRV_DGMGRL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = sdb5)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sh4_DGMGRL)
    )
  )
[oracle12c@sdb1 admin]$

3.5 在shardcat主机:

dgmgrl sys/oracle@sh1_obsrv
edit database sh1 set property ObserverConnectIdentifier='sh1_obsrv';
edit database sh3 set property ObserverConnectIdentifier='sh3_obsrv';

dgmgrl sys/oracle@sh2_obsrv
edit database sh2 set property ObserverConnectIdentifier='sh2_obsrv';
edit database sh4 set property ObserverConnectIdentifier='sh4_obsrv';

3.6 启动observer

cd /home/oracle12c/startObsrv_sh1
nohup dgmgrl -silent sys/oracle@sh1_obsrv "start observer" &

cd /home/oracle12c/startObsrv_sh2
nohup dgmgrl -silent sys/oracle@sh2_obsrv "start observer" &

注意2个ovserver需要到2个目录下面启动,不然每次启动,会生成一个fsfo.dat,在同一目录下不能生成同名文件,会冲突。

3.7 检查,恢复正常:

DGMGRL> show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh1 - Primary database
    sh3 - (*) Physical standby database

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh3
  Observer:           sdb1<<<<<<<<<<<<<<<<<注意,observer在shardcat上,即sdb1上。
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
SUCCESS

DGMGRL>

同时,在gdsctl中检查:

GDSCTL>databases
Database: "sh1" Registered: Y State: Ok ONS: N. Role: PRIMARY Instances: 1 Region: region1
   Registered instances:
     shardcat%1
Database: "sh2" Registered: Y State: Ok ONS: N. Role: PRIMARY Instances: 1 Region: region1
   Registered instances:
     shardcat%11
Database: "sh3" Registered: Y State: Ok ONS: N. Role: PH_STNDBY Instances: 1 Region: region2
   Registered instances:
     shardcat%21
Database: "sh4" Registered: Y State: Ok ONS: N. Role: PH_STNDBY Instances: 1 Region: region2
   Registered instances:
     shardcat%31

GDSCTL>
GDSCTL>
GDSCTL>config shard
Name                Shard Group         Status    State       Region    Availability
----                -----------         ------    -----       ------    ------------
sh1                 primary_shardgroup  Ok        Deployed    region1   ONLINE
sh2                 primary_shardgroup  Ok        Deployed    region1   ONLINE
sh3                 standby_shardgroup  Ok        Deployed    region2   READ ONLY
sh4                 standby_shardgroup  Ok        Deployed    region2   READ ONLY

GDSCTL>



注:
GDSCTL>databases
Database: "sh1" Registered: Y State: Ok ONS: N. Role: PRIMARY Instances: 1 Region: region1
   Registered instances: <<<<<<<<<<<<已经配置好的,所以没有告警
     shardcat%1
Database: "sh2" Registered: Y State: Ok ONS: N. Role: PRIMARY Instances: 1 Region: region1
Alert: Data Guard observer is not running. <<<<<<如果没配置好,会有一个alert告警
   Registered instances:
     shardcat%11
Database: "sh3" Registered: Y State: Ok ONS: N. Role: PH_STNDBY Instances: 1 Region: region2
   Registered instances:
     shardcat%21
Database: "sh4" Registered: Y State: Ok ONS: N. Role: PH_STNDBY Instances: 1 Region: region2
   Registered instances:
     shardcat%31

GDSCTL>

4. 添加services:

GDSCTL>  add service -service oltp_rw_srvc -role primary
The operation completed successfully
GDSCTL>start service -service oltp_rw_srvc
The operation completed successfully
GDSCTL>
GDSCTL>add service -service oltp_ro_srvc -role physical_standby
The operation completed successfully
GDSCTL>start service oltp_ro_srvc
GSM-45011: Unexpected argument
oltp_ro_srvc
GDSCTL>start service -service oltp_ro_srvc
The operation completed successfully
GDSCTL>
GDSCTL>
GDSCTL>status service
Service "oltp_ro_srvc.shardcat.oradbcloud" has 2 instance(s). Affinity: ANYWHERE
   Instance "shardcat%21", name: "sh3", db: "sh3", region: "region2", status: ready.
   Instance "shardcat%31", name: "sh4", db: "sh4", region: "region2", status: ready.
Service "oltp_rw_srvc.shardcat.oradbcloud" has 2 instance(s). Affinity: ANYWHERE
   Instance "shardcat%1", name: "sh1", db: "sh1", region: "region1", status: ready.
   Instance "shardcat%11", name: "sh2", db: "sh2", region: "region1", status: ready.

GDSCTL>
GDSCTL>
GDSCTL>services
Service "oltp_ro_srvc.shardcat.oradbcloud" has 2 instance(s). Affinity: ANYWHERE
   Instance "shardcat%21", name: "sh3", db: "sh3", region: "region2", status: ready.
   Instance "shardcat%31", name: "sh4", db: "sh4", region: "region2", status: ready.
Service "oltp_rw_srvc.shardcat.oradbcloud" has 2 instance(s). Affinity: ANYWHERE
   Instance "shardcat%1", name: "sh1", db: "sh1", region: "region1", status: ready.
   Instance "shardcat%11", name: "sh2", db: "sh2", region: "region1", status: ready.

GDSCTL>

5. 创建sharding的应用用户app_schema:

sqlplus "/ as sysdba
alter session enable shard ddl;
create user app_schema identified by app_schema_password;
grant all privileges to app_schema;
grant gsmadmin_role to app_schema;
grant select_catalog_role to app_schema;
grant connect, resource to app_schema;
grant dba to app_schema;
grant execute on dbms_crypto to app_schema;

后面就是照常的创建shard table和duplicate table了。不再累述。

sharding database的一些概念的补充

$
0
0

在继『Oracle sharding database的一些概念』之后,我觉得还有一些关于sharding的概念,是值得理解的。

(1) shardgroup:

In system-managed and composite sharding, the logical unit of replication is a group of shards called a shardgroup.

也就是说,在逻辑上,将一组相同复制属性的shard称作shard group。如有8台主机,其中4台是shard node的primary,另外4台是shard node的standby。那么,我们可以把4台primary定义成一个shardgroup,叫primary_shardgroup,另外4台standby定义成另外一个shardgroup,叫standby_shardgroup。

注,一个shardgroup通常是在一个data center内。

dataguard可以级联,那么我们可以把primary做为一个shardgroup1,第一级的dataguard叫shardgroup2,第二级的dataguard叫shardgroup2.如下:
system-managed-sharding-with-data-guard-replication

(2). shardspace:

A shardspace is set of shards that store data that corresponds to a range or list of key values.

shardspace的概念伴随着综合性分片的分片方法(composite sharding method)出现的;如果是系统管理分片方法(system-managed sharding method),只有一个默认的shardspace。所以只有在composite sharding下,才有可能出现多个shardspace。

在composite sharding下,数据首先根据list或者range,分成若干个shardspace。然后再根据一致性hash进行分片。

注,每个shardspace包含一个或者多个复制shard for HA/DR。

shardspace

我们可以按照服务级别来划分shardspace,如硬件好的,作为shardspace_gold,硬件差一些的,划做shardspace_silver:

或者也可以根据业务需要,按照地域来分不同的shardgroup,如这里的shardgroup cust_america和shardgroup cust_euro
add-shardgroup

(3). super sharding key

Composite sharding enables two levels of sharding - one by list or range and another by consistent hash. This is accomplished by the application providing two keys: a super sharding key and a sharding key.

super sharding key也是随着综合性分片的分片方法出现的。由于综合性分片是2层分片,第一层是根据list或者range进行分片,这个shard key,就叫做super_sharding_key。第二层才是根据一致性hash进行分片(基于sharding key)。

(4). Composite sharding
综合性分片,提供了2层的分片方法,第一层按照range 或者list,第二层根据一致性hash。

综合性分片一般适用于:
(4.1)在不同的地理位置,使用不同的shardspace:
comp_shard_1

(4.2) 在不同的服务器,或者云上面,使用不同的shardspace:
comp_shard_2

(5). region

A region in the context of Oracle Sharding represents a data center or multiple data centers that are in close network proximity.

region,地区的概念。可以指一个数据中心,也可以指一个地域。

(6). shard director

A shard director is a specific implementation of a global service manager that acts as a regional listener for clients that connect to an SDB. The director maintains a current topology map of the SDB. Based on the sharding key passed during a connection request, the director routes the connections to the appropriate shard.

To achieve high availability, deploy multiple shard directors. In Oracle Database 12c Release 2, you can deploy up to 5 shard directors in a given region.

shard director提供:
a).实时维护SDB的配置信息和可用性。
b).衡量自身所处的region和别的region间的网络延时
c).接受来自客户端到SDB的连接,你可以把它当作region listener。
d).管理global services
e).实现连接负载均衡。

注:每个region需要至少一个shard director,可以最多有五个shard director。

shard node的outage测试

$
0
0

shard node的路由方式有直接路由和代理路由,之前我们已经说过,由于我没有connection pool,我们只能来测试一下,在代理路由的情况下,连接shardcat的情况下,当shard node出现意外,连接在shardcat上的操作会发生什么问题。

这里我们要注意下,查询分如下几种情况:
1. 基于shard key的查询。
2. 不基于shard key的查询
3. multi shard的查询
4. 貌似基于shard key的查询。
(不喜欢看测试过程的,可以直接拖到文末看结果。^_^)

加载数据:

insert into products
select rownum,dbms_random.STRING('U',8),dbms_random.STRING('A',64),round(dbms_random.value(1,1000),2) from dual
connect by level<=1000;

begin
   for k in 1 .. 1000 loop
     insert into customers(custid,firstname,lastname,CLASS,geo,passwd)
     values
       (k, 'HE', 'Jimmy', 'A', 'CHINA', to_char(k+999));
   end loop;
   commit;
 end;
 /

begin
   for k in 1 .. 1000 loop
     insert into ORDERS(ORDERID,CUSTID,ORDERDATE,SUMTOTAL,STATUS)
     values
       (k+888, k, sysdate-k,mod(k,99),'SEND');
   end loop;
   commit;
 end;
 /

begin
   for k in 1 .. 1000 loop
     insert into LINEITEMS(ORDERID,CUSTID,PRODUCTID,PRICE,QTY)
     values
       (k+888, k, K+777,mod(k,99)*k/10.24,k+5);
   end loop;
   commit;
 end;
 /

commit;

加载之后我的shard table,customers表的情况是:

=====> sh1:
SQL> select CUSTID,passwd from customers where rownum<=15;

CUSTID                         PASSWD
------------------------------ ------------------------------
1                              1000
2                              1001
8                              1007
29                             1028
30                             1029
40                             1039
46                             1045
50                             1049
75                             1074
78                             1077
79                             1078
117                            1116
143                            1142
148                            1147
156                            1155

15 rows selected.

SQL>



====> sh2:
SQL> select count(*) from customers;

  COUNT(*)
----------
       484

SQL>
SQL>
SQL>
SQL> select CUSTID,passwd from customers where rownum<=15;

CUSTID                         PASSWD
------------------------------ ------------------------------
3                              1002
5                              1004
16                             1015
28                             1027
67                             1066
69                             1068
82                             1081
87                             1086
94                             1093
133                            1132
134                            1133
135                            1134
137                            1136
141                            1140
176                            1175

15 rows selected.

SQL>

所以我的查询语句就是:
1. 基于shard key的查询。
select CUSTID,FIRSTNAME,LASTNAME from customers where custid=’1′;
select CUSTID,FIRSTNAME,LASTNAME from customers where custid=’3′;

2. 不基于shard key的查询
select CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD=’1000′;
select CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD=’1002′;

3. multi shard的查询
select CUSTID,FIRSTNAME,LASTNAME from customers where custid in (‘1′,’3’);

4. 貌似基于shard key的查询。
select CUSTID,FIRSTNAME,LASTNAME from customers where custid=1;
select CUSTID,FIRSTNAME,LASTNAME from customers where custid=3;

我们通过一个循环语句来测试:

while true
do
echo "############################ `date` ############################"
sqlplus -s app_schema/oracle<<EOF
set line 1000
set feedback on
set echo on
select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='1';
select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='3';
select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000';
select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002';
select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3');
select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=1;
select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=3;
exit
EOF
sleep 1
echo ""
echo ""
echo ""
done


场景1:在没有dataguard FSFO保护的情况下,shard node 1 database crash。

############################ Sun Nov 20 00:10:00 CST 2016 ############################

TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE              CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using multi shard 1                                                            HE                                                           Jimmy
Using multi shard 3                                                            HE                                                           Jimmy

2 rows selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 3                                                            HE                                                           Jimmy

1 row selected.

–sh1 shutdown abort

############################ Sun Nov 20 00:10:02 CST 2016 ############################

TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.

select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000'
*
ERROR at line 1:
ORA-03150: end-of-file on communication channel for database link
ORA-03113: end-of-file on communication channel


select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002'
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor


select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3')
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=1
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=3
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor





############################ Sun Nov 20 00:10:03 CST 2016 ############################
select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='1'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1



TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.

select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3')
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=1
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=3
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1

我们看到,在sh1 shutdown abort之后,在shardcat上的查询,出现短暂的一次db link连接失败的报错后,后面就都是:
1. 基于shard key的查询。–访问sh1的操作失败,访问sh2的操作正常
2. 不基于shard key的查询。–无论访问sh1还是sh2,都失败
3. multi shard的查询 –访问失败
4. 貌似基于shard key的查询 –无论访问sh2还是sh2,都失败。

这里我们看出,貌似基于shard key的访问,如上面进行隐式转换的语句,看上去像基于shard key,其实还是不能正常访问到对应的shard node的。

我们再re-startup sh1

############################ Sun Nov 20 00:11:12 CST 2016 ############################

TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE              CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using multi shard 1                                                            HE                                                           Jimmy
Using multi shard 3                                                            HE                                                           Jimmy

2 rows selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 3                                                            HE                                                           Jimmy

1 row selected.

re-startup sh1之后,所有的访问都恢复正常。


场景2:在没有dataguard FSFO保护的情况下,shard node 1 主机 power down。

############################ Sun Nov 20 00:32:25 CST 2016 ############################

TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE              CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using multi shard 1                                                            HE                                                           Jimmy
Using multi shard 3                                                            HE                                                           Jimmy

2 rows selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 3                                                            HE                                                           Jimmy

1 row selected.


-- shutdown sh1 server power

############################ Sun Nov 20 00:32:27 CST 2016 ############################
select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='1'
*
ERROR at line 1:
ORA-12170: TNS:Connect timeout occurred



TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.

select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000'
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002'
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3')
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=1
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=3
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable





############################ Sun Nov 20 00:33:43 CST 2016 ############################
select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='1'
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable



TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.

select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000'
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002'
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3')
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=1
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


 select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=3
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable





############################ Sun Nov 20 00:34:03 CST 2016 ############################
select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='1'
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable



TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.

select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000'
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002'
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3')
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=1
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=3
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1





############################ Sun Nov 20 00:34:19 CST 2016 ############################
select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='1'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1



TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.

select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3')
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=1
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=3
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1





############################ Sun Nov 20 00:34:20 CST 2016 ############################

我们看到,在shard node 1 server power down之后,在shardcat上的查询,出现短暂的大约2分钟的hang,等待之后报错ORA-12543: TNS:destination host unreachable,再后面就和db shutdown abort的情况一下了:
1. 基于shard key的查询。–访问sh1的操作失败,访问sh2的操作正常
2. 不基于shard key的查询。–无论访问sh1还是sh2,都失败
3. multi shard的查询 –访问失败
4. 貌似基于shard key的查询 –无论访问sh2还是sh2,都失败。

–restart server之后,重启listener和db:

############################ Sun Nov 20 00:37:48 CST 2016 ############################

TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE              CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using multi shard 1                                                            HE                                                           Jimmy
Using multi shard 3                                                            HE                                                           Jimmy

2 rows selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 3                                                            HE                                                           Jimmy

1 row selected.


场景3:在dataguard FSFO保护的情况下,shard node 1 database crash。

############################ Mon Nov 21 22:46:53 CST 2016 ############################

TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE              CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using multi shard 1                                                            HE                                                           Jimmy
Using multi shard 3                                                            HE                                                           Jimmy

2 rows selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 3                                                            HE                                                           Jimmy

1 row selected.


--shutdown abort sh1

############################ Mon Nov 21 22:46:55 CST 2016 ############################
select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='1'
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor



TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.

select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000'
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor


select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002'
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor


select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3')
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=1
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=3
*
ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor





############################ Mon Nov 21 22:46:56 CST 2016 ############################
select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='1'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1



TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.

select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3')
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=1
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Look like use shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid=3
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "1" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


--FSFO effect

############################ Mon Nov 21 22:47:46 CST 2016 ############################

TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE              CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using multi shard 3                                                            HE                                                           Jimmy
Using multi shard 1                                                            HE                                                           Jimmy

2 rows selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 3                                                            HE                                                           Jimmy

1 row selected.

我们可以看到,在50秒的时间,就完成了FSFO。在FSFO切换期间内:
1. 基于shard key的查询。–访问sh1的操作失败,访问sh2的操作正常
2. 不基于shard key的查询。–无论访问sh1还是sh2,都失败
3. multi shard的查询 –访问失败
4. 貌似基于shard key的查询 –无论访问sh2还是sh2,都失败。

等FSFO完,所有的操作就都恢复正常。

注意,FSFO完之后,数据库在broker中的状态变成需要reinstated:

DGMGRL>    show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh3 - Primary database
    Error: ORA-16825: multiple errors or warnings, including fast-start failover-related errors or warnings, detected for the database

    sh1 - (*) Physical standby database (disabled)
      ORA-16661: the standby database needs to be reinstated

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh1
  Observer:           sdb1
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
ERROR

DGMGRL>

我们现在来把sh1恢复成初始状态。
(1) 启动sh1数据库,注意,reinstate需要在standby上做,在sh1上做是会报错的。

[oracle12c@sdb2 ~]$ dgmgrl sys/oracle@sh1
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Tue Nov 22 15:26:42 2016

Copyright (c) 1982, 2016, Oracle and/or its affiliates.  All rights reserved.

Welcome to DGMGRL, type "help" for information.
Unable to connect to database using sh1
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

Failed.
DGMGRL> exit
[oracle12c@sdb2 ~]$ dgmgrl sys/oracle
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Tue Nov 22 15:26:56 2016

Copyright (c) 1982, 2016, Oracle and/or its affiliates.  All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected as SYSDG.
DGMGRL> startup
ORACLE instance started.
Database mounted.
ORA-16649: possible failover to another database prevents this database from being opened

DGMGRL>
DGMGRL> reinstate database sh1
ORA-16795: the standby database needs to be re-created

Configuration details cannot be determined by DGMGRL
DGMGRL>
DGMGRL>
DGMGRL> exit
[oracle12c@sdb2 ~]$

(2) 在sh3上做reinstate,注意,做完reinstate之后,虽然不用re-create standby,但是sh3还是primary,sh1还是standby。另外,observer的状态还没有恢复。

[oracle12c@sdb4 ~]$ dgmgrl sys/oracle@sh3
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Tue Nov 22 15:33:23 2016

Copyright (c) 1982, 2016, Oracle and/or its affiliates.  All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected to "sh3"
Connected as SYSDBA.
DGMGRL> show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh3 - Primary database
    Error: ORA-16825: multiple errors or warnings, including fast-start failover-related errors or warnings, detected for the database

    sh1 - (*) Physical standby database (disabled)
      ORA-16661: the standby database needs to be reinstated

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh1
  Observer:           sdb1
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
ERROR

DGMGRL> reinstate database sh1
Reinstating database "sh1", please wait...
Reinstatement of database "sh1" succeeded
DGMGRL>
DGMGRL>
DGMGRL>
DGMGRL>
DGMGRL>
DGMGRL> show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh3 - Primary database
    Error: ORA-16820: fast-start failover observer is no longer observing this database

    sh1 - (*) Physical standby database
      Error: ORA-16820: fast-start failover observer is no longer observing this database

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh1
  Observer:           sdb1
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
ERROR

DGMGRL>

(3) 我们先来恢复一下observer。在observer server上,也就是sh1上重置observer状态和重启observer进程:

[oracle12c@sdb1 startObsrv_sh1]$ dgmgrl  sys/oracle@sh1_obsrv
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Tue Nov 22 15:39:09 2016

Copyright (c) 1982, 2016, Oracle and/or its affiliates.  All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected to "sh1"
Connected as SYSDBA.
DGMGRL> show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh3 - Primary database
    Error: ORA-16820: fast-start failover observer is no longer observing this database

    sh1 - (*) Physical standby database
      Error: ORA-16820: fast-start failover observer is no longer observing this database

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh1
  Observer:           sdb1
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
ERROR

DGMGRL>
DGMGRL>
DGMGRL> STOP OBSERVER ALL
Observer stopped.
DGMGRL>
DGMGRL>
DGMGRL> show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh3 - Primary database
    Warning: ORA-16819: fast-start failover observer not started

    sh1 - (*) Physical standby database
      Warning: ORA-16819: fast-start failover observer not started

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh1
  Observer:           (none)
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
WARNING

DGMGRL> exit
[oracle12c@sdb1 startObsrv_sh1]$
[oracle12c@sdb1 startObsrv_sh1]$ cd /home/oracle12c/startObsrv_sh1
[oracle12c@sdb1 startObsrv_sh1]$ rm *
[oracle12c@sdb1 startObsrv_sh1]$
[oracle12c@sdb1 startObsrv_sh1]$ nohup dgmgrl -silent sys/oracle@sh1_obsrv "start observer" &
[oracle12c@sdb1 startObsrv_sh1]$ dgmgrl  sys/oracle@sh1_obsrv
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Tue Nov 22 15:46:41 2016

Copyright (c) 1982, 2016, Oracle and/or its affiliates.  All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected to "sh1"
Connected as SYSDBA.
DGMGRL> show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh3 - Primary database
    sh1 - (*) Physical standby database

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh1
  Observer:           sdb1
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
SUCCESS

DGMGRL>

(4) 我们把主备切换回来,sh1切回成主。注意切换过程,shard node会不可访问。

[oracle12c@sdb1 ~]$ dgmgrl sys/oracle@sh3_obsrv
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Tue Nov 22 15:58:49 2016

Copyright (c) 1982, 2016, Oracle and/or its affiliates.  All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected to "sh3"
Connected as SYSDBA.
DGMGRL> show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh3 - Primary database
    sh1 - (*) Physical standby database

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh1
  Observer:           sdb1
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
SUCCESS

DGMGRL>
DGMGRL> switchover to sh1
Performing switchover NOW, please wait...
Operation requires a connection to database "sh1"
Connecting ...
Connected to "sh1"
Connected as SYSDBA.
New primary database "sh1" is opening...
Operation requires start up of instance "sh3" on database "sh3"
Starting instance "sh3"...
ORACLE instance started.
Database mounted.
 Database opened.
Connected to "sh3"
Switchover succeeded, new primary is "sh1"
DGMGRL>
DGMGRL> show configuration verbose

Configuration - sh1

  Protection Mode: MaxPerformance
  Members:
  sh1 - Primary database
    sh3 - (*) Physical standby database

  (*) Fast-Start Failover target

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    TraceLevel                      = 'SUPPORT'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'
    ConfigurationWideServiceName    = 'sh1_CFG'

Fast-Start Failover: ENABLED

  Threshold:          30 seconds
  Target:             sh3
  Observer:           sdb1
  Lag Limit:          30 seconds
  Shutdown Primary:   TRUE
  Auto-reinstate:     TRUE
  Observer Reconnect: (none)
  Observer Override:  FALSE

Configuration Status:
SUCCESS

DGMGRL>

场景4:最后,我们来测试一下在FSFO保护的情况下,shard node 1 power down。

############################ Tue Nov 22 16:08:36 CST 2016 ############################

TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE              CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using multi shard 1                                                            HE                                                           Jimmy
Using multi shard 3                                                            HE                                                           Jimmy

2 rows selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 3                                                            HE                                                           Jimmy

1 row selected.




############################ Tue Nov 22 16:08:37 CST 2016 ############################
 select 'Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid='1'
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable



TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.

select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1000'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "5" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'NOT Using shard_key' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where PASSWD='1002'
*
ERROR at line 1:
ORA-02519: cannot perform cross-shard operation. Chunk "5" is unavailable
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18795
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18772
ORA-06512: at "GSMADMIN_INTERNAL.DBMS_GSM_POOLADMIN", line 18811
ORA-06512: at line 1


select 'Using multi shard' as TYPE,CUSTID,FIRSTNAME,LASTNAME from customers where custid in ('1','3')
*
ERROR at line 1:
ORA-12543: TNS:destination host unreachable



TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 3                                                            HE                                                           Jimmy

1 row selected.




############################ Tue Nov 22 16:09:37 CST 2016 ############################

TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE            CUSTID                                                       FIRSTNAME                                                    LASTNAME
--------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                CUSTID                                                       FIRSTNAME                                                    LASTNAME
------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
NOT Using shard_key 3                                                            HE                                                           Jimmy

1 row selected.


TYPE              CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Using multi shard 3                                                            HE                                                           Jimmy
Using multi shard 1                                                            HE                                                           Jimmy

2 rows selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 1                                                            HE                                                           Jimmy

1 row selected.


TYPE                    CUSTID                                                       FIRSTNAME                                                    LASTNAME
----------------------- ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
Look like use shard_key 3                                                            HE                                                           Jimmy

1 row selected.

可以看到,当server的down的时候,被ovserver观察到,立马做主备切换。切换时间大约1分钟。 切换期间,行为和之前的一样:
1. 基于shard key的查询。–访问sh1的操作失败,访问sh2的操作正常
2. 不基于shard key的查询。–无论访问sh1还是sh2,都失败
3. multi shard的查询 –访问失败
4. 貌似基于shard key的查询 –无论访问sh2还是sh2,都失败

主机重启后,后续的操作也是类似的,启动listener,启动数据库,到sh3上做reinstate database sh1,再做switchover,再重启observer。

总结:
1. 在没有ADG+FSFO的高可用保护下,当shard node宕掉的时候,只有基于shard key的访问才能正常,其他的访问都不正常。需要等shard node重新启动后,才能恢复正常访问。
2. 在没有ADG+FSFO的高可用保护下,当shard node主机宕掉的时候,中间会hang两分钟左右的时间(因为TNS:Connect timeout),过了两分钟的停顿时间后,只有基于shard key的访问才能正常,其他的访问都不正常。需要等shard node重新启动后,才能恢复正常访问。
3. 在有ADG+FSFO的高可用保护下,当shard node宕掉的时候,只有基于shard key的访问才能正常,其他的访问都不正常。切换过程大约50秒,50秒之后,所有访问恢复正常访问。
4. 在有ADG+FSFO的高可用保护下,当shard node主机宕掉的时候,只有基于shard key的访问才能正常,其他的访问都不正常。切换过程大约50秒,50秒之后,所有访问恢复正常访问。

可以看到,有FSFO的保护,影响业务时间可以在一分钟以内。

另外,由于reinstate之后,还需要switchover,切换成本比较高,又是一次down库,所以如果有RAC,那么对业务的影响可以降至最低。

再谈sharding database的一些概念

$
0
0

在继『Oracle sharding database的一些概念』『sharding database的一些概念的补充』之后,我觉得还是有些概念需要谈一下。

1.shard prune(分片裁剪):
这个概念类似分区裁剪(partition prune),是指根据sql语句会到对应的分片上去。
但是并不是所有的sql语句都会用到分片裁剪的功能。需要基于shardcat db的statement-level routing,也就是代理路由;因为需要在shardcat上做sql语句的解析。
1.1 当分片方式不是system-managed了,而是user-defined的分片方式,或者是Composite混合型的分片方式的时候,如果此时语句中包含基于shard key的range或者list的条件,如等于,in-list,like,范围等,这时就能触发分片裁剪。
1.2 当分片方式是一致性hash时,如果此时语句中包含基于shard的等于,或者in-list的时候,就可以触发分片裁剪。

2. cross shard join:
12.2只支持基于shard key的cross shard join。

3. cross shard DML
12.2.0.2不支持cross shard dml。

其实这3点的限制,oracle都是为了最大程度上避免跨分片操作。

设置threaded_execution启用12c的多线程模式

$
0
0

Unix/Linux中oracle数据库进程采用多进程模式,如我们可以在系统进程列表中看到pmon,smon,dbwr,lgwr,ckpt等oracle系统进程。随着oracle数据库功能增多,进程数量也随之增加,创建进程的开销以及进程上下文切换的开销也越来越大(进程状态切换 switching 是要直接硬件CPU资源),多线程结构中,线程切换在用户空间通过库函数实现,开销不在一个量级。所以,在oracle 12c中,有一个关于多线程的参数:threaded_execution,默认为false。启用的话,将其设置为true。启用之后,有如下变化:

1.进程数变少:
之前:

[oracle@ol6-121-rac2 diag]$ ps -ef |grep ora_
oracle    7562     1  0 14:54 ?        00:00:00 ora_pmon_cdbrac_1
oracle    7564     1  0 14:54 ?        00:00:00 ora_psp0_cdbrac_1
oracle    7567     1  4 14:54 ?        00:00:20 ora_vktm_cdbrac_1
oracle    7571     1  0 14:54 ?        00:00:00 ora_gen0_cdbrac_1
oracle    7573     1  0 14:54 ?        00:00:00 ora_mman_cdbrac_1
oracle    7577     1  0 14:54 ?        00:00:00 ora_diag_cdbrac_1
oracle    7579     1  0 14:54 ?        00:00:00 ora_dbrm_cdbrac_1
oracle    7581     1  0 14:54 ?        00:00:00 ora_ping_cdbrac_1
oracle    7583     1  0 14:54 ?        00:00:00 ora_acms_cdbrac_1
oracle    7585     1  0 14:54 ?        00:00:01 ora_dia0_cdbrac_1
oracle    7587     1  0 14:54 ?        00:00:00 ora_lmon_cdbrac_1
oracle    7589     1  0 14:54 ?        00:00:04 ora_lmd0_cdbrac_1
oracle    7591     1  0 14:54 ?        00:00:03 ora_lms0_cdbrac_1
oracle    7595     1  0 14:54 ?        00:00:00 ora_rms0_cdbrac_1
oracle    7597     1  0 14:54 ?        00:00:00 ora_lmhb_cdbrac_1
oracle    7599     1  0 14:54 ?        00:00:02 ora_lck1_cdbrac_1
oracle    7601     1  0 14:54 ?        00:00:00 ora_dbw0_cdbrac_1
oracle    7603     1  0 14:54 ?        00:00:00 ora_lgwr_cdbrac_1
oracle    7605     1  0 14:54 ?        00:00:00 ora_ckpt_cdbrac_1
oracle    7607     1  0 14:54 ?        00:00:00 ora_smon_cdbrac_1
oracle    7609     1  0 14:54 ?        00:00:00 ora_reco_cdbrac_1
oracle    7611     1  0 14:54 ?        00:00:00 ora_lreg_cdbrac_1
oracle    7613     1  0 14:54 ?        00:00:00 ora_rbal_cdbrac_1
oracle    7615     1  0 14:54 ?        00:00:00 ora_asmb_cdbrac_1
oracle    7617     1  0 14:54 ?        00:00:01 ora_mmon_cdbrac_1
oracle    7621     1  0 14:54 ?        00:00:00 ora_gcr0_cdbrac_1
oracle    7623     1  0 14:54 ?        00:00:00 ora_mmnl_cdbrac_1
oracle    7625     1  0 14:54 ?        00:00:00 ora_d000_cdbrac_1
oracle    7627     1  0 14:54 ?        00:00:00 ora_s000_cdbrac_1
oracle    7629     1  0 14:54 ?        00:00:00 ora_lck0_cdbrac_1
oracle    7634     1  0 14:54 ?        00:00:00 ora_rsmn_cdbrac_1
oracle    7644     1  0 14:54 ?        00:00:00 ora_ppa7_cdbrac_1
oracle    7668     1  0 14:54 ?        00:00:00 ora_mark_cdbrac_1
oracle    8033     1  0 14:55 ?        00:00:00 ora_o000_cdbrac_1
oracle    8038     1  0 14:56 ?        00:00:00 ora_tmon_cdbrac_1
oracle    8040     1  0 14:56 ?        00:00:00 ora_tt00_cdbrac_1
oracle    8042     1  0 14:56 ?        00:00:00 ora_gcr1_cdbrac_1
oracle    8044     1  0 14:56 ?        00:00:00 ora_smco_cdbrac_1
oracle    8046     1  0 14:56 ?        00:00:00 ora_w000_cdbrac_1
oracle    8049     1  0 14:56 ?        00:00:00 ora_gtx0_cdbrac_1
oracle    8054     1  0 14:56 ?        00:00:00 ora_rcbg_cdbrac_1
oracle    8101     1  0 14:56 ?        00:00:00 ora_aqpc_cdbrac_1
oracle    8126     1  3 14:56 ?        00:00:11 ora_p000_cdbrac_1
oracle    8188     1  0 14:56 ?        00:00:00 ora_o001_cdbrac_1
oracle    8247     1  1 14:56 ?        00:00:04 ora_p001_cdbrac_1
oracle    8249     1  0 14:56 ?        00:00:00 ora_p002_cdbrac_1
oracle    8251     1  0 14:56 ?        00:00:00 ora_p003_cdbrac_1
oracle    8302     1  0 14:56 ?        00:00:00 ora_qm02_cdbrac_1
oracle    8304     1  0 14:56 ?        00:00:00 ora_qm05_cdbrac_1
oracle    8306     1  0 14:56 ?        00:00:00 ora_q002_cdbrac_1
oracle    8310     1  0 14:56 ?        00:00:00 ora_q004_cdbrac_1
oracle    8327     1  0 14:56 ?        00:00:00 ora_ppa6_cdbrac_1
oracle    8663     1  1 14:56 ?        00:00:02 ora_cjq0_cdbrac_1
oracle    8708     1  0 14:56 ?        00:00:00 ora_p004_cdbrac_1
oracle    8710     1  0 14:56 ?        00:00:00 ora_p005_cdbrac_1
oracle    9052     1  0 14:58 ?        00:00:00 ora_q003_cdbrac_1
oracle    9118     1  0 14:59 ?        00:00:00 ora_p006_cdbrac_1
oracle    9120     1  0 14:59 ?        00:00:00 ora_p007_cdbrac_1
oracle    9294  7647  0 15:01 pts/0    00:00:00 grep ora_
[oracle@ol6-121-rac2 diag]$

之后:

[oracle@ol6-121-rac1 admin]$ ps -ef |grep ora_
oracle   10514     1  0 14:59 ?        00:00:00 ora_pmon_cdbrac_1
oracle   10516     1  0 14:59 ?        00:00:00 ora_psp0_cdbrac_1
oracle   10548     1  3 14:59 ?        00:00:13 ora_vktm_cdbrac_1
oracle   10552     1  2 14:59 ?        00:00:07 ora_u004_cdbrac_1
oracle   10558     1  7 14:59 ?        00:00:28 ora_u005_cdbrac_1
oracle   10563     1  0 14:59 ?        00:00:00 ora_ping_cdbrac_1
oracle   10569     1  0 14:59 ?        00:00:02 ora_u010_cdbrac_1
oracle   10578     1  0 14:59 ?        00:00:00 ora_dbw0_cdbrac_1
oracle   11244  9828  0 15:05 pts/0    00:00:00 grep ora_
[oracle@ol6-121-rac1 admin]$

2. 必须网络登录,不能本地验证:

[oracle@ol6-121-rac1 admin]$ sqlplus "sys/oracle@CDBRAC as sysdba"

SQL*Plus: Release 12.1.0.1.0 Production on Wed Dec 9 15:04:33 2015

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options

SQL>
SQL>


3. 可以不同实例不同值:

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
cdbrac_1

SQL> show parameter thread

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
parallel_threads_per_cpu             integer     2
thread                               integer     0
threaded_execution                   boolean     TRUE
SQL>


SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
cdbrac_2

SQL> show parameter thread

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
parallel_threads_per_cpu             integer     2
thread                               integer     0
threaded_execution                   boolean     FALSE
SQL>

4. listener相关修改:
当threaded_execution这个字被设置成true后,在listener.ora文件中,需要加上:

DEDICATED_THROUGH_BROKER_[listener-name]=ON。

参考:
http://docs.oracle.com/database/121/REFRN/GUID-7A668A49-9FC5-4245-AD27-10D90E5AE8A8.htm#REFRN10335
http://docs.oracle.com/database/121/CNCPT/process.htm#CNCPT1245

Known Issues for Database and Query Performance Reported in 12C

$
0
0

LAST UPDATE:

Dec 13, 2016

APPLIES TO:

Oracle Database - Enterprise Edition - Version 12.1.0.1 to 12.1.0.2 [Release 12.1]
Information in this document applies to any platform.

PURPOSE:

In recent quarters, during non-code closure bug review for Performance, it was found that more than 50% of duplicates (36,96) closed by Sustaining Engineering (SE) belonged to version 12.1. As a result this document was created to list most commonly reported and share this with Tier-1 engineers so that they could check this before logging any new bugs. Thus the Goal of this document is to provide a list of known bugs reported in 12C for database & SQL performance for support analysts to check before logging new bugs.

In addition to the bugs listed in this article, there is also a useful list of Documented Database Bugs With High "Solved SR" Count where a high number of Service Requests means that there are more than 50 "Solved SR" entries for the bug - ie: all bugs in this doc have > 50 "Solved SR" entries.” :

Document 2099231.1 Documented Database Bugs With High "Solved SR" Count



DETAILS:
Query Optimizer / SQL Execution

Bug 20271226 - QUERY INVOLVING VIRTUAL COLUMN AND PRIMARY KEY CONSTRAINT CRASHES
Document 19046459.8 - Inconsistent behavior of OJPPD
Document 22077191.8 - Create Table As Select of Insert Select Statement on 12.1 is Much Slower Than on 11.2
Bug 20597568 - PJE INCORRECTLY APPLIED TO A CONNECT BY QUERY
Document 18456944.8 - Suboptimal plan for query fetching ROWID from nested VIEW with fix 10129357
Bug 20355502 - QUERY PARSE NEVER ENDS ( BURNING CPU ALL THE TIME)
Document 20355502.8 Limit number of branches on non-cost based OR expansion
Document 20636003.8 - Slow Parsing caused by Dynamic Sampling (DS_SRV) queries in 12.1.0.2
Bug 22513913 - QUERY FAILS WITH ORA-07445: [KKOSJT()+281] WHEN USING DATABASE LINK
Bug 22020067 - UPGRADE 11.2.0.2 TO 11.2.0.4 SCALAR SUBQUERY UNNEST DISABLED
Bug 21099502 - JPPD Not Happening In UNION ALL View Having Group-by and Aggregates
Bug 22862828 - Regression with 22706363, JPPD Does Not Occur Despite the Fix Control 9380298 is ON
Bug 19295003 - High CPU While Parsing Huge SQL [kkqtutlTravOptAndReplaceOJNNCols]
Document 21091518.8 - Suboptimal plan for SQLs using UNION-ALL with bug fix 18304693 enabled
Document 22113854.8 - Query Against ALL_SYNONYMS Runs Slow in 12C
Document 21871902.8 - SELECT query fails with ORA-7445 [qerixRestoreFetchState2] - superseded by
Document 22255113.8 - High parse time with high memory and CPU usage
Document 22339954.8 - Bug 22339954 - High Parse Time for Query Using UNPIVOT Operator
Document 19490852.8 - Excessive "library cache lock" waits for DML with PARALLEL hint when parallel DML is disabled
Bug 20226806 - QUERY AGAINST ALL_CONSTRAINTS AND ALL_CONS_COLUMNS RUNS SLOWER IN 12.1.0.2
duplicate of Bug 20355502 - QUERY PARSE NEVER ENDS ( BURNING CPU ALL THE TIME)
Document 20118383.8 - Long query parse time in 12.1 when many histograms are involved - superseded by
Document 18795224.8 - Hard parse time increases with fix 12341619 enabled, fixed in 12.2
Document 19475484.8 - Cardinality of 0 for range predicate with fix for bug 6062266 present (default), fixed in 12.2
Document 2182951.1 Higher Elapsed Time after Updating from 11.2.0.4 to 12.1.0.2
Document 18498878.8 - medium size tables do not cached consistently causing unnecessary waits on direct path read, fixed in 12.2
Bug 23516956 - DYNAMIC SAMPLING QUERIES CONTAINS INCORRECT HINTS
duplicate of Document 19631234.8 - Suboptimal execution plan for Dynamic Sampling Queries
Bug 20503656 - Remote SQLs having group by with bind variables throw ORA-00979, fixed in 12.2
Bug 19047578 - Optimizer No Longer Uses Function Based Index When CURSOR_SHARING=FORCE
Document 22734628.8 - Wrong results from UNION ALL using OJPPD with cost based transformation disabled, fixed in 12.2
Bug 21839477 - ORA-7445 [QESDCF_DFB_RESET] WITH FIX FOR BUG:20118383 ON, fixed in 12.2
Document 20774515.8 - Wrong results with partial join evaluation, fixed in 12.2
Bug 21303294 - Wrong Result Due to Lost OR Predicate in Bitmap Plan, fixed in 12.2
Document 22951825.8 - Wrong Results with JPPD, Concatenation and Projection Pushdown, fixed in 12.2
Bug 19847091 - HUGE INLIST SQL HANGS DURING PARSE
superseded by Bug 20384335 - CPU REGRESSION DUE TO PLAN CHANGE IN ONE SELECT SQL WITH IN PREDICATE, fixed in 12.2


SQL Plan Management (SPM)

Document 20877664.8 - SQL Plan Management Slow with High Shared Pool Allocations
Document 21075138.8 - SPM does not reproduce plan with SORT UNIQUE, affected from 11.2.0.4 and fixed in 12.2 only
Document 20978266.8 - SPM: SQL not using plan in plan baselines and plans showing as not reproducible - superseded, fixed in 12.2
Document 19141838.8 - ORA-600 [qksanGetTextStr:1] from SQL Plan Management after Upgrade to 12.1
Document 18961555.8 - Static PL/SQL baseline reproduction broken by fix for bug 18020394, fixed in 12.2
Document 21463894.8 - Failure to reproduce plan with fix for bug 20978266, fixed in 12.2
Document 2039379.1 ORA-04024: Self-deadlock detected while trying to mutex pin cursor" on AUD_OBJECT_OPT$ With SQL Plan Management (SPM) Enabled


Wrong Results

Document 20214168.8 - Wrong Results using aggregations of CASE expression with fix of Bug 20003240 present
Bug 21971099 - 12C WRONG CARDINALITY FROM SQL ANALYTIC WINDOWS FUNCTIONS
Document 16191689.8 - Wrong resilts from projection pruning with XML and NESTED LOOPS
Bug 18302923 - WRONG ESTIMATE CARDINALITY IN HASH GROUP BY OR HASH JOIN
Bug 21220620 - WRONG RESULT ON 12C WHEN QUERYING PARTITIONED TABLE WITH DISTINCT CLAUSE
Document 22173980.8 - Wrong results (number of rows) from HASH join when "_rowsets_enabled" = true in 12c (default)
Bug 20871556 - WRONG RESULTS WITH OPTIMIZER_FEATURES_ENABLE SET TO 12.1.0.1 OR 12.1.0.2
Bug 21387771 - 12C WRONG RESULT WITH OR CONDITION EVEN AFTER PATCHING FOR BUG:20871556
Bug 22660003 - WRONG RESULTS WHEN UNNESTING SET SUBQUERY WITH CORRELATED SUBQUERY IN A BRANCH
Bug 22373397 - WRONG RESULTS DUE TO MISSING PREDICATE DURING BITMAP OR EXPANSION
Bug 22365117 - SQL QUERY COMBINING TABLE FUNCTION WITH JOIN YIELDS WRONG JOIN RESULTS
Bug 20176675 - Wrong results for SQLs using ROWNUM<=N when Scalar Subquery is Unnested (VW_SSQ_1)
Document 19072979.8 - Wrong results with HASH JOIN and parameter "_rowsets_enable"
Document 22338374.8 - ORA-7445 [kkoiqb] or ORA-979 or Wrong Results when using scalar sub-queries
Document 22365117.8 - Wrong Results / ORA-7445 from Query with Table Function
Bug 19318508 - WRONG RESULT IN 12.1 WITH NULL ACCEPTING SEMIJOIN - fixed in 12.2
Bug 21962459 - WRONG RESULTS WITH FIXED CHAR COLUMN AFTER 12C MIGRATION WITH PARTIAL JOIN EVAL
Bug 23019286 - CARDINALITY ESTIMATE WRONG WITH HISTOGRAM ON COLUMN GROUP ON CHAR/NCHAR TYPES, fixed in 12.2
Bug 23253821 - Wrong Results While Running Merge Statement in Parallel, fixed in 12.2
Document 18485835.8 - Wrong results from semi-join elimination if fix 18115594 enabled, fixed in 12.2
Document 18650065.8 - Wrong Results on Query with Subquery Using OR EXISTS or Null Accepting Semijoin, fixed in 12.2
Document 19567916.8 - Wrong results when GROUP BY uses nested queries in 12.1.0.2 - superseded by
Document 20508819.8 - Wrong results/dump/ora-932 from GROUP BY query when "_optimizer_aggr_groupby_elim"=true - superseded by
Document 21826068.8 - Wrong Results when _optimizer_aggr_groupby_elim=true
Document 20634449.8 - Wrong results from OUTER JOIN with a bind variable and a GROUP BY clause in 12.1.0.2
Bug 20162495 - WRONG RESULTS FROM NULL ACCEPTING SEMI-JOIN, fixed in 12.2.


Statistics

Bug 22081245 - COPY_TABLE_STATS DOES NOT WORK PROPERLY FOR TABLES WITH SUB PARTITIONS
Bug 22276972 - DBMS_STATS.COPY_TABLE_STATS INCORRECTLY ADJUST MIN/MAX FOR PARTITION COLUMNS
Document 19450139.8 Slow gather table stats with incremental stats enabled
Bug 21258096 - UNNECESSARY INCREMENTAL STATISTICS GATHERED FOR UNCHANGED PARTITIONS DUE TO HISTOGRAMS
Bug 23100700 - PERFORMANCE ISSUE WITH RECLAIM_SYNOPSIS_SPACE, fixed in 12.2
Document 21171382.8 - Enhancement: AUTO_STAT_EXTENSIONS preference on DBMS_STATS - Enhancement To turn off automatic creation of extended statistics in 12c
Document 21498770.8 - automatic incremental statistics job taking more time with fix 16851194, fixed in 12.2
Document 22984335.8 - Unnecessary Incremental Partition Gathers/Histogram Regathers


Errors

Document 20804063.8 ORA-1499 as REGEXP_REPLACE is allowed to be used in Function-based indexes (FBI)
Document 17609164.8 ORA-600 [kkqctmdcq: Query Block Could] from ANSI JOIN with no a join predicate
Document 21482099.8 ORA-7445 [opitca] or ORA-932 errors from aggregate GROUP BY elimination
Document 21756734.8 - ORA-600 [kkqcsnlopcbkint : 1] from cost based query transformation
Bug 22566555 - ORA-00600 [KKQCSCPOPNWITHMAP: 0] FOR SUBQUERY FACTORING QUERY WITH DISTINCT
Bug 21377051 - ORA-600 [QKAFFSINDEX1] FROM DELETE STATEMENT
Document 21188532.8 - Unexpected ORA-979 with fix for bug 20177858 - superseded by
Bug 23343584 - GATHER_TABLE_STATS FAILS WITH ORA-6502/ORA-6512
duplicate of Bug 22928015 - GATHER DATABASE STATS IS RUNNING VERY SLOWLY ON A RAC ENVIRONMENT
Document 21038926.8 - ORA-7445 [qesdcf_dfb_reset] with fix for bug 20118383 present, fixed in 12.2
Document 18405192.8 - ORA-7445 under qervwFetch() or qervwRestoreViewBufPtrs() when deleting from view with an INSTEAD OF trigger
Document 21968539.8 - ORA-600 [kkqcscpopnwithmap: 0]
Document 18201352.8 - ORA-7445 [qertbStart] or similar errors from query with DISTINCT and partial join evaluation (PJE) transformation
Document 19472320.8 - ORA-600 [kkqtSetOp.1] from join factorization on encrypted column
Bug 22394273 - ORA-600 [QESMMCVALSTAT4] FROM SELECT STATEMENT
Document 21529241.8 - DBMS_STATS ORA-6502: "PL/SQL: numeric or value error"
Document 20505851.8 - ORA-600 / ORA-7445 qksqbApplyToQbcLoc from WITH query that has duplicate predicates
Bug 19952510 - ORA 600 [QERSCALLOCATE: BUFFER SIZE LIMIT] AND ORA 600 [KEUUXS_1]
Bug 21274291 - ORA-600 :[17147] AND [ORA-600 :[KGHALF] DURING AN INSERT
Bug 21524270 - ORA-28115 ON ORACLE 12C WITH VPD IN MERGE STMT, BUT INSERT SUCCEEDS
Bug 20660917 - INSTEAD OF TRIGGER IS FIRED TWICE INSTEAD OF ONCE WITH FIX TO 13812807, Causes ORA-07445 [kxtifir] in 12.1.0.2 - fixed in 12.2.


Adaptive Query Optimization

Bug 18745156 - ADAPTIVE DYNAMIC SAMPLING CAUSES BAD CARDINALITY ESTIMATE
Bug 16033838 - TST&PERF: ADAPTIVE JOINS LEADS TO WORSE PLAN FOR QUERY B4TKVSMPFSP85
Document 20465582.8 High parse time in 12c for multi-table join SQL with SQL plan directives enabled - superseded
Document 20807398.8 ORA-600 [kgl-hash-collision] with fix to Bug 20465582 installed
Document 18430870.8 Adaptive Plan and Left Join Give Wrong Result
Bug 21912039 : GSIAS: PERF REGRESSION: ADAPTIVE PLAN SQL_ID DN50XQR69FJ0F GETS WORSE
  duplicate of Bug 20243268 : EM QUERY WITH SQL_ID 4RQ83FNXTF39U PERFORMS POORLY ON ORACLE 12C RELATIVE TO 11G
Bug 19731829 - ISSUES WITH PACK AND UNPACK OF SQL PLAN DIRECTIVES
Document 20370037.8 - KGLH0 growth leading to ORA-4031 by cardinality feedback, fixed in 12.2
Document 20413540.8 - Excessive executions of SQL frjd8zfy2jfdq


Library cache / Rowcache / Shared Cursors / Dictionary / Buffer cache

Document 19450314.8 Unnecessary invalidations in 12c
Bug 21153142 - ROW CACHE LOCK SELF DEADLOCK ACCESSING SEED PDB
Bug 22081947 - ORA-4023 MAY OCCUR IN ACTIVE DATA GUARD ENVIRONMENTS
Bug 12387079 - THE CHILD CURSOR IS INCREASED WHEN THE CURSOR IS KEPT AND EXECUTED DDL
  superseded by Bug 19239846 - FIX FOR Bug 12387079 NEEDS TO BE RE-WORKED
Bug 12320556 - HIGH VERSION COUNTS OCCUR DUE TO AUTH_CHECK_MISMATCH, INSUFF_PRIVS_REM=Y
  superseded by Bug 21515534 - QUERY USING 2 REMOTE DB NOT SHARED - AUTH_CHECK_MISMATCH ,INSUFF_PRIVS_REM
Document 21515534.8 Query referencing multiple remote databases not shared with reason AUTH_CHECK_MISMATCH INSUFF_PRIVS_REM
Document 20907061.8 High number of executions for recursive call on col$
Document 20476175.8 High VERSION_COUNT (in V$SQLAREA) for query with OPT_PARAM('_fix_control') hint
Bug 21799609 - ORA-04024 DEADLOCK ON STARTUP ON SYS.ECOL$ ON LOAD HISTOGRAMS
  duplicate of Bug 19469538 - LOADING OF DATA IN ECOL$ TABLE IS NON-OPTIMAL FOR QUERIES
Bug 22586498 - HUGE M000 TRACEFILE DUE TO OBSOLETE CURSOR DUMPS
Document 20906941.8 - DBW0 spins with high CPU
Bug 17700290 - TST&PERF: LIBRARY CACHE MUTEX WAIT TIME INCREASED HUGELY IN MAIN - affected 12.1.0.2, fixed in 12.2 only
Bug 22733141 - GATHERING STATS ON X$KQLFBC HANGS
Bug 23098370 - DBWR CAN ISSUE MORE THAN SSTMXIOB IO'S
Bug 23103188 - Incorrect ORA-1031 or ORA-942 during Grant due to 22677790, fixed in 12.2
Bug 19340498 - CDB:NO ROWS RETURNED WHEN QUERYING V$SQL_SHARED_MEMORY INSIDE A PDB
Bug 23514710 - CROSS-CONTAINER FIXED TABLE NOT OBSOLETED WHEN PARENT IS MARKED OBSOLETE in ADG Env
Document 19392364.8 - Process spin in kkscsFindMatchingRange() with adaptive cursor sharing, fixed in 12.2
Document 2096561.1 - High Amount Of Shared Memory Allocated Into KGLH0 Heap In 12.1.0.2
Document 2119923.1 - Shared Pool from KGLH0 constantly growing causing ORA-04031 and Latch contention
Document 23168642.8 - Sporadic ORA-600 [kglunpin-bad-pin] / ORA-14403 / high 'library cache: mutex x' using partitions and deferred seg creation / ORA-600 [qesmascTrimLRU_1] with fix 21759047, fixed in 12.2
Document 21759047.8 - High 'library cache: mutex x' Contention when Many Sessions are Executing Cursors Concurrently Against a Partitioned Table - superseded, fixed in 12.2
Document 14380605.8 - High "library cache lock", "cursor: pin S wait on X" and "library cache: mutex X" waits, fixed in 12.2
Document 19822816.8 - High parse time for SQL with PIVOT and binds (can block LGWR on "library cache lock"), fixed in 12.2
Document 13542050.8 - 'library cache: mutex X' waits : A mutex related hang with holder around 65534 (0xfffe), fixed in 12.2
Document 21834574.8 - Mutex contention and increased hard parse time due to ILM (segment-access tracking) checking with partitioned objects, fixed in 12.2
Document 19790972.8 - "library cache lock" waits due to DBMS_STATS gather of stats for a subpartition, fixed in 12.2


Server Manageability (SVRMAN)

Bug 21521882 - SQLT CAUSES ORA-00600: [KGHSTACK_UNDERFLOW_INTERNAL_1]
  duplicate of Bug 19593445 - SR12.2CDBCONC3 - TRC - KPDBSWITCH
Document 18148383.8 AWR snapshots stopped , MMON hung with "EMON to process ntnfs" - affected 12.1.0.1, fixed in 12.1.0.2
Bug 20976392 - AWR REPORT: NEGATIVE OR WRONG VALUES IN %TOTAL OF UNOPTIMIZED READS
Document 2016112.1 - Replaying a PRE-12C Capture On 12.1.0.2.0 Encounters Unexpected ORA-1000 Errors
Bug 21117072 - DBREPLAY PATCH BUNDLE 1 FOR 12.1.0.2 , RAT Patch Bundle 1 for 12.1.0.2 is mandatory LGWR
Bug 23501117 - WORKLOAD REPLAY SKIPS USERCALLS FOR WORKLOAD CAPTURED UNDER 11.2.0.4
Document 22345045.8 - ORA-600 [kewrspbr_2: wrong last partition] in AWR internal tables after upgrading to 12.1.0.2
Multiple LGWR

Document 1968563.1 Hang Waiting on 'LGWR worker group ordering' with Deadlock Between LGWR (Log Writer) Slaves (LG0n) when Using Multiple LGWR Processes
Document 1957710.1 ALERT: Bug 21915719 Database hang or may fail to OPEN in 12c IBM AIX or HPUX Itanium - ORA-742, DEADLOCK or ORA-600 [kcrfrgv_nextlwn_scn] ORA-600


Exadata/In-memory/Multitenant

Document 21553476.8 Wrong Results using aggregations of CASE expression with fix of Bug 20003240 present in Exadata
Bug 19130972 - EXTREMELY LONG PARSE TIME FOR STAR QUERY (For In-memory DB, fixed in 12.1.0.2 DBBP 3)
Bug 17439841 - IMC DYNAMIC SAMPLING CAUSE "CURSOR: PIN S WAIT ON X" ON PARALLEL QUERY - affected 12.1.0.2, fixed in 12.1.0.2
Bug 21445204 - PARSING OF A QUERY TAKES LONG TIME WITH IMC
Document 21153142.8 - Row cache lock self deadlock accessing seed PDB, fixed in 12.2.
Bug 20766944 - QUERIES INVOLVING INT$DBA_CONSTRAINTS TAKE A LOT OF TIME, fixed in 12.2.
Document 17805926.8 - Parameter changes at PDB level affect other PDBs, fixed in 12.2


Popular Documents for Known issues/Bugs

Document 2034610.1 Things to Consider Before Upgrading to 12.1.0.2 to Avoid Poor Performance or Wrong Results
Document 2035898.1 Patches to Consider for 12.1.0.2 to Avoid Problems with SQL Plan Management (SPM)
Document 2107602.1 Things to Consider When Using Incremental Statistics
Document 1683802.1 12.1.0.2 Patch Set - List of Bug Fixes by Problem Type
Document 1924126.1 12.1.0.2 Patch Set Updates - List of Fixes in each PSU


Port-Specific

Document 1970525.1 Things to Consider to Avoid RDBMS Performance Problems on SPARC Platforms Using Oracle 12.1.0.2


Reference documents covering 12c new features

The following list of documents cover many of the features that have been introduced or enhanced in 12c and as provided to aid re-discovery:

Document 2031605.1 Adaptive Query Optimization
Document 2002108.1 Dynamic Sampling Level Is Changed Automatically in 12C
Document 2033658.1 Dictionary Queries Running Slow in 12C PDBs
Document 2002089.1 High Latch Free Waits on 'Result Cache: RC Latch' In 12C when RESULT_CACHE_MODE = MANUAL
Document 2004828.1 ORA-20002: Unable To Export Table Stats Using DBMS_STATS Package In 12c Database
Document 2051004.1 ORA-12012 ORA-20000 During Automatic Statistics Collection Job in 12C With Concurrent Option Enabled
Document 1955319.1 Huge Trace Files Created Containing "----- Cursor Obsoletion Dump sql_id=%s -----" From 12.1.0.2
Document 2053877.1 Wrong Results (0 Rows) Returned for Query that Includes Subquery Containing AND ROWNUM when OPTIMIZER_ADAPTIVE_FEATURES = TRUE
Document 2041541.1 Gather_Database_Stats_Job_Proc Taking More Time in 12.1.0.2 Than 11.2.0.4


Documentation

Database SQL Tuning Guide 12.1: http://docs.oracle.com/database/121/TGSQL/toc.htm
Database Performance Tuning Guide: http://docs.oracle.com/database/121/TGDBA/toc.htm
Database Testing Guide (RAT): http://docs.oracle.com/database/121/RATUG/toc.htm



参考:
Commonly Reported Known Issues for Database and Query Performance Reported in 12C (Doc ID 2097793.1 INTERNAL)
Documented Database Bugs With High “Solved SR” Count (Doc ID 2099231.1 INTERNAL)


12c的GI下cvu目录满

$
0
0

12c的GI中,/oracle_grid/app/oracle/crsdata/@global/cvu/baseline/cvures这个目录下的文件占用空间巨大。某生产环境中,目录已经到了32G以上。

这可能和如下3个bug有关:

Unpublished Bug 18143707 CVU NEED TO DO CVU BASELINE REPORT CLEAN TO AVOID DISK FULL  will limit .txt files to 5
Unpublished Bug 19703199 CVU NEED TO DO CVU BASELINE REPORT CLEAN TO AVOID DISK FULL  will limit .xml files to 5
Unpublished Bug 20177779 BIGBH U01 SPACE CONSUMPTION BY CVUCHECKREPORT.XML will purge the files on remote nodes

解决方案:

Bug 18143707 is fixed in 12.1.0.2
Bug 19703199 is fixed in 12.1.0.2.4 PSU
Bug 20177779 is fixed in 12.1.0.2.5 PSU
The workaround is to remove these reports manually.

参考:
Doc ID 1964482.1
Doc ID 2054765.1

Known Issues for Database and Query Performance Reported in 12C

$
0
0

LAST UPDATE:

Dec 13, 2016

APPLIES TO:

Oracle Database - Enterprise Edition - Version 12.1.0.1 to 12.1.0.2 [Release 12.1]
Information in this document applies to any platform.

PURPOSE:

In recent quarters, during non-code closure bug review for Performance, it was found that more than 50% of duplicates (36,96) closed by Sustaining Engineering (SE) belonged to version 12.1. As a result this document was created to list most commonly reported and share this with Tier-1 engineers so that they could check this before logging any new bugs. Thus the Goal of this document is to provide a list of known bugs reported in 12C for database & SQL performance for support analysts to check before logging new bugs.

In addition to the bugs listed in this article, there is also a useful list of Documented Database Bugs With High "Solved SR" Count where a high number of Service Requests means that there are more than 50 "Solved SR" entries for the bug - ie: all bugs in this doc have > 50 "Solved SR" entries.” :

Document 2099231.1 Documented Database Bugs With High "Solved SR" Count



DETAILS:
Query Optimizer / SQL Execution

Bug 20271226 - QUERY INVOLVING VIRTUAL COLUMN AND PRIMARY KEY CONSTRAINT CRASHES
Document 19046459.8 - Inconsistent behavior of OJPPD
Document 22077191.8 - Create Table As Select of Insert Select Statement on 12.1 is Much Slower Than on 11.2
Bug 20597568 - PJE INCORRECTLY APPLIED TO A CONNECT BY QUERY
Document 18456944.8 - Suboptimal plan for query fetching ROWID from nested VIEW with fix 10129357
Bug 20355502 - QUERY PARSE NEVER ENDS ( BURNING CPU ALL THE TIME)
Document 20355502.8 Limit number of branches on non-cost based OR expansion
Document 20636003.8 - Slow Parsing caused by Dynamic Sampling (DS_SRV) queries in 12.1.0.2
Bug 22513913 - QUERY FAILS WITH ORA-07445: [KKOSJT()+281] WHEN USING DATABASE LINK
Bug 22020067 - UPGRADE 11.2.0.2 TO 11.2.0.4 SCALAR SUBQUERY UNNEST DISABLED
Bug 21099502 - JPPD Not Happening In UNION ALL View Having Group-by and Aggregates
Bug 22862828 - Regression with 22706363, JPPD Does Not Occur Despite the Fix Control 9380298 is ON
Bug 19295003 - High CPU While Parsing Huge SQL [kkqtutlTravOptAndReplaceOJNNCols]
Document 21091518.8 - Suboptimal plan for SQLs using UNION-ALL with bug fix 18304693 enabled
Document 22113854.8 - Query Against ALL_SYNONYMS Runs Slow in 12C
Document 21871902.8 - SELECT query fails with ORA-7445 [qerixRestoreFetchState2] - superseded by
Document 22255113.8 - High parse time with high memory and CPU usage
Document 22339954.8 - Bug 22339954 - High Parse Time for Query Using UNPIVOT Operator
Document 19490852.8 - Excessive "library cache lock" waits for DML with PARALLEL hint when parallel DML is disabled
Bug 20226806 - QUERY AGAINST ALL_CONSTRAINTS AND ALL_CONS_COLUMNS RUNS SLOWER IN 12.1.0.2
duplicate of Bug 20355502 - QUERY PARSE NEVER ENDS ( BURNING CPU ALL THE TIME)
Document 20118383.8 - Long query parse time in 12.1 when many histograms are involved - superseded by
Document 18795224.8 - Hard parse time increases with fix 12341619 enabled, fixed in 12.2
Document 19475484.8 - Cardinality of 0 for range predicate with fix for bug 6062266 present (default), fixed in 12.2
Document 2182951.1 Higher Elapsed Time after Updating from 11.2.0.4 to 12.1.0.2
Document 18498878.8 - medium size tables do not cached consistently causing unnecessary waits on direct path read, fixed in 12.2
Bug 23516956 - DYNAMIC SAMPLING QUERIES CONTAINS INCORRECT HINTS
duplicate of Document 19631234.8 - Suboptimal execution plan for Dynamic Sampling Queries
Bug 20503656 - Remote SQLs having group by with bind variables throw ORA-00979, fixed in 12.2
Bug 19047578 - Optimizer No Longer Uses Function Based Index When CURSOR_SHARING=FORCE
Document 22734628.8 - Wrong results from UNION ALL using OJPPD with cost based transformation disabled, fixed in 12.2
Bug 21839477 - ORA-7445 [QESDCF_DFB_RESET] WITH FIX FOR BUG:20118383 ON, fixed in 12.2
Document 20774515.8 - Wrong results with partial join evaluation, fixed in 12.2
Bug 21303294 - Wrong Result Due to Lost OR Predicate in Bitmap Plan, fixed in 12.2
Document 22951825.8 - Wrong Results with JPPD, Concatenation and Projection Pushdown, fixed in 12.2
Bug 19847091 - HUGE INLIST SQL HANGS DURING PARSE
superseded by Bug 20384335 - CPU REGRESSION DUE TO PLAN CHANGE IN ONE SELECT SQL WITH IN PREDICATE, fixed in 12.2


SQL Plan Management (SPM)

Document 20877664.8 - SQL Plan Management Slow with High Shared Pool Allocations
Document 21075138.8 - SPM does not reproduce plan with SORT UNIQUE, affected from 11.2.0.4 and fixed in 12.2 only
Document 20978266.8 - SPM: SQL not using plan in plan baselines and plans showing as not reproducible - superseded, fixed in 12.2
Document 19141838.8 - ORA-600 [qksanGetTextStr:1] from SQL Plan Management after Upgrade to 12.1
Document 18961555.8 - Static PL/SQL baseline reproduction broken by fix for bug 18020394, fixed in 12.2
Document 21463894.8 - Failure to reproduce plan with fix for bug 20978266, fixed in 12.2
Document 2039379.1 ORA-04024: Self-deadlock detected while trying to mutex pin cursor" on AUD_OBJECT_OPT$ With SQL Plan Management (SPM) Enabled


Wrong Results

Document 20214168.8 - Wrong Results using aggregations of CASE expression with fix of Bug 20003240 present
Bug 21971099 - 12C WRONG CARDINALITY FROM SQL ANALYTIC WINDOWS FUNCTIONS
Document 16191689.8 - Wrong resilts from projection pruning with XML and NESTED LOOPS
Bug 18302923 - WRONG ESTIMATE CARDINALITY IN HASH GROUP BY OR HASH JOIN
Bug 21220620 - WRONG RESULT ON 12C WHEN QUERYING PARTITIONED TABLE WITH DISTINCT CLAUSE
Document 22173980.8 - Wrong results (number of rows) from HASH join when "_rowsets_enabled" = true in 12c (default)
Bug 20871556 - WRONG RESULTS WITH OPTIMIZER_FEATURES_ENABLE SET TO 12.1.0.1 OR 12.1.0.2
Bug 21387771 - 12C WRONG RESULT WITH OR CONDITION EVEN AFTER PATCHING FOR BUG:20871556
Bug 22660003 - WRONG RESULTS WHEN UNNESTING SET SUBQUERY WITH CORRELATED SUBQUERY IN A BRANCH
Bug 22373397 - WRONG RESULTS DUE TO MISSING PREDICATE DURING BITMAP OR EXPANSION
Bug 22365117 - SQL QUERY COMBINING TABLE FUNCTION WITH JOIN YIELDS WRONG JOIN RESULTS
Bug 20176675 - Wrong results for SQLs using ROWNUM<=N when Scalar Subquery is Unnested (VW_SSQ_1)
Document 19072979.8 - Wrong results with HASH JOIN and parameter "_rowsets_enable"
Document 22338374.8 - ORA-7445 [kkoiqb] or ORA-979 or Wrong Results when using scalar sub-queries
Document 22365117.8 - Wrong Results / ORA-7445 from Query with Table Function
Bug 19318508 - WRONG RESULT IN 12.1 WITH NULL ACCEPTING SEMIJOIN - fixed in 12.2
Bug 21962459 - WRONG RESULTS WITH FIXED CHAR COLUMN AFTER 12C MIGRATION WITH PARTIAL JOIN EVAL
Bug 23019286 - CARDINALITY ESTIMATE WRONG WITH HISTOGRAM ON COLUMN GROUP ON CHAR/NCHAR TYPES, fixed in 12.2
Bug 23253821 - Wrong Results While Running Merge Statement in Parallel, fixed in 12.2
Document 18485835.8 - Wrong results from semi-join elimination if fix 18115594 enabled, fixed in 12.2
Document 18650065.8 - Wrong Results on Query with Subquery Using OR EXISTS or Null Accepting Semijoin, fixed in 12.2
Document 19567916.8 - Wrong results when GROUP BY uses nested queries in 12.1.0.2 - superseded by
Document 20508819.8 - Wrong results/dump/ora-932 from GROUP BY query when "_optimizer_aggr_groupby_elim"=true - superseded by
Document 21826068.8 - Wrong Results when _optimizer_aggr_groupby_elim=true
Document 20634449.8 - Wrong results from OUTER JOIN with a bind variable and a GROUP BY clause in 12.1.0.2
Bug 20162495 - WRONG RESULTS FROM NULL ACCEPTING SEMI-JOIN, fixed in 12.2.


Statistics

Bug 22081245 - COPY_TABLE_STATS DOES NOT WORK PROPERLY FOR TABLES WITH SUB PARTITIONS
Bug 22276972 - DBMS_STATS.COPY_TABLE_STATS INCORRECTLY ADJUST MIN/MAX FOR PARTITION COLUMNS
Document 19450139.8 Slow gather table stats with incremental stats enabled
Bug 21258096 - UNNECESSARY INCREMENTAL STATISTICS GATHERED FOR UNCHANGED PARTITIONS DUE TO HISTOGRAMS
Bug 23100700 - PERFORMANCE ISSUE WITH RECLAIM_SYNOPSIS_SPACE, fixed in 12.2
Document 21171382.8 - Enhancement: AUTO_STAT_EXTENSIONS preference on DBMS_STATS - Enhancement To turn off automatic creation of extended statistics in 12c
Document 21498770.8 - automatic incremental statistics job taking more time with fix 16851194, fixed in 12.2
Document 22984335.8 - Unnecessary Incremental Partition Gathers/Histogram Regathers


Errors

Document 20804063.8 ORA-1499 as REGEXP_REPLACE is allowed to be used in Function-based indexes (FBI)
Document 17609164.8 ORA-600 [kkqctmdcq: Query Block Could] from ANSI JOIN with no a join predicate
Document 21482099.8 ORA-7445 [opitca] or ORA-932 errors from aggregate GROUP BY elimination
Document 21756734.8 - ORA-600 [kkqcsnlopcbkint : 1] from cost based query transformation
Bug 22566555 - ORA-00600 [KKQCSCPOPNWITHMAP: 0] FOR SUBQUERY FACTORING QUERY WITH DISTINCT
Bug 21377051 - ORA-600 [QKAFFSINDEX1] FROM DELETE STATEMENT
Document 21188532.8 - Unexpected ORA-979 with fix for bug 20177858 - superseded by
Bug 23343584 - GATHER_TABLE_STATS FAILS WITH ORA-6502/ORA-6512
duplicate of Bug 22928015 - GATHER DATABASE STATS IS RUNNING VERY SLOWLY ON A RAC ENVIRONMENT
Document 21038926.8 - ORA-7445 [qesdcf_dfb_reset] with fix for bug 20118383 present, fixed in 12.2
Document 18405192.8 - ORA-7445 under qervwFetch() or qervwRestoreViewBufPtrs() when deleting from view with an INSTEAD OF trigger
Document 21968539.8 - ORA-600 [kkqcscpopnwithmap: 0]
Document 18201352.8 - ORA-7445 [qertbStart] or similar errors from query with DISTINCT and partial join evaluation (PJE) transformation
Document 19472320.8 - ORA-600 [kkqtSetOp.1] from join factorization on encrypted column
Bug 22394273 - ORA-600 [QESMMCVALSTAT4] FROM SELECT STATEMENT
Document 21529241.8 - DBMS_STATS ORA-6502: "PL/SQL: numeric or value error"
Document 20505851.8 - ORA-600 / ORA-7445 qksqbApplyToQbcLoc from WITH query that has duplicate predicates
Bug 19952510 - ORA 600 [QERSCALLOCATE: BUFFER SIZE LIMIT] AND ORA 600 [KEUUXS_1]
Bug 21274291 - ORA-600 :[17147] AND [ORA-600 :[KGHALF] DURING AN INSERT
Bug 21524270 - ORA-28115 ON ORACLE 12C WITH VPD IN MERGE STMT, BUT INSERT SUCCEEDS
Bug 20660917 - INSTEAD OF TRIGGER IS FIRED TWICE INSTEAD OF ONCE WITH FIX TO 13812807, Causes ORA-07445 [kxtifir] in 12.1.0.2 - fixed in 12.2.


Adaptive Query Optimization

Bug 18745156 - ADAPTIVE DYNAMIC SAMPLING CAUSES BAD CARDINALITY ESTIMATE
Bug 16033838 - TST&PERF: ADAPTIVE JOINS LEADS TO WORSE PLAN FOR QUERY B4TKVSMPFSP85
Document 20465582.8 High parse time in 12c for multi-table join SQL with SQL plan directives enabled - superseded
Document 20807398.8 ORA-600 [kgl-hash-collision] with fix to Bug 20465582 installed
Document 18430870.8 Adaptive Plan and Left Join Give Wrong Result
Bug 21912039 : GSIAS: PERF REGRESSION: ADAPTIVE PLAN SQL_ID DN50XQR69FJ0F GETS WORSE
  duplicate of Bug 20243268 : EM QUERY WITH SQL_ID 4RQ83FNXTF39U PERFORMS POORLY ON ORACLE 12C RELATIVE TO 11G
Bug 19731829 - ISSUES WITH PACK AND UNPACK OF SQL PLAN DIRECTIVES
Document 20370037.8 - KGLH0 growth leading to ORA-4031 by cardinality feedback, fixed in 12.2
Document 20413540.8 - Excessive executions of SQL frjd8zfy2jfdq


Library cache / Rowcache / Shared Cursors / Dictionary / Buffer cache

Document 19450314.8 Unnecessary invalidations in 12c
Bug 21153142 - ROW CACHE LOCK SELF DEADLOCK ACCESSING SEED PDB
Bug 22081947 - ORA-4023 MAY OCCUR IN ACTIVE DATA GUARD ENVIRONMENTS
Bug 12387079 - THE CHILD CURSOR IS INCREASED WHEN THE CURSOR IS KEPT AND EXECUTED DDL
  superseded by Bug 19239846 - FIX FOR Bug 12387079 NEEDS TO BE RE-WORKED
Bug 12320556 - HIGH VERSION COUNTS OCCUR DUE TO AUTH_CHECK_MISMATCH, INSUFF_PRIVS_REM=Y
  superseded by Bug 21515534 - QUERY USING 2 REMOTE DB NOT SHARED - AUTH_CHECK_MISMATCH ,INSUFF_PRIVS_REM
Document 21515534.8 Query referencing multiple remote databases not shared with reason AUTH_CHECK_MISMATCH INSUFF_PRIVS_REM
Document 20907061.8 High number of executions for recursive call on col$
Document 20476175.8 High VERSION_COUNT (in V$SQLAREA) for query with OPT_PARAM('_fix_control') hint
Bug 21799609 - ORA-04024 DEADLOCK ON STARTUP ON SYS.ECOL$ ON LOAD HISTOGRAMS
  duplicate of Bug 19469538 - LOADING OF DATA IN ECOL$ TABLE IS NON-OPTIMAL FOR QUERIES
Bug 22586498 - HUGE M000 TRACEFILE DUE TO OBSOLETE CURSOR DUMPS
Document 20906941.8 - DBW0 spins with high CPU
Bug 17700290 - TST&PERF: LIBRARY CACHE MUTEX WAIT TIME INCREASED HUGELY IN MAIN - affected 12.1.0.2, fixed in 12.2 only
Bug 22733141 - GATHERING STATS ON X$KQLFBC HANGS
Bug 23098370 - DBWR CAN ISSUE MORE THAN SSTMXIOB IO'S
Bug 23103188 - Incorrect ORA-1031 or ORA-942 during Grant due to 22677790, fixed in 12.2
Bug 19340498 - CDB:NO ROWS RETURNED WHEN QUERYING V$SQL_SHARED_MEMORY INSIDE A PDB
Bug 23514710 - CROSS-CONTAINER FIXED TABLE NOT OBSOLETED WHEN PARENT IS MARKED OBSOLETE in ADG Env
Document 19392364.8 - Process spin in kkscsFindMatchingRange() with adaptive cursor sharing, fixed in 12.2
Document 2096561.1 - High Amount Of Shared Memory Allocated Into KGLH0 Heap In 12.1.0.2
Document 2119923.1 - Shared Pool from KGLH0 constantly growing causing ORA-04031 and Latch contention
Document 23168642.8 - Sporadic ORA-600 [kglunpin-bad-pin] / ORA-14403 / high 'library cache: mutex x' using partitions and deferred seg creation / ORA-600 [qesmascTrimLRU_1] with fix 21759047, fixed in 12.2
Document 21759047.8 - High 'library cache: mutex x' Contention when Many Sessions are Executing Cursors Concurrently Against a Partitioned Table - superseded, fixed in 12.2
Document 14380605.8 - High "library cache lock", "cursor: pin S wait on X" and "library cache: mutex X" waits, fixed in 12.2
Document 19822816.8 - High parse time for SQL with PIVOT and binds (can block LGWR on "library cache lock"), fixed in 12.2
Document 13542050.8 - 'library cache: mutex X' waits : A mutex related hang with holder around 65534 (0xfffe), fixed in 12.2
Document 21834574.8 - Mutex contention and increased hard parse time due to ILM (segment-access tracking) checking with partitioned objects, fixed in 12.2
Document 19790972.8 - "library cache lock" waits due to DBMS_STATS gather of stats for a subpartition, fixed in 12.2


Server Manageability (SVRMAN)

Bug 21521882 - SQLT CAUSES ORA-00600: [KGHSTACK_UNDERFLOW_INTERNAL_1]
  duplicate of Bug 19593445 - SR12.2CDBCONC3 - TRC - KPDBSWITCH
Document 18148383.8 AWR snapshots stopped , MMON hung with "EMON to process ntnfs" - affected 12.1.0.1, fixed in 12.1.0.2
Bug 20976392 - AWR REPORT: NEGATIVE OR WRONG VALUES IN %TOTAL OF UNOPTIMIZED READS
Document 2016112.1 - Replaying a PRE-12C Capture On 12.1.0.2.0 Encounters Unexpected ORA-1000 Errors
Bug 21117072 - DBREPLAY PATCH BUNDLE 1 FOR 12.1.0.2 , RAT Patch Bundle 1 for 12.1.0.2 is mandatory LGWR
Bug 23501117 - WORKLOAD REPLAY SKIPS USERCALLS FOR WORKLOAD CAPTURED UNDER 11.2.0.4
Document 22345045.8 - ORA-600 [kewrspbr_2: wrong last partition] in AWR internal tables after upgrading to 12.1.0.2
Multiple LGWR

Document 1968563.1 Hang Waiting on 'LGWR worker group ordering' with Deadlock Between LGWR (Log Writer) Slaves (LG0n) when Using Multiple LGWR Processes
Document 1957710.1 ALERT: Bug 21915719 Database hang or may fail to OPEN in 12c IBM AIX or HPUX Itanium - ORA-742, DEADLOCK or ORA-600 [kcrfrgv_nextlwn_scn] ORA-600


Exadata/In-memory/Multitenant

Document 21553476.8 Wrong Results using aggregations of CASE expression with fix of Bug 20003240 present in Exadata
Bug 19130972 - EXTREMELY LONG PARSE TIME FOR STAR QUERY (For In-memory DB, fixed in 12.1.0.2 DBBP 3)
Bug 17439841 - IMC DYNAMIC SAMPLING CAUSE "CURSOR: PIN S WAIT ON X" ON PARALLEL QUERY - affected 12.1.0.2, fixed in 12.1.0.2
Bug 21445204 - PARSING OF A QUERY TAKES LONG TIME WITH IMC
Document 21153142.8 - Row cache lock self deadlock accessing seed PDB, fixed in 12.2.
Bug 20766944 - QUERIES INVOLVING INT$DBA_CONSTRAINTS TAKE A LOT OF TIME, fixed in 12.2.
Document 17805926.8 - Parameter changes at PDB level affect other PDBs, fixed in 12.2


Popular Documents for Known issues/Bugs

Document 2034610.1 Things to Consider Before Upgrading to 12.1.0.2 to Avoid Poor Performance or Wrong Results
Document 2035898.1 Patches to Consider for 12.1.0.2 to Avoid Problems with SQL Plan Management (SPM)
Document 2107602.1 Things to Consider When Using Incremental Statistics
Document 1683802.1 12.1.0.2 Patch Set - List of Bug Fixes by Problem Type
Document 1924126.1 12.1.0.2 Patch Set Updates - List of Fixes in each PSU


Port-Specific

Document 1970525.1 Things to Consider to Avoid RDBMS Performance Problems on SPARC Platforms Using Oracle 12.1.0.2


Reference documents covering 12c new features

The following list of documents cover many of the features that have been introduced or enhanced in 12c and as provided to aid re-discovery:

Document 2031605.1 Adaptive Query Optimization
Document 2002108.1 Dynamic Sampling Level Is Changed Automatically in 12C
Document 2033658.1 Dictionary Queries Running Slow in 12C PDBs
Document 2002089.1 High Latch Free Waits on 'Result Cache: RC Latch' In 12C when RESULT_CACHE_MODE = MANUAL
Document 2004828.1 ORA-20002: Unable To Export Table Stats Using DBMS_STATS Package In 12c Database
Document 2051004.1 ORA-12012 ORA-20000 During Automatic Statistics Collection Job in 12C With Concurrent Option Enabled
Document 1955319.1 Huge Trace Files Created Containing "----- Cursor Obsoletion Dump sql_id=%s -----" From 12.1.0.2
Document 2053877.1 Wrong Results (0 Rows) Returned for Query that Includes Subquery Containing AND ROWNUM when OPTIMIZER_ADAPTIVE_FEATURES = TRUE
Document 2041541.1 Gather_Database_Stats_Job_Proc Taking More Time in 12.1.0.2 Than 11.2.0.4


Documentation

Database SQL Tuning Guide 12.1: http://docs.oracle.com/database/121/TGSQL/toc.htm
Database Performance Tuning Guide: http://docs.oracle.com/database/121/TGDBA/toc.htm
Database Testing Guide (RAT): http://docs.oracle.com/database/121/RATUG/toc.htm



参考:
Commonly Reported Known Issues for Database and Query Performance Reported in 12C (Doc ID 2097793.1 INTERNAL)
Documented Database Bugs With High “Solved SR” Count (Doc ID 2099231.1 INTERNAL)

12.2优化器和12.1优化器变化之处

$
0
0

在oracle 12.2的优化器,相比12.1已经有一些细微的变化,当我们将数据库从12.1升级到12.2,或者从12.1之前的版本,升级到12.2.需要在优化器的一些参数上引起注意,因为这些参数已经发生了变化。

在12.1中,有个统领全局的,是否启用自适应优化器参数,optimizer_adaptive_features。这个参数统领两大特性:自适应计划(adaptive plans)和自适应统计信息(adaptive statistics)。

但optimizer_adaptive_features这个参数在12.2已经过期。自适应优化器的两大部分,自适应计划(adaptive plans)和自适应统计信息(adaptive statistics)将有2个独自的参数进行控制:

optimizer_adaptive_plans 默认值为TRUE
optimizer_adaptive_statistics 默认值为FALSE

而自适应统计信息,默认被设置成了false,估计是很多人在12.1的时候,遭遇到了由于SQL执行计划指导(SQL Plan Directives,SPD)产生了过量动态采样的问题。

可以见我之前的这篇文章《SQL Plan Directives与过量的动态采样》,在这篇文章中,我是建议在12.1中,禁用SPD产生新的directive,以及禁止SPD动态采样的。在12.2中,自适应统计信息(adaptive statistics)默认被关闭,也就是说,自适应统计信息所包含的3个功能:动态采样(Dynamic Statistics)、自动重优化(automatic reoptimization)、SPD都被默认关闭了。

另外,在mos中有篇文档Recommendations for Adaptive Features in Oracle Database 12c (Doc ID 2187449.1),在这个文档中提到,建议为12.1打上patch 22652097和patch 21171382,这2个patch的作用如下:

We recommend that upgrades to 12.1 adopt the 12.2 defaults. This may be done by applying the following patches for your version and platform:

Patch 22652097 splits the parameter optimizer_adaptive_features into two, as above, and disables adaptive statistics.
Patch 21171382 disables the automatic creation of extended statistics unless the optimizer preference AUTO_STAT_EXTENSIONS is set to ON.

If you are already on 12.1, but are encountering performance problems, you may want to consider applying the above patches.

那么,我们的升级场景可以分为如下:
1. 从11.2或者更早的版本升级到12.2
==> 什么都不用动

2. 从12.1升级到12.2
2.1 如果已经打上patch 22652097和patch 21171382
==> 不需要做修改,
==> 升级到12.2后检查optimizer_adaptive_plans是否为true;optimizer_adaptive_statistics是否为false;AUTO_STAT_EXTENSIONS是否为off。

2.2 如果没有打过patch 22652097和patch 21171382
==> 你需要取消在初始化参数中的optimizer_adaptive_features,因为这个参数已在12.2过期;
==> 取消之前可能设置过的关于_optimizer_dsdir_usage_control和_sql_plan_directive_mgmt_control的设置;
==> 检查optimizer_adaptive_plans是否为true;optimizer_adaptive_statistics是否为false;AUTO_STAT_EXTENSIONS是否为off

参考:
Recommendations for Adaptive Features in Oracle Database 12c (Doc ID 2187449.1)
SQL Plan Directives与过量的动态采样
Optimizer Adaptive Features in Oracle Database 12c Release 2

12.2 online TDE

$
0
0

在12.2之前,如果对表空间进行透明数据加密,这是需要停机时间的,可参考 Oracle Advanced Security 透明数据加密最佳实践,但是在12.2中,我们可以不用停机的进行TDE加密了。

是的,no downtime。

我们先来创建一个表空间,创建一个表,如信用卡信息表(credit_card表),里面放的是信用卡用户名和信用卡号。通过strings数据文件,其实我们是可以看到存储的数据的。也就是说,如果有人得到了这个数据文件,是可以窥探到其中的信息的。包括像信用卡用户和卡号这样的敏感信息。

1.先创建一个测试用户test。

[oracle12c@testdb10 ~]$ sqlplus "/ as sysdba"

SQL*Plus: Release 12.2.0.1.0 Production on Sun Mar 12 23:28:07 2017

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> create tablespace tbs_test datafile size 100m;

Tablespace created.

SQL> create user test identified by test;

User created.

SQL> grant connect,resource,unlimited tablespace to test;

Grant succeeded.

2.在测试用户下创建信用卡信息表,insert数据。并做个move。

SQL> conn test/test
Connected.
SQL> create table credit_card (name varchar2(20), card_no varchar2(50)) tablespace tbs_test;

Table created.

SQL> insert into credit_card (name,card_no) select 'Jimmy',rownum+1000 from dual connect by level<=10000;

10000 rows created.

SQL> commit;

Commit complete.


SQL> insert into test.credit_card select * from test.credit_card ;

10000 rows created.

SQL> /

20000 rows created.

SQL> commit;

Commit complete.


SQL> alter table test.credit_card move;

Table altered.

3.找到该表所在的表空间是在哪个数据文件上,我们通过strings该数据文件,可以看到对应的信息:

SQL> select file_name from dba_data_files where tablespace_name='TBS_TEST';

FILE_NAME
--------------------------------------------------------------------------------
/u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_tbs_test_ddbt8d1l_.dbf

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle12c@testdb10 ~]$
[oracle12c@testdb10 ~]$
[oracle12c@testdb10 ~]$
[oracle12c@testdb10 ~]$ strings /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_tbs_test_ddbt8d1l_.dbf |more
}|{z
ORA12C
TBS_TEST
AAAAAAAAAAAAAAAA
        ,       :       H       V       d       r
Jimmy
3041,
Jimmy
3042,
Jimmy
3043,
Jimmy
3044,
Jimmy
3045,
Jimmy
3046,
Jimmy
3047,
Jimmy
3048,
Jimmy
3049,
Jimmy
3050,
Jimmy
3051,
Jimmy
3052,
Jimmy
3053,
Jimmy
3054,
Jimmy
3055,
Jimmy
3056,
Jimmy
3057,
Jimmy
3058,
Jimmy
3059,
Jimmy
3060,
Jimmy
3061,
Jimmy
3062,
Jimmy
3063,
Jimmy
3064,
……

[oracle12c@testdb10 ~]$

好了。我们现在利用12.2的online TDE功能进行数据加密。

4. 首先,做一些启用TDE的准备工作,这在12.1的时候也是这么操作的:
4.1 创建keystore目录:

[oracle12c@testdb10 ~]$ cd $ORACLE_HOME
[oracle12c@testdb10 db_1]$ ls
addnode     bin    cfgtoollogs  css  data    dc_ocm     diagnostics  env.ora  install        javavm  jlib  log  network  odbc    opmn         ord    oss  perl     QOpatch  rdbms     schagent.conf  sqldeveloper  sqlplus   sysman  utl
apex        ccr    clone        ctx  dbjava  deinstall  dmu          has      instantclient  jdbc    ldap  md   nls      olap    oracore      ordim  oui  plsql    R        relnotes  scheduler      sqlj          srvm      ucp     wwg
assistants  cdata  crs          cv   dbs     demo       dv           hs       inventory      jdk     lib   mgw  oc4j     OPatch  oraInst.loc  ords   owm  precomp  racg     root.sh   slax           sqlpatch      suptools  usm     xdk
[oracle12c@testdb10 db_1]$ mkdir keystore
[oracle12c@testdb10 db_1]$ cd keystore
[oracle12c@testdb10 keystore]$ pwd
/u01/ora12c/app/oracle/product/12.2.0.1/db_1/keystore
[oracle12c@testdb10 keystore]$

4.2 修改sqlnet.ora

[oracle12c@testdb10 keystore]$ cd $ORACLE_HOME/network/admin
[oracle12c@testdb10 admin]$
[oracle12c@testdb10 admin]$ ls
samples  shrept.lst  sqlnet.ora
[oracle12c@testdb10 admin]$
[oracle12c@testdb10 admin]$ ##修改前:
[oracle12c@testdb10 admin]$ cat sqlnet.ora
# sqlnet.ora Network Configuration File: /u01/ora12c/app/oracle/product/12.2.0.1/db_1/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.

NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)

[oracle12c@testdb10 admin]$
[oracle12c@testdb10 admin]$
[oracle12c@testdb10 admin]$
[oracle12c@testdb10 admin]$
[oracle12c@testdb10 admin]$ ##修改后:
[oracle12c@testdb10 admin]$ cat sqlnet.ora
# sqlnet.ora Network Configuration File: /u01/ora12c/app/oracle/product/12.2.0.1/db_1/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.

NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)

ENCRYPTION_WALLET_LOCATION =
  (SOURCE =(METHOD = FILE)(METHOD_DATA =
    (DIRECTORY = /u01/ora12c/app/oracle/product/12.2.0.1/db_1/keystore/)
[oracle12c@testdb10 admin]$
[oracle12c@testdb10 admin]$

4.3 创建和打开keystore密码
注:ADMINISTER KEY MANAGEMENT命令是12.1引入的命令,之前11g和10g是用ALTER SYSTEM SET ENCRYPTION KEY和ALTER SYSTEM SET ENCRYPTION WALLET操作:

[oracle12c@testdb10 admin]$ sqlplus "/ as sysdba"

SQL*Plus: Release 12.2.0.1.0 Production on Sun Mar 12 23:53:49 2017

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production


SQL> administer key management create keystore
  2  '/u01/ora12c/app/oracle/product/12.2.0.1/db_1/keystore' identified by oracleblog;

keystore altered.

SQL>
SQL> administer key management set keystore
  2  open identified by oracleblog;

keystore altered.

SQL> administer key management set key
  2  identified by oracleblog with backup;

keystore altered.

SQL>

5.进行在线透明数据加(注意表空间的数据文件名字会被修改成别的):

SQL> select tablespace_name,file_name from dba_data_files
SQL> /

TABLESPACE_NAME                          FILE_NAME
---------------------------------------- --------------------------------------------------------------------------------
SYSTEM                                   /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_system_ddbr1kg4_.dbf
SYSAUX                                   /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_sysaux_ddbr1x14_.dbf
UNDOTBS1                                 /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_undotbs1_ddbr23dc_.dbf
USERS                                    /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_users_ddbr2ktc_.dbf
TBS_TEST                                 /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_tbs_test_ddbt8d1l_.dbf

SQL>
SQL>
SQL>
SQL> alter tablespace tbs_test encryption online using 'AES192' encrypt ;

Tablespace altered.

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                          FILE_NAME
---------------------------------------- --------------------------------------------------------------------------------
SYSTEM                                   /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_system_ddbr1kg4_.dbf
SYSAUX                                   /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_sysaux_ddbr1x14_.dbf
UNDOTBS1                                 /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_undotbs1_ddbr23dc_.dbf
USERS                                    /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_users_ddbr2ktc_.dbf
TBS_TEST                                 /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_tbs_test_ddbw3m85_.dbf

SQL>
SQL>

注意我们这里使用了omf,所以不用指定TDE之后的数据文件名,如果你原来不使用omf,可以手工的指定转换的文件名,只需加上file_name_convert即可:

SQL> alter tablespace tbs_test encryption online using 'AES192'
  2  encrypt file_name_convert('tbs_test','tbs_test_enc');

6.现在,我们再次strings数据文件,可以看到已经被加密了:

[oracle12c@testdb10 admin]$ strings /u01/ora12c/app/oracle/oradata/ORA12C/datafile/o1_mf_tbs_test_ddbw3m85_.dbf |more
}|{z
ORA12C
TBS_TEST
r9Y(
%mja
YPQ#
*]dV
/MN5
><=z9
?EM+$qWg
y/I9
USBV%1l
,xoY
Sk,|
hk*s
NB?:
j]rv
}Yf#
rwTY
Ytho
Y0\V
Fd"^
|Gmx\c
p       z<
[5a%
        qgc
MCxB
Mj1q$a
P_Uq
Xw_&K/t
MF*~
 j^     t
[P]Z
XTXz
B@U&
l?T-
wgn5
4b~]M
T(Qa
9m= ((6
U"bk
F~mq
6veW
jNEc
}:{Qh
]-?b
)dEND
_rd~
2"O:
jVW"
FtG;PXl~3T
>=y.
Uc7;
:!a[
:L~\O
fk4[[
ZB3+
3jU\
'm!6
eSm_
F,j(d|
        T*O
/BI;
"Xay
reIQ!
EGEn7
[oracle12c@testdb10 admin]$

最后,需要提醒的是,虽然TDE已经可以在线操作,但是在转换的过程中,还是会对性能有一定的影响,根据swingbench的测试,对OLTP系统大约会有50%的性能影响,也就是说,OLTP每秒事务数下降一半。

所以不建议在业务时间段进行TDE的转换操作,而是找非业务峰值的时间进行操作。

参考:
1. Oracle Advanced Security 透明数据加密最佳实践
2. Multitenant : Transparent Data Encryption (TDE) in Pluggable Databases (PDBs) in Oracle Database 12c Release 1 (12.1)
3. 12c Release 2 – Transparent Data Encryption online !
4. ORACLE DATABASE 12.2 – NEW FEATURE: ONLINE TRANSPARENT DATA ENCRYPTION (TDE)

12c的一些新等待事件

$
0
0

今天用swingbench加载数据的时候,发现了一些之前没有看过的等待事件,列举一下:

(1)LGWR worker group idle
这是因为12c默认是以adaptive方式启用scalable lgwr,即会在自动的在 single<-->scalable 之间进行切换,可以参考我的这个文章。
设置 alter system set “_use_single_log_writer”=true scope=spfile; 之后,即可恢复到12c之前的模式,从而不再有LGWR worker group idle等待。

(2)lreg timer
12c有一个新的进程LREG:
LREG (Listener Registration Process) Registers the instance with the listeners。在12c之前,是有pmon将数据库注册到listener中(动态注册,大约需要60秒的时间才会注册进去,除非alter system register),而在12c之后,将有lreg进程来做这个事情。当instance启动的时候,lrge进程会轮询listener是否已经启动,如果已经启动就将数据库的信息注册到listener中。如果listner还没有启动,轮询就会间隔大约每3000毫秒检查一次。strace的结果可以看到:epoll_wait(7, {}, 1024, 3000)

epoll_wait(7, {}, 1024, 3000)           = 0
getrusage(0x1 /* RUSAGE_??? */, {ru_utime={0, 43993}, ru_stime={0, 22996}, ...}) = 0
getrusage(0x1 /* RUSAGE_??? */, {ru_utime={0, 43993}, ru_stime={0, 22996}, ...}) = 0
epoll_wait(7, {}, 1024, 3000)           = 0
getrusage(0x1 /* RUSAGE_??? */, {ru_utime={0, 43993}, ru_stime={0, 23996}, ...}) = 0
getrusage(0x1 /* RUSAGE_??? */, {ru_utime={0, 43993}, ru_stime={0, 23996}, ...}) = 0
epoll_wait(7, {}, 1024, 3000)           = 0

注:还会去读/proc/loadavg,猜测可能在资源消耗高的情况下,延缓注册database到listener:

open("/proc/loadavg", O_RDONLY)         = 10
fstat(10, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5f0f198000
read(10, "0.07 0.27 0.25 2/306 3175\n", 1024) = 26
close(10)                               = 0

也还会读/etc/hosts文件(所以如果hosts配置不正确,也会无法实现动态注册)

open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 10
fstat(10, {st_mode=S_IFREG|0644, st_size=169, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5f0f198000
read(10, "# Do not remove the following li"..., 4096) = 169
read(10, "", 4096)                      = 0
close(10)                               = 0

oracle把listener动态注册从pmon独立出来,让新进程lreg来做动态注册这个事情,我们可以看到:
1. 动态注册的时间短了,原来60秒,现在3秒
2. pmon减轻了压力,注册的事情有lreg进程来完成。

(3)heartbeat redo informer

SQL> l
  1* select sid,spid,event from v$session a,v$process b where a.paddr=b.addr and a.event like '%heart%'
SQL> /

       SID SPID                     EVENT
---------- ------------------------ ----------------------------------------
        20 2152                     heartbeat redo informer

SQL> !ps -ef |grep 2152
54322     2152     1  0 22:35 ?        00:00:00 ora_tt02_ora12c
54322     3486  3448  0 23:13 pts/3    00:00:00 /bin/bash -c ps -ef |grep 2152
54322     3488  3486  0 23:13 pts/3    00:00:00 grep 2152

SQL>
SQL>
SQL> l
  1*   select name,pid,type,role from V$DATAGUARD_PROCESS
SQL> /

NAME  PID                      TYP ROLE
----- ------------------------ --- -----------------------
LGWR  2108                     KSB log writer
TMON  2140                     KSB redo transport monitor
TT00  2148                     KSV gap manager
TT01  2150                     KSV redo transport timer
TT02  2152                     KSV heartbeat redo informer

SQL>


(出自在线文档

可以看到,原来在11g中,有arch进程来做dataguard的heartbeat检测,在12c中,也多出来TMON和TTnn进程来做dataguard之间的gap检测和心跳检测。
但是这个进程,不管是否启用dataguard,都会存在。当没有dataguard的时候,他就处于heartbeat redo informer这个空闲等待了。
注:TMON进程是Redo Transport Process monitor,是async模式下用来监控redolog和standby redolog之间的同步关系,TTnn是TMON派生出来的slave进程

参考:
New Idle Events are Erroneously Listed in STATSPACK Report (Doc ID 1998538.1)
New Background Processes In 12c (Doc ID 1625912.1)

关于11g和12c数据库初始化参数的一些最佳实践参考

$
0
0

Base on 11.2.0.4 :

 

Base on 12.1.0.2 :

Oracle支持在docker上跑oracle数据库了

$
0
0

Oracle开始支持在docker上oracle数据库了,注意,是单实例,RAC不支持。docker的操作系统需要时候Oracle linux 7或者RHEL 7。

Oracle will support customers running Oracle Database (single instance) in Docker containers. Oracle will only provide support when running the database in Docker containers running on Oracle Linux and Red Hat RHEL. Supported versions of these Linux distributions are

Oracle Linux 7
Red Hat Enterprise Linux 7 (RHEL)

Oracle does not support Oracle Database running in a Real Application Clusters (RAC) configuration in Docker containers.


另外,在github上也有一个非官方的如何制作oracle database on docker的image。

参考:
Oracle Support for Database Running on Docker (Doc ID 2216342.1)


在MAC上安装docker并部署oracle12.2

$
0
0

其实很早就想写这篇,但是由于工作忙,一直没有来得整理出来。趁着周末,发布出来吧。

在本文中,你将看到:

1. 在Mac上安装docker,并启动docker
2. 部署oracle docker的build file,并创建image
3. 部署oracle软件在docker中
4. 安装oracle实例在docker中
5. 启动,停止docker以及如何连接数据库

一。在Mac上安装docker。
到docker store下载即可。下载地址是:https://store.docker.com/editions/community/docker-ce-desktop-mac
其实我们还可以看到别的操作系统的版本,如centos版本,aws版本,Ubuntu版本等等,在centos上,可以用wget命令进行下载。在这里我们用到的是mac版本。

下载完成后,我们得到116M左右的Docker.dmg文件,点击拖动到application文件夹进行安装。

安装完成后,你就可以在launchpad中看到docker图标,点击打开:

适当调整一下cpu内存分配,如给一半资源,4个CPU,16G内存。注意这里也可以看到了你的container image的位置在哪里,点击move可以挪到别的位置去。

启动之后,你就可以在终端敲docker info检查了。

LoveHousedeiMac:Oracle 12c on docker lovehouse$ docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.03.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.27-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.65 GiB
Name: moby
ID: CINI:FSC5:XEQX:BERH:YCH5:7BGY:D4WD:NKME:MVGR:VYFL:JONR:DQ7D
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 19
 Goroutines: 36
 System Time: 2017-05-20T13:54:44.607290579Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
LoveHousedeiMac:Oracle 12c on docker lovehouse$

其实安装完docker之后,你可以在docker store中直接pull oracle database 12c(12.1.0.2版本)

但是一方面这个版本是oracle 12.1版本,不是最新的12.2版本,另一方面数据库是包含在container中,如果删除container,就也一并删除了database,这不是我们所想要的。我们选择将container和database的数据文件分开。

二、部署oracle docker的build file,并创建image
到github下载oracle的build file:docker-images-master.zip,地址是https://github.com/oracle/docker-images,是一个约5M的文件。

下载完成后,找个目录解压。如我是放在/Users/[username]/iDocker 下。

然后到otn下载oracle 12.2的安装介质linuxx64_12201_database.zip。下载地址是:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html,是一个3.2G的文件。

下载完成后,将安装介质放在docker-images-master解压之后的目录下:/Users/[username]/idocker/docker-images-master/OracleDatabase/dockerfiles/12.2.0.1,即:

/Users/lovehouse/idocker/docker-images-master/OracleDatabase/dockerfiles/12.2.0.1
LoveHousedeiMac:12.2.0.1 lovehouse$ ls -l
total 6745656
-rw-r--r--@ 1 lovehouse  staff          62 May 20 20:04 Checksum.ee
-rw-r--r--@ 1 lovehouse  staff          62 May 20 20:04 Checksum.se2
-rw-r--r--@ 1 lovehouse  staff        2547 May 20 20:04 Dockerfile.ee
-rw-r--r--@ 1 lovehouse  staff        2549 May 20 20:04 Dockerfile.se2
-rwxr-xr-x@ 1 lovehouse  staff        1259 May 20 20:04 checkDBStatus.sh
-rwxr-xr-x@ 1 lovehouse  staff         839 May 20 20:04 checkSpace.sh
-rwxr-xr-x@ 1 lovehouse  staff        2898 May 20 20:04 createDB.sh
-rw-r--r--@ 1 lovehouse  staff        6878 May 20 20:04 db_inst.rsp
-rw-r--r--@ 1 lovehouse  staff        9264 May 20 20:04 dbca.rsp.tmpl
-rwxr-xr-x@ 1 lovehouse  staff        2057 May 20 20:04 installDBBinaries.sh
-rwxr-xr-x@ 1 lovehouse  staff        1065 May 20 20:04 installPerl.sh
-rwxrwxrwx@ 1 lovehouse  staff  3453696911 Mar 12 19:02 linuxx64_12201_database.zip
-rwxr-xr-x@ 1 lovehouse  staff        5332 May 20 20:04 runOracle.sh
-rwxr-xr-x@ 1 lovehouse  staff         769 May 20 20:04 setPassword.sh
-rwxr-xr-x@ 1 lovehouse  staff         876 May 20 20:04 setupLinuxEnv.sh
-rwxr-xr-x@ 1 lovehouse  staff         689 May 20 20:04 startDB.sh
LoveHousedeiMac:12.2.0.1 lovehouse$

三、部署oracle软件在docker中
很简单,就一条命令:

./buildDockerImage.sh -v 12.2.0.1 -e

其中Parameters:
   -v: version to build
       Choose one of: 11.2.0.2  12.1.0.2  12.2.0.1
   -e: creates image based on 'Enterprise Edition'
   -s: creates image based on 'Standard Edition 2'
   -x: creates image based on 'Express Edition'
   -i: ignores the MD5 checksums

需要注意的时候,在安装过程中需要联网,因为他会下载oraclelinux:7-slim和yum install pre-install的包。

LoveHousedeiMac:dockerfiles lovehouse$ ./buildDockerImage.sh -v 12.2.0.1 -e
Ignored MD5 sum, 'md5sum' command not available.
==========================
DOCKER info:
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.03.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs

……

Step 16/16 : CMD exec $ORACLE_BASE/$RUN_FILE
 ---> Running in 14330d207a42
 ---> 4f9df5f46a19
Removing intermediate container 14330d207a42
Successfully built 4f9df5f46a19

  Oracle Database Docker Image for 'ee' version 12.2.0.1 is ready to be extended:

    --> oracle/database:12.2.0.1-ee

  Build completed in 931 seconds.

LoveHousedeiMac:dockerfiles lovehouse$

附件是完整的log:build.log

安装完成这一步后,我们就可以用docker images命令看我们的安装情况了:
可以看到oracle linux和oracle database软件已经被装好。

LoveHousedeiMac:Data lovehouse$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
oracle/database     12.2.0.1-ee         4f9df5f46a19        2 hours ago         14.8 GB
oraclelinux         7-slim              442ebf722584        4 weeks ago         114 MB
LoveHousedeiMac:Data lovehouse$


四、安装oracle实例在docker中

安装数据库实例,也只需要一条命令:

docker run --name oracle -p 1521:1521 -p 5500:5500 -v /Users/[username]/oradata:/opt/oracle/oradata oracle/database:12.2.0.1-ee

其中Parameters:
   --name:        The name of the container (default: auto generated)
   -p:            The port mapping of the host port to the container port.
                  Two ports are exposed: 1521 (Oracle Listener), 5500 (OEM Express)
   -e ORACLE_SID: The Oracle Database SID that should be used (default: ORCLCDB)
   -e ORACLE_PDB: The Oracle Database PDB name that should be used (default: ORCLPDB1)
   -e ORACLE_PWD: The Oracle Database SYS, SYSTEM and PDB_ADMIN password (default: auto generated)
   -e ORACLE_CHARACTERSET:
                  The character set to use when creating the database (default: AL32UTF8)
   -v             The data volume to use for the database.
                  Has to be owned by the Unix user "oracle" or set appropriately.
                  If omitted the database will not be persisted over container recreation.

注意数据文件已经map到/Users/[username]/oradata下。此时就算你删除了container,这些数据文件还是会被保留的。
对应的log如下,注意到了最后,会停在那里,估计run命令最后调用类似docker logs -f oracle这样的命令,会tail -f类似的输出,所以我们可以直接在别的窗口docker stop oracle再docker start oracle。

LoveHousedeiMac:dockerfiles lovehouse$ docker run --name oracle -p 1521:1521 -p 5500:5500 -v /Users/lovehouse/oradata:/opt/oracle/oradata oracle/database:12.2.0.1-ee
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: scXX7Cj+1m0=1

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 20-MAY-2017 14:25:30

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

Starting /opt/oracle/product/12.2.0.1/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /opt/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/c9f09116cc83/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))

……

SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
Completed: alter pluggable database ORCLPDB1 open
2017-05-20T14:31:25.862061+00:00
ORCLPDB1(3):CREATE SMALLFILE TABLESPACE "USERS" LOGGING  DATAFILE  '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED  EXTENT MANAGEMENT LOCAL  SEGMENT SPACE MANAGEMENT  AUTO
ORCLPDB1(3):Completed: CREATE SMALLFILE TABLESPACE "USERS" LOGGING  DATAFILE  '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED  EXTENT MANAGEMENT LOCAL  SEGMENT SPACE MANAGEMENT  AUTO
ORCLPDB1(3):ALTER DATABASE DEFAULT TABLESPACE "USERS"
ORCLPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
2017-05-20T14:31:26.657295+00:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl' SCOPE=SPFILE;
   ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
Completed:    ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE

2017-05-20T14:41:16.140414+00:00
ORCLPDB1(3):Resize operation completed for file# 10, old size 337920K, new size 358400K

完整的log:run.log

如果“DATABASE IS READY TO USE!”字样已经出现,且后面的log一直停着不动,可以在别的窗口重启container:

LoveHousedeiMac:~ lovehouse$ docker stop oracle
oracle
LoveHousedeiMac:~ lovehouse$
LoveHousedeiMac:~ lovehouse$
LoveHousedeiMac:~ lovehouse$ docker start oracle
oracle
LoveHousedeiMac:~ lovehouse$

五、启动,停止docker以及如何连接数据库
到了最关心的部分,如何docker和连接数据库。
启停docker其实我们在上一步已经操作过,即:

docker stop oracle
docker start oracle

如果要看alertlog,可以:

docker logs oracle
docker logs -f oracle

后者是以tail -f的方式查看的。

连接数据库,注意我们一开始创建的数据库,密码是:

我们可以通过如下命令来修改密码:

docker exec oracle ./setPassword.sh XXXXXX

然后我们可以用Navicat这个Mac上最流行的客户端,连接oracle数据库。

另外,如果你想进入container,以传统的方式管理数据库,你可以这样:
先用docker ps -a查询出container的container id,再用docker exec -it [container id] /bin/bash 连接:

LoveHousedeiMac:12.2.0.1 lovehouse$ docker ps -a
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS                                            NAMES
c9f09116cc83        oracle/database:12.2.0.1-ee   "/bin/sh -c 'exec ..."   2 hours ago         Up About an hour    0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp   oracle
LoveHousedeiMac:12.2.0.1 lovehouse$
LoveHousedeiMac:12.2.0.1 lovehouse$
LoveHousedeiMac:12.2.0.1 lovehouse$
LoveHousedeiMac:12.2.0.1 lovehouse$ docker exec -it c9f09116cc83 /bin/bash
[oracle@c9f09116cc83 ~]$ ps -ef |grep ora_
oracle      21     1  0 15:00 ?        00:00:00 ora_pmon_ORCLCDB
oracle      23     1  0 15:00 ?        00:00:00 ora_clmn_ORCLCDB
oracle      25     1  0 15:00 ?        00:00:01 ora_psp0_ORCLCDB
……
oracle     360     1  0 15:00 ?        00:00:00 ora_q004_ORCLCDB
oracle    1017     1  0 16:04 ?        00:00:00 ora_w007_ORCLCDB
oracle    1031     1  0 16:05 ?        00:00:00 ora_w003_ORCLCDB
oracle    1081     1  0 16:12 ?        00:00:00 ora_w000_ORCLCDB
oracle    1496  1476  0 16:58 ?        00:00:00 grep --color=auto ora_
[oracle@c9f09116cc83 ~]$

参考:
https://sqlmaria.com/2017/04/27/oracle-database-12c-now-available-on-docker/
http://www.eygle.com/archives/2017/05/mac_docker_oracle_122.html

备份,迁移和克隆docker镜像

$
0
0

《Oracle支持在docker上跑oracle数据库了》《在MAC上安装docker并部署oracle12.2》 之后,我们再来看看如何将docker镜像进行备份,迁移和克隆。

(一)备份:
我们用docker ps看有几个container,注意如果加-a参数,则没有running的container也会显示出来。

LoveHousedeiMac:idocker lovehouse$ docker ps -a
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS                     PORTS               NAMES
c9f09116cc83        oracle/database:12.2.0.1-ee   "/bin/sh -c 'exec ..."   23 hours ago        Exited (137) 4 hours ago                       oracle
LoveHousedeiMac:idocker lovehouse$

我们先将该container commit成镜像:
先检查一下已经存在的image:

LoveHousedeiMac:idocker lovehouse$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
oracle/database     12.2.0.1-ee         4f9df5f46a19        23 hours ago        14.8 GB
oraclelinux         7-slim              442ebf722584        4 weeks ago         114 MB
LoveHousedeiMac:idocker lovehouse$

停下container,并进行commit:

LoveHousedeiMac:idocker lovehouse$ docker stop oracle
oracle
LoveHousedeiMac:idocker lovehouse$
LoveHousedeiMac:idocker lovehouse$ docker commit -p c9f09116cc83 container-backup
sha256:f58f6143fca7d2e001ce810b2d13b8adac9d64e4cc9f50477f0108bb246db3c0
LoveHousedeiMac:idocker lovehouse$

检查现有的image:

LoveHousedeiMac:idocker lovehouse$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
container-backup    latest              f58f6143fca7        4 seconds ago       15.3 GB
oracle/database     12.2.0.1-ee         4f9df5f46a19        23 hours ago        14.8 GB
oraclelinux         7-slim              442ebf722584        4 weeks ago         114 MB
LoveHousedeiMac:idocker lovehouse$

将container-backup 这个image做成tar文件:

LoveHousedeiMac:idocker lovehouse$ ls
docker-images-master
LoveHousedeiMac:idocker lovehouse$ docker save -o ./container-backup.tar container-backup
LoveHousedeiMac:idocker lovehouse$
LoveHousedeiMac:idocker lovehouse$ ls -l
total 29910416
-rw-------   1 lovehouse  staff  15314129920 May 21 21:48 container-backup.tar
drwxr-xr-x@ 19 lovehouse  staff          646 May 20 20:04 docker-images-master
LoveHousedeiMac:idocker lovehouse$

我们将container-backup.tar备份或者迁移至别的主机,或者路径。实现了docker container的迁移。

注意,由于之前我们建立database采用了分离式的持久化,即数据文件不是在container,是在/Users/[username]/oradata下,所以我们也要备份一份这个文件。

cd /Users/lovehouse
tar cvf oradata.tar oradata

(二)还原或克隆:
我们这里将备份的东西,load进去,并且成为oracle_2

先将数据文件还原,且文件夹命名成oradata_2

LoveHousedeiMac:~ lovehouse$ pwd
/Users/lovehouse
LoveHousedeiMac:~ lovehouse$ ls -l
total 7356176
drwxr-xr-x   4 lovehouse  staff         136 May 21 21:48 iDocker
drwxr-xr-x@  6 lovehouse  staff         204 May 21 22:21 oradata
drwxr-xr-x@  6 lovehouse  staff         204 May 21 22:21 oradata_2
LoveHousedeiMac:~ lovehouse$

将备份的tar包 load进去

LoveHousedeiMac:~ lovehouse$ cd idocker
LoveHousedeiMac:idocker lovehouse$ ls
container-backup.tar    docker-images-master
LoveHousedeiMac:idocker lovehouse$
LoveHousedeiMac:idocker lovehouse$  docker load -i ./container-backup.tar
94fd1a061ee3: Loading layer [==================================================>] 433.9 MB/433.9 MB
Loaded image: container-backup:latest
LoveHousedeiMac:idocker lovehouse$
LoveHousedeiMac:idocker lovehouse$
LoveHousedeiMac:idocker lovehouse$
LoveHousedeiMac:idocker lovehouse$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
container-backup    latest              f58f6143fca7        About an hour ago   15.3 GB
oracle/database     12.2.0.1-ee         4f9df5f46a19        25 hours ago        14.8 GB
oraclelinux         7-slim              442ebf722584        4 weeks ago         114 MB
LoveHousedeiMac:idocker lovehouse$

运行docker run创建container,注意端口要修改一下,以免占用原来的oracle这个container的端口。如果不修改,那么第二个container启动的时候会报错:port is already allocated

LoveHousedeiMac:idocker lovehouse$ docker run --name oracle_2 -p 1522:1521 -p 5501:5500 -v /Users/lovehouse/oradata_2:/opt/oracle/oradata container-backup:latest

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 21-MAY-2017 15:21:22

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

Starting /opt/oracle/product/12.2.0.1/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /opt/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/e12ff2cf32f2/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                21-MAY-2017 15:21:26
Uptime                    0 days 0 hr. 0 min. 2 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/e12ff2cf32f2/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully

SQL*Plus: Release 12.2.0.1.0 Production on Sun May 21 15:21:26 2017

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

Connected to an idle instance.

SQL> ORACLE instance started.

Total System Global Area 1610612736 bytes
Fixed Size                  8793304 bytes
Variable Size             520094504 bytes
Database Buffers         1073741824 bytes
Redo Buffers                7983104 bytes
Database mounted.
Database opened.
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
Shared IO Pool defaulting to 64MB. Trying to get it from Buffer Cache for process 83.
===========================================================
Dumping current patch information
===========================================================
No patches have been applied
===========================================================
Starting background process CJQ0
2017-05-21T15:21:43.968340+00:00
CJQ0 started with pid=40, OS id=295
Completed: ALTER DATABASE OPEN
2017-05-21T15:21:44.275108+00:00
db_recovery_file_dest_size of 12780 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
2017-05-21T15:21:47.119178+00:00
Setting Resource Manager plan SCHEDULER[0x4AC9]:DEFAULT_MAINTENANCE_PLAN via scheduler window
Setting Resource Manager CDB plan DEFAULT_MAINTENANCE_PLAN via parameter
ORCLPDB1(3):Setting Resource Manager plan SCHEDULER[0x4AC3]:DEFAULT_MAINTENANCE_PLAN via scheduler window
ORCLPDB1(3):Setting Resource Manager plan DEFAULT_MAINTENANCE_PLAN via parameter

至此,2个docker container已经同时跑起来。container-backup:latest这个container是利用第一个克隆出来的,并且做了端口映射,将1522映射到内部的1521,将5501映射到内部的5500。

LoveHousedeiMac:idocker lovehouse$ docker ps
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS                                            NAMES
e12ff2cf32f2        container-backup:latest       "/bin/sh -c 'exec ..."   3 minutes ago       Up 2 minutes        0.0.0.0:1522->1521/tcp, 0.0.0.0:5501->5500/tcp   oracle_2
c9f09116cc83        oracle/database:12.2.0.1-ee   "/bin/sh -c 'exec ..."   24 hours ago        Up 6 minutes        0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp   oracle
LoveHousedeiMac:idocker lovehouse$
LoveHousedeiMac:idocker lovehouse$

Oracle在12.1.0.2开始改变了补丁策略

$
0
0

Oracle在12.1.0.2开始,改变了补丁策略:在12.1.0.2之前,即12.1.0.1,11.2.0.4或者更早的版本之前,是推荐使用PSU的补丁策略的。但是从12.1.0.2开始,oracle更推荐使用Database Proactive Bundle Patches(简称DPBP)。

DPBP的内容,包含了PSU的内容,也包含了SPU的内容。可以说是一个十全大补丸。以170418为例,大小为2.1G,解压缩后近7G,要求system free space 13G。

DPBP适用于Engineered Systems,DB In-Memory,也适用于Non-Engineered Systems,RAC和非RAC。里面包含的补丁包括GI和DB,以及ACFS。

值得注意的是,DPBP,psu,spu是不同的路,一旦选择走某一条路,就不能走另外的路了。也就是说,如果你之前选择打PSU,那么如果你要改成打bp,就必须回滚之前的psu。

从发布的频率看,从12.1.0.2.160719开始,也是一个季度一次DPBP。

我们需要做的是:
1. 决定今后的补丁战略方向,是PSU还DPBP
2. 升级opatch到最新版本
3. opatchauto apply
4. opatch lsinventory检查
5. datapatch -verbose(之前是catch psu脚本)
6. select * from dba_registry_sqlpatch(之前是dba_hist_registry)

参考:
Oracle Database – Overview of Database Patch Delivery Methods (Doc ID 1962125.1)
12.1.0.2 Database Proactive Bundle Patches / Bundle Patches for Engineered Systems and DB In-Memory – List of Fixes in each Bundle (Doc ID 1937782.1)
Quick Reference to Patch Numbers for Database/GI PSU, SPU(CPU), Bundle Patches and Patchsets (Doc ID 1454618.1)

打DPBP 170418补丁

$
0
0

上一篇文章中提到,从oracle 12.1.0.2之后,oracle就推荐打Database Proactive Bundle Patches(简称DPBP,参考Oracle Database – Overview of Database Patch Delivery Methods (Doc ID 1962125.1))

打补丁的过程,可以参考补丁的readme.html文档,这里简单记录一下打DPBP 170418补丁的过程。
整体来说:
DPBP 170418,补丁号为25433352,里面包含4个大的补丁包。

25397136 这其实是db的补丁集。但是不仅仅要打在db home,grid home也是需要的。
25481150 这其实是个grid的补丁集,OCW的意思是Oracle Cluster Ware,所以你从这个名字中也可以猜到是for grid用的。但是不仅仅要打在grid home,db home也是需要的。
25363750 这个是for ACFS的补丁集
21436941 这个是DBWLM,即DataBase WorkLoad Management组件。

步骤为:

1. 升级opatch到最新版本。注,在opatch 12.2.0.1.5之前,执行opatchauto时需要加-ocmrf [ocm response file]参数。如果使用这个版本之后,就不需要再加响应文件的参数了。另外,170418这个DPBP要求使用opatch版本至少为12.2.0.1.7。

2. [GRID_HOME]/OPatch/opatchauto apply [UNZIPPED_PATCH_LOCATION]/25433352。注意,这个命令需要在各个节点上依次(非并行)执行。执行的时候,会bring down crs和database,会给grid home和oracle home打上补丁。依次打的方式,也减少了停机时间。

3. datapatch -verbose。注,上面说了依次打减少了停机时间,但是停机时间还是需要的,就是在这里的运行datapatch的时间。这个步骤是升级数据字典,针对整个database的数据字典,因此只需在一个节点上跑就可以了。主要注意的是,如果是cdb模式,需要alter pluggable database all open,打开所有的pdb之后,再运行datapatch。

4. 打完之后建议用orachk检查一下。

日志如下:
运行前的信息

======Mon Jun 12 00:11:09 CST 2017========
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ASMNET1LSNR_ASM.lsnr
               ONLINE  ONLINE       12102-rac1               STABLE
               ONLINE  ONLINE       12102-rac2               STABLE
               ONLINE  ONLINE       12102-rac3               STABLE
ora.DG_DATA.dg
               ONLINE  ONLINE       12102-rac1               STABLE
               ONLINE  ONLINE       12102-rac2               STABLE
               ONLINE  ONLINE       12102-rac3               STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       12102-rac1               STABLE
               ONLINE  ONLINE       12102-rac2               STABLE
               ONLINE  ONLINE       12102-rac3               STABLE
ora.net1.network
               ONLINE  ONLINE       12102-rac1               STABLE
               ONLINE  ONLINE       12102-rac2               STABLE
               ONLINE  ONLINE       12102-rac3               STABLE
ora.ons
               ONLINE  ONLINE       12102-rac1               STABLE
               ONLINE  ONLINE       12102-rac2               STABLE
               ONLINE  ONLINE       12102-rac3               STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.12102-rac1.vip
      1        ONLINE  ONLINE       12102-rac1               STABLE
ora.12102-rac2.vip
      1        ONLINE  ONLINE       12102-rac2               STABLE
ora.12102-rac3.vip
      1        ONLINE  ONLINE       12102-rac3               STABLE
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       12102-rac2               STABLE
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       12102-rac3               STABLE
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       12102-rac1               STABLE
ora.MGMTLSNR
      1        ONLINE  ONLINE       12102-rac1               169.254.161.44 192.1
                                                             68.57.34,STABLE
ora.asm
      1        ONLINE  ONLINE       12102-rac1               Started,STABLE
      2        ONLINE  ONLINE       12102-rac2               Started,STABLE
      3        ONLINE  ONLINE       12102-rac3               Started,STABLE
ora.cdbrac.db
      1        ONLINE  ONLINE       12102-rac3               Open,STABLE
      2        ONLINE  ONLINE       12102-rac1               Open,STABLE
      3        ONLINE  ONLINE       12102-rac2               Open,STABLE
ora.cvu
      1        ONLINE  ONLINE       12102-rac2               STABLE
ora.gns
      1        ONLINE  ONLINE       12102-rac1               STABLE
ora.gns.vip
      1        ONLINE  ONLINE       12102-rac1               STABLE
ora.mgmtdb
      1        ONLINE  ONLINE       12102-rac1               Open,STABLE
ora.oc4j
      1        ONLINE  ONLINE       12102-rac2               STABLE
ora.scan1.vip
      1        ONLINE  ONLINE       12102-rac2               STABLE
ora.scan2.vip
      1        ONLINE  ONLINE       12102-rac3               STABLE
ora.scan3.vip
      1        ONLINE  ONLINE       12102-rac1               STABLE
--------------------------------------------------------------------------------

SQL>  select * from dba_registry_sqlpatch;

no rows selected

SQL>

节点1的opatch版本检查,节点2,节点3的类似检查。

[root@12102-rac1 ~]# /u01/app/12.1.0.2/grid/OPatch/opatch version
OPatch Version: 12.2.0.1.9

OPatch succeeded.
[root@12102-rac1 ~]#

节点1的opatchauto,节点2,节点3的类似操作。

[root@12102-rac1 ~]# /u01/app/12.1.0.2/grid/OPatch/opatch version
OPatch Version: 12.2.0.1.9

OPatch succeeded.
[root@12102-rac1 ~]# /u01/app/12.1.0.2/grid/OPatch/opatchauto apply /u01/ora_inst/25433352

OPatchauto session is initiated at Sun Jun 11 21:43:31 2017

System initialization log file is /u01/app/12.1.0.2/grid/cfgtoollogs/opatchautodb/systemconfig2017-06-11_09-43-37PM.log.

Session log file is /u01/app/12.1.0.2/grid/cfgtoollogs/opatchauto/opatchauto2017-06-11_09-44-37PM.log
The id for this session is R7M1

Executing OPatch prereq operations to verify patch applicability on home /u01/app/12.1.0.2/grid

Executing OPatch prereq operations to verify patch applicability on home /u01/app/oracle/product/12.1.0.2/db_1
 Patch applicability verified successfully on home /u01/app/12.1.0.2/grid

 Patch applicability verified successfully on home /u01/app/oracle/product/12.1.0.2/db_1


Verifying SQL patch applicability on home /u01/app/oracle/product/12.1.0.2/db_1
SQL patch applicability verified successfully on home /u01/app/oracle/product/12.1.0.2/db_1


Preparing to bring down database service on home /u01/app/oracle/product/12.1.0.2/db_1
Successfully prepared home /u01/app/oracle/product/12.1.0.2/db_1 to bring down database service


Bringing down CRS service on home /u01/app/12.1.0.2/grid
  Prepatch operation log file location: /u01/app/12.1.0.2/grid/cfgtoollogs/crsconfig/crspatch_12102-rac1_2017-06-11_09-49-08PM.log
CRS service brought down successfully on home /u01/app/12.1.0.2/grid


Performing prepatch operation on home /u01/app/oracle/product/12.1.0.2/db_1
Perpatch operation completed successfully on home /u01/app/oracle/product/12.1.0.2/db_1


Start applying binary patch on home /u01/app/oracle/product/12.1.0.2/db_1
  Binary patch applied successfully on home /u01/app/oracle/product/12.1.0.2/db_1


Performing postpatch operation on home /u01/app/oracle/product/12.1.0.2/db_1
Postpatch operation completed successfully on home /u01/app/oracle/product/12.1.0.2/db_1


Start applying binary patch on home /u01/app/12.1.0.2/grid
   Binary patch applied successfully on home /u01/app/12.1.0.2/grid


Starting CRS service on home /u01/app/12.1.0.2/grid
   Postpatch operation log file location: /u01/app/12.1.0.2/grid/cfgtoollogs/crsconfig/crspatch_12102-rac1_2017-06-11_10-04-00PM.log
CRS service started successfully on home /u01/app/12.1.0.2/grid


Preparing home /u01/app/oracle/product/12.1.0.2/db_1 after database service restarted
No step execution required.........
Prepared home /u01/app/oracle/product/12.1.0.2/db_1 successfully after database service restarted


Trying to apply SQL patch on home /u01/app/oracle/product/12.1.0.2/db_1
  SQL patch applied successfully on home /u01/app/oracle/product/12.1.0.2/db_1

OPatchAuto successful.

--------------------------------Summary--------------------------------

Patching is completed successfully. Please find the summary as follows:

Host:12102-rac1
RAC Home:/u01/app/oracle/product/12.1.0.2/db_1
Summary:

==Following patches were SKIPPED:

Patch: /u01/ora_inst/25433352/21436941
Reason: This patch is not applicable to this specified target type - "rac_database"

Patch: /u01/ora_inst/25433352/25363750
Reason: This patch is not applicable to this specified target type - "rac_database"


==Following patches were SUCCESSFULLY applied:

Patch: /u01/ora_inst/25433352/25397136
Log: /u01/app/oracle/product/12.1.0.2/db_1/cfgtoollogs/opatchauto/core/opatch/opatch2017-06-11_21-52-02PM_1.log

Patch: /u01/ora_inst/25433352/25481150
Log: /u01/app/oracle/product/12.1.0.2/db_1/cfgtoollogs/opatchauto/core/opatch/opatch2017-06-11_21-52-02PM_1.log


Host:12102-rac1
CRS Home:/u01/app/12.1.0.2/grid
Summary:

==Following patches were SUCCESSFULLY applied:

Patch: /u01/ora_inst/25433352/21436941
Log: /u01/app/12.1.0.2/grid/cfgtoollogs/opatchauto/core/opatch/opatch2017-06-11_21-57-02PM_1.log

Patch: /u01/ora_inst/25433352/25363750
Log: /u01/app/12.1.0.2/grid/cfgtoollogs/opatchauto/core/opatch/opatch2017-06-11_21-57-02PM_1.log

Patch: /u01/ora_inst/25433352/25397136
Log: /u01/app/12.1.0.2/grid/cfgtoollogs/opatchauto/core/opatch/opatch2017-06-11_21-57-02PM_1.log

Patch: /u01/ora_inst/25433352/25481150
Log: /u01/app/12.1.0.2/grid/cfgtoollogs/opatchauto/core/opatch/opatch2017-06-11_21-57-02PM_1.log



OPatchauto session completed at Sun Jun 11 22:13:40 2017
Time taken to complete the session 30 minutes, 9 seconds
[root@12102-rac1 ~]#
[root@12102-rac1 ~]#

节点1的datapatch,节点2,节点3无需操作。

[oracle@12102-rac1 OPatch]$ sqlplus "/ as sysdba"

SQL*Plus: Release 12.1.0.2.0 Production on Mon Jun 12 00:19:54 2017

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options

SQL> alter pluggable database all open;

Pluggable database altered.

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options
[oracle@12102-rac1 OPatch]$ cd $ORACLE_HOME/OPatc
[oracle@12102-rac1 OPatch]$ ./datapatch -verbose
SQL Patching tool version 12.1.0.2.0 Production on Mon Jun 12 00:20:42 2017
Copyright (c) 2012, 2017, Oracle.  All rights reserved.

Log file for this invocation: /u01/app/oracle/cfgtoollogs/sqlpatch/sqlpatch_26172_2017_06_12_00_20_42/sqlpatch_invocation.log

Connecting to database...OK
Note:  Datapatch will only apply or rollback SQL fixes for PDBs
       that are in an open state, no patches will be applied to closed PDBs.
       Please refer to Note: Datapatch: Database 12c Post Patch SQL Automation
       (Doc ID 1585822.1)
Bootstrapping registry and package to current versions...done
Determining current state... done

Current state of SQL patches:
Bundle series DBBP:
  ID 170418 in the binary registry and not installed in any PDB

Adding patches to installation queue and performing prereq checks...
Installation queue:
  For the following PDBs: CDB$ROOT PDB$SEED PDBRAC1 PDBRAC2
    Nothing to roll back
    The following patches will be applied:
      25397136 (DATABASE BUNDLE PATCH 12.1.0.2.170418)

Installing patches...



Patch installation complete.  Total patches installed: 4

Validating logfiles...
Patch 25397136 apply (pdb CDB$ROOT): SUCCESS
  logfile: /u01/app/oracle/cfgtoollogs/sqlpatch/25397136/21145057/25397136_apply_CDBRAC_CDBROOT_2017Jun12_00_23_03.log (no errors)
Patch 25397136 apply (pdb PDB$SEED): SUCCESS
  logfile: /u01/app/oracle/cfgtoollogs/sqlpatch/25397136/21145057/25397136_apply_CDBRAC_PDBSEED_2017Jun12_00_42_12.log (no errors)
Patch 25397136 apply (pdb PDBRAC1): SUCCESS
  logfile: /u01/app/oracle/cfgtoollogs/sqlpatch/25397136/21145057/25397136_apply_CDBRAC_PDBRAC1_2017Jun12_00_42_12.log (no errors)
Patch 25397136 apply (pdb PDBRAC2): SUCCESS
  logfile: /u01/app/oracle/cfgtoollogs/sqlpatch/25397136/21145057/25397136_apply_CDBRAC_PDBRAC2_2017Jun12_00_42_10.log (no errors)
SQL Patching tool complete on Mon Jun 12 00:59:05 2017


SQL> select PATCH_ID,PATCH_UID,VERSION,ACTION,STATUS,DESCRIPTION,BUNDLE_SERIES,BUNDLE_ID from dba_registry_sqlpatch
  2
SQL> /

  PATCH_ID  PATCH_UID VERSION              ACTION          STATUS          DESCRIPTION                                                                                          BUNDLE_SERIES                   BUNDLE_ID
---------- ---------- -------------------- --------------- --------------- ---------------------------------------------------------------------------------------------------- ------------------------------ ----------
  25397136   21145057 12.1.0.2             APPLY           SUCCESS         DATABASE BUNDLE PATCH 12.1.0.2.170418                                                                DBBP                               170418

SQL>
[oracle@12102-rac1 OPatch]$

最后在用orachk检查一下。

题外话,你可能会觉得奇怪,我db打了25397136和25481150两个补丁,为什么我只看到了PATCH_ID为25397136的注册信息,没看到25481150的信息?

这是因为,25481150没有产生需要执行的sqlpatch脚本,首先,你可以在$ORACLE_HOME/sqlpatch下是没有看到与25481150相关的需要执行的脚本的。

[oracle@12102-rac1 sqlpatch]$ pwd
/u01/app/oracle/product/12.1.0.2/db_1/sqlpatch
[oracle@12102-rac1 sqlpatch]$ ls
20243804  20594149  20950328  21359749  21694919  22806133  24340679  25397136  sqlpatch      sqlpatch_bootstrap_driver.sql  sqlpatch.pl
20415006  20788771  21125181  21527488  21949015  23144544  24732088  lib       sqlpatch.bat  sqlpatch_bootstrap.sql         sqlpatch.pm
[oracle@12102-rac1 sqlpatch]$

而为什么没有在$ORACLE_HOME/sqlpatch下生产脚本,这是由于25481150这个补丁不需要生产执行的脚本。我们可以通过查验action.xml确认。

[oracle@12102-rac1 config]$ pwd
/u01/ora_inst/25433352/25481150/etc/config
[oracle@12102-rac1 config]$
[oracle@12102-rac1 config]$ ls -l
total 168
-rw-r--r--. 1 oracle oinstall 102444 Mar 28 21:00 actions.xml
-rw-rw-r--. 1 oracle oinstall  63645 Mar 28 21:01 inventory.xml
[oracle@12102-rac1 config]$
[oracle@12102-rac1 config]$
[oracle@12102-rac1 config]$ cat actions.xml |grep -i sqlpatch
[oracle@12102-rac1 config]$

我们看到是不包含放到sqlpatch目录下的操作。(一般会是onewaycopy具体的脚本)

注:补丁的所有操作,都会写在这个action.xml文件里面。如备份文件,拷贝文件,删除文件,编译文件等等。注意需要最新的opatch,才能执行最新的action.xml。

Real-time materialized view,面向开发者的12.2新特性

$
0
0

先来谈谈为什么要有这个real time mv。

在12.2之前,如果你想获得实时的数据,那么在利用query rewrite前,你必须得用on commit的刷新方式刷新物化视图。但是on commit的刷新方式有众多限制,如sql的复杂度,如频繁对系统的压力等等。所以,我们不得不采用on command的方式来进行刷新(不管是全量刷新还是增量刷新)。那么在使用on command刷新的时候,必须得有个job来定时的刷,那么,在一次job运行之后,下一次job到来之前,如果基表有数据变化,那么此时的数据肯定不是最新的。

real time mv就是为了解决这个问题而生的。它即可以帮你获取实时的数据,且不用频繁的刷新mv。

我们来看一下这是怎么实现的。

传统mv的创建方式:

SQL> create table t1 (x not null primary key, y not null) as
  2    select rownum x, mod(rownum, 10) y from dual connect by level <= 1000000;

Table created.

SQL> create materialized view log on t1 with rowid (x, y) including new values;

Materialized view log created.

SQL>
SQL> create materialized view mv_old
  2  refresh fast on demand
  3  enable on query computation
  4  enable query rewrite
  5  as
  6    select y , count(*) c1
  7    from t1
  8    group by y;

Materialized view created.

SQL>
SQL>

Real time mv的创建方式:
注意在create mv时的关键字:enable on query computation

SQL> create table t2 (x not null primary key, y not null) as
  2    select rownum x, mod(rownum, 10) y from dual connect by level <= 1000000;

Table created.

SQL> create materialized view log on t2 with rowid (x, y) including new values;

Materialized view log created.

SQL>
SQL> create materialized view mv_new
  2  refresh fast on demand
  3  enable on query computation
  4  enable query rewrite
  5  as
  6    select y , count(*) c1
  7    from t2
  8    group by y;

Materialized view created.

SQL>
SQL>

我们来比较一下传统mv和real time mv的差别:
相关参数:

SQL> show parameter rewr

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
query_rewrite_enabled                string      TRUE
query_rewrite_integrity              string      enforced
SQL>
SQL>
SQL>
SQL>
SQL> set autotrace on explain stat
SQL>

初始状态:
传统mv:

SQL> select  y as y_new_parse1, count(*) from t1
  2  group by y;

Y_NEW_PARSE1   COUNT(*)
------------ ----------
           1     100000
           6     100000
           2     100000
           4     100000
           5     100000
           8     100000
           3     100000
           7     100000
           9     100000
           0     100000

10 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 2738786661

---------------------------------------------------------------------------------------
| Id  | Operation                    | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |        |    10 |    60 |     3   (0)| 00:00:01 |
|   1 |  MAT_VIEW REWRITE ACCESS FULL| MV_OLD |    10 |    60 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------------------


Statistics
----------------------------------------------------------
       1029  recursive calls
          2  db block gets
       1587  consistent gets
         76  physical reads
          0  redo size
        739  bytes sent via SQL*Net to client
        608  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
         86  sorts (memory)
          0  sorts (disk)
         10  rows processed

SQL>
SQL>

Real time mv:

SQL> select  y as y_new_parse1, count(*) from t2
  2  group by y;

Y_NEW_PARSE1   COUNT(*)
------------ ----------
           1     100000
           6     100000
           2     100000
           4     100000
           5     100000
           8     100000
           3     100000
           7     100000
           9     100000
           0     100000

10 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 496717744

---------------------------------------------------------------------------------------
| Id  | Operation                    | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |        |    10 |    60 |     3   (0)| 00:00:01 |
|   1 |  MAT_VIEW REWRITE ACCESS FULL| MV_NEW |    10 |    60 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------------------


Statistics
----------------------------------------------------------
        170  recursive calls
         13  db block gets
        248  consistent gets
          7  physical reads
       2008  redo size
        739  bytes sent via SQL*Net to client
        608  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
         21  sorts (memory)
          0  sorts (disk)
         10  rows processed

SQL>

看到此时2个物化视图,数据都是最新的,staleness显示是fresh:

SQL> select mview_name,staleness,on_query_computation from user_mviews;

MVIEW_NAME                               STALENESS           O
---------------------------------------- ------------------- -
MV_OLD                                   FRESH               N
MV_NEW                                   FRESH               Y

SQL>

物化视图日志里面也没有记录

SQL> select count(*) from MLOG$_T1;

  COUNT(*)
----------
         0

SQL> select count(*) from MLOG$_T2;

  COUNT(*)
----------
         0

SQL>

我们对基表insert数据:

SQL> insert into t1
  2  select 1000000+rownum, mod(rownum, 3) from dual connect by level <= 999;

999 rows created.

SQL>
SQL> insert into t2
  2  select 1000000+rownum, mod(rownum, 3) from dual connect by level <= 999;

999 rows created.

SQL> commit;

Commit complete.

SQL>

可以看到2个表的staleness已经变成need compile,且物化视图日志表里面,也与了日志的记录:

SQL> select mview_name,staleness,on_query_computation from user_mviews;

MVIEW_NAME                               STALENESS           O
---------------------------------------- ------------------- -
MV_OLD                                   NEEDS_COMPILE       N
MV_NEW                                   NEEDS_COMPILE       Y

SQL>
SQL> select count(*) from MLOG$_T1;

  COUNT(*)
----------
       999

SQL> select count(*) from MLOG$_T2;

  COUNT(*)
----------
       999

SQL>

我们来见证一下奇迹的时刻。我们先重复上面第一个查询,可以看到,由于数据stale,且没有set query_rewrite_integrity=stale_tolerated,传统mv没有进行query write。

SQL> select  y as y_new_parse1, count(*) from t1
  2  group by y;

Y_NEW_PARSE1   COUNT(*)
------------ ----------
           1     100333
           6     100000
           2     100333
           4     100000
           5     100000
           8     100000
           3     100000
           7     100000
           9     100000
           0     100333

10 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 136660032

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |    10 |    30 |   515   (4)| 00:00:01 |
|   1 |  HASH GROUP BY     |      |    10 |    30 |   515   (4)| 00:00:01 |
|   2 |   TABLE ACCESS FULL| T1   |  1000K|  2929K|   498   (1)| 00:00:01 |
---------------------------------------------------------------------------


Statistics
----------------------------------------------------------
       1975  recursive calls
         30  db block gets
       4167  consistent gets
       1786  physical reads
       5440  redo size
        754  bytes sent via SQL*Net to client
        608  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
        131  sorts (memory)
          0  sorts (disk)
         10  rows processed

SQL>
SQL>

我们看到,real time mv,进行了query rewrite,且查到的数据是最新实时数据!

SQL> select  y as y_new_parse1, count(*) from t2
  2  group by y;

Y_NEW_PARSE1   COUNT(*)
------------ ----------
           6     100000
           4     100000
           5     100000
           8     100000
           3     100000
           7     100000
           9     100000
           1     100333
           2     100333
           0     100333

10 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 542978159

------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                |    12 |   312 |    22  (14)| 00:00:01 |
|   1 |  VIEW                               |                |    12 |   312 |    22  (14)| 00:00:01 |
|   2 |   UNION-ALL                         |                |       |       |            |          |
|*  3 |    VIEW                             | VW_FOJ_0       |    10 |   290 |     9  (12)| 00:00:01 |
|*  4 |     HASH JOIN FULL OUTER            |                |    10 |   240 |     9  (12)| 00:00:01 |
|   5 |      VIEW                           |                |     1 |     7 |     6  (17)| 00:00:01 |
|   6 |       HASH GROUP BY                 |                |     1 |    22 |     6  (17)| 00:00:01 |
|*  7 |        TABLE ACCESS FULL            | MLOG$_T2       |   999 | 21978 |     5   (0)| 00:00:01 |
|   8 |      VIEW                           |                |    10 |   170 |     3   (0)| 00:00:01 |
|   9 |       MAT_VIEW ACCESS FULL          | MV_NEW         |    10 |    60 |     3   (0)| 00:00:01 |
|  10 |    VIEW                             |                |     2 |    52 |    13  (16)| 00:00:01 |
|  11 |     UNION-ALL                       |                |       |       |            |          |
|* 12 |      FILTER                         |                |       |       |            |          |
|  13 |       NESTED LOOPS OUTER            |                |     1 |    32 |     6  (17)| 00:00:01 |
|  14 |        VIEW                         |                |     1 |    26 |     6  (17)| 00:00:01 |
|* 15 |         FILTER                      |                |       |       |            |          |
|  16 |          HASH GROUP BY              |                |     1 |    22 |     6  (17)| 00:00:01 |
|* 17 |           TABLE ACCESS FULL         | MLOG$_T2       |   999 | 21978 |     5   (0)| 00:00:01 |
|* 18 |        INDEX UNIQUE SCAN            | I_SNAP$_MV_NEW |     1 |     6 |     0   (0)| 00:00:01 |
|  19 |      NESTED LOOPS                   |                |     1 |    35 |     7  (15)| 00:00:01 |
|  20 |       VIEW                          |                |     1 |    29 |     6  (17)| 00:00:01 |
|  21 |        HASH GROUP BY                |                |     1 |    22 |     6  (17)| 00:00:01 |
|* 22 |         TABLE ACCESS FULL           | MLOG$_T2       |   999 | 21978 |     5   (0)| 00:00:01 |
|* 23 |       MAT_VIEW ACCESS BY INDEX ROWID| MV_NEW         |     1 |     6 |     1   (0)| 00:00:01 |
|* 24 |        INDEX UNIQUE SCAN            | I_SNAP$_MV_NEW |     1 |       |     0   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   3 - filter("AV$0"."OJ_MARK" IS NULL)
   4 - access(SYS_OP_MAP_NONNULL("SNA$0"."Y")=SYS_OP_MAP_NONNULL("AV$0"."GB0"))
   7 - filter("MAS$"."SNAPTIME$$">TO_DATE(' 2017-07-12 14:35:01', 'syyyy-mm-dd hh24:mi:ss'))
  12 - filter(CASE  WHEN ROWID IS NOT NULL THEN 1 ELSE NULL END  IS NULL)
  15 - filter(SUM(1)>0)
  17 - filter("MAS$"."SNAPTIME$$">TO_DATE(' 2017-07-12 14:35:01', 'syyyy-mm-dd hh24:mi:ss'))
  18 - access("MV_NEW"."SYS_NC00003$"(+)=SYS_OP_MAP_NONNULL("AV$0"."GB0"))
  22 - filter("MAS$"."SNAPTIME$$">TO_DATE(' 2017-07-12 14:35:01', 'syyyy-mm-dd hh24:mi:ss'))
  23 - filter("MV_NEW"."C1"+"AV$0"."D0">0)
  24 - access(SYS_OP_MAP_NONNULL("Y")=SYS_OP_MAP_NONNULL("AV$0"."GB0"))

Note
-----
   - dynamic statistics used: dynamic sampling (level=2)
   - this is an adaptive plan


Statistics
----------------------------------------------------------
        906  recursive calls
         64  db block gets
       1232  consistent gets
         14  physical reads
      10548  redo size
        744  bytes sent via SQL*Net to client
        608  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
         64  sorts (memory)
          0  sorts (disk)
         10  rows processed

SQL>

我们看到,在查t2的时候,优化器会根据成本决定是否使用query rewrite。
我们的这个例子中CBO选择使用query rewrite。可以看到query rewrite到物化视图之后,不是取的是过期的物化视图的值,而是最新的值。结合执行计划,可以看到,是结合了stale的物化视图,再union all和hash join outer了物化视图日志。得到了最新的结果。

可以看到,使用的物化视图日志是”MAS$”.”SNAPTIME$$”>TO_DATE(‘ 2017-07-12 14:35:01’, ‘syyyy-mm-dd hh24:mi:ss’)之后的。

对比直接从table取值,到利用real time物化视图取值,consistent get从4167变成了1232。

注意我们的mv log还是没有被刷新的。还是需要去定期的job刷新:

SQL> select count(*) from MLOG$_T1;

  COUNT(*)
----------
       999

SQL> select count(*) from MLOG$_T2;

  COUNT(*)
----------
       999

SQL>

另外再提一下,有个/*+ fresh_mv */的hint,可以直接查询real time mv的实时结果:

SQL> select * from mv_new;

         Y         C1
---------- ----------
         1     100000
         6     100000
         2     100000
         4     100000
         5     100000
         8     100000
         3     100000
         7     100000
         9     100000
         0     100000

10 rows selected.

SQL>
SQL> select /*+ fresh_mv */* from mv_new;

         Y         C1
---------- ----------
         6     100000
         4     100000
         5     100000
         8     100000
         3     100000
         7     100000
         9     100000
         1     100333
         2     100333
         0     100333

10 rows selected.

综上,Real time mv利用原来的已经stale的物化视图,结合mv log,通过计算后,帮你获取实时的数据。你即能获得实时数据,又不必那么频繁的刷新mv。

参考:
https://blogs.oracle.com/sql/12-things-developers-will-love-about-oracle-database-12c-release-2#real-time-mv
https://blog.dbi-services.com/12cr2-real-time-materialized-view-on-query-computation/
https://uhesse.com/2017/01/05/real-time-materialized-views-in-oracle-12c/
https://docs.oracle.com/database/122/SQLRF/CREATE-MATERIALIZED-VIEW.htm#SQLRF01302

Viewing all 61 articles
Browse latest View live