Skip to content

Oracle - 13. page

对于在云数据库 (OCI) 创建时 (虚拟机还没有生成) 的问题,只提供第一步的信息就可以。

 

对于其他的问题,需要提供步骤一到步骤三的所有信息。

1. 从 OCI 的控制台搜集数据库(OCI) 的相关信息:

a. Cloud Account Name
b. Region:
Region will be available on the top corner of every page in OCI console
c. Availability Domain:
Availability Domain can be found next to the database system name in OCI console
d. Tenancy ID:
In OCI console, Navigate to Administration –> Tenancy Details, Look OCID under the Tenancy Information
e. Compartment OCID:
In OCI console, Navigate to Identity –> Compartments. Look OCID under the compartment name
f. Database system OCID:
In OCI console, Navigate to Menu –> Bare Metal, VM, and Exadata, Look for Database System OCID near the database system name
g. Database OCID:
In OCI console, navigate to Database System page and click on the problematic database system. In the Database System page, look for the Database OCID under the “Databases”

 

2. 如果数据库 (OCI) 对应的虚拟机可以访问,那么用 root 用户登陆虚拟机,搜集基础架构、代理、数据库和任务详细信息:

基础架构详细信息

 

# sudo -s

# curl -s http://169.254.169.254/opc/v1/instance/ | egrep -v “user_data|ssh_authorized_keys|timeCreated”

代理详细信息

# sudo -s

# rpm -qa | grep dcs
# initctl status initdcsagent
# initctl status initdcsadmin

集群、数据库详细信息

# sudo -s

# Replace the grid home and issue below command
# /u01/app/12.2.0.1/grid/bin/crsctl check crs

# sudo su – oracle

# sqlplus / as sysdba

— Run below SQLs in SQLPLUS prompt

select status from v$instance;
select name, open_mode from v$database;
select banner from v$version where banner like ‘Oracle Database%’;

— if Multitenant

show pdbs;

任务详细信息

# sudo -s

# /opt/oracle/dcs/bin/dbcli describe-component > /tmp/dcs_job_details.log
# /opt/oracle/dcs/bin/dbcli list-databases >> /tmp/dcs_job_details.log
# /opt/oracle/dcs/bin/dbcli list-jobs >> /tmp/dcs_job_details.log
# /opt/oracle/dcs/bin/dbcli describe-job -i <faild_job_ID> >> /tmp/dcs_job_details.log

上传 /tmp/dcs_job_details.log

3. 使用 opc 用户登陆到数据库 (OCI) 对应的虚拟机,并执行如下命令:

# sudo /opt/oracle/dcs/bin/diagcollector.py

Sample Output:
=============[oci@ludatou ~]$ sudo /opt/oracle/dcs/bin/diagcollector.py
Log files collected to :/tmp/dcsdiag/diagLogs-1526004897.zip

Logs are being collected to:
/ludatou/ocidiag/diagLogs-4758698722.zip

该命令会生成 /tmp/dcsdiag/diagLogs-xxxxx.zip 的文件。

用如下命令上传这个文件到 SR:
Note 1547088.2 – How to upload large files to Oracle Support

# curl -T <path_and_filename>” -u “<userID>” https://transport.oracle.com/upload/issue/<sr-number>/

For example:
curl -T /ludatou/ocidiag/diagLogs-4758698722.zip -u ********@oracle.com https://transport.oracle.com/upload/issue/

Oracle cloud 上的云资源诊断信息收集

有一些用户的海外系统上到oracle的云,在海外oracle云上的备份设置以及相关信息查询加入到了工作常态,下面是描述如何在oracle database cloud上检查数据库的备份信息

 

1. 使用’opc’用户登录到主机

2. 切换到’root’用户并使用下面的任意一个命令:

a) 要检查备份的进度,使用下面的bkup_api的命令:
$ /var/opt/oracle/bkup_api/bkup_api bkup_status 

b) 使用bkup_api命令列出可用的备份

$ /var/opt/oracle/bkup_api/bkup_api recover_list

-或者-

c) 使用dbaascli命令列出正常的备份

$ dbaascli orec –args -list

-或者-

d) 使用dbaascli命令来列出长期保留的备份

$dbaascli orec –args -keep -list

3. 检查备份产生的obkup.log

/home/oracle/bkup/<SID>/log/obkup.log

4. 切换至’oracle’用户并连接到RMAN

RMAN target /RMAN> list backup;

-或者-

RMAN> list backup summary;

5. 关于处理了多少bytes的数据,备份持续的时间等更多细节,可以以SYS登陆数据库并检查动态视图V$RMAN_BACKUP_JOB_DETAILS

如何在Oracle Database Cloud上检查数据库备份的信息

optimizer_dynamic_sampling 参数与sql语句执行时的动态采样相关,这关系到sql的执行计划的准确与否。一般在表的统计信息收集准确的情况下执行计划(实际执行的)可以准确的,但有些情况下不一定,比如数据分布不均(要收集柱状图信息)、或使用了临时表(应用程序处于某种目的:如为了提高应用性能使用临时表存放事务的中间结果集或者将子查询作为一个临时表),都有可能执行计划不准确,最终导致sql语句在实际执行计划的产生严重的效率。

下面是收集关于这个参数的一些资料,同时在ORACLE10D的Oracle Database Documentation Library中也有记录(Oracle Database Documentation Library–>Books—>Reference–> Initialization Parameters—>OPTIMIZER_DYNAMIC_SAMPLING,Oracle Database Documentation Library–>Performance Tuning Guide–>14.5.6 Estimating Statistics with Dynamic Sampling–>Dynamic Sampling Levels

这个参数的default value=1(9i) (10g :optimizer_dynamic_sampling parameter=2) 

 

1. Dynamic Sampling (动态采样)

The purpose of dynamic sampling is to improve server performance by determining more accurate selectivity and cardinality estimates.
More accurate selectivity and cardinality estimates allow the optimizer to produce better performing plans.
(动态采样的目的是为了通过更精确的seletivity值cardinality值来提高服务器性能,更精确的seletivity值cardinality值可以让优化器提供更好的执行计划。)

Estimate single-table predicate selectivities when collected statistics cannot be used or are likely to lead to significant errors in estimation.
Estimate table cardinality for tables without statistics or for tables whose statistics are too out of date to trust.
(当没有使用statistics统计信息或者可能导致评估错误的时候,可以提前预估出来单表的selectivities值。
当表没有收集统计信息时,或者表的统计信息过期的时候,可以估算出表的cardinality值。)

2. How Dynamic Sampling Works(动态采样如何工作)

The primary performance attribute is compile time.
Oracle determines at compile time whether a query would benefit from dynamic sampling.
If so, a recursive SQL statement is issued to scan a small random sample of the table’s blocks,
and to apply the relevant single table predicates to estimate predicate selectivities.
The sample cardinality can also be used, in some cases, to estimate table cardinality.
(主要的性能影响被归因于编译时间。ORACLE来判断在编译的时候,动态采样是否对查询是否有意。如果是,那么sql语句会发起
相对应表的快的小部分随机采样,然后应用相关的单表去前瞻性预估相应的selectivities值。

3. When to Use Dynamic Sampling(什么时候使用动态采样)

(1) A better plan can be found using dynamic sampling.
(2) The sampling time is a small fraction of total execution time for the query.
(3) The query will be executed many times.

(1) 使用动态采样可以更好的生成执行计划
(2) 动态采样的时间占查询执行的时间一小部分
(3) 查询语句将被执行许多次

4. How to Use Dynamic Sampling to Improve Performance
   (如何使用动态采样提高性能)

 Level 0: dynamic sampling will not be done.
(动态采样不会收集)

 Level 1: (default value) dynamic sampling will be performed if all of the following conditions are true:
(1) There is more than one table in the query.
(2) Some table has not been analyzed and has no indexes.
(3) The optimizer determines that a relatively expensive table scan would be required for this unanalyzed table.
(默认值,如果如下的条件全部满足的时候,那么动态采样将被执行
(1) 有超过一个表的查询
(2) 一些表没有被分析,而且没有index
(3) 优化器认为这个没有被分析的表会消耗相当昂贵的表扫描资源)

 Level 2: Apply dynamic sampling to all unanalyzed tables.
The number of blocks sampled is the default number of dynamic sampling blocks.
(针对所有没有被分析的表应用动态采样,采样blocks的数量是默认的动态采样的数量)

Level 3: Apply dynamic sampling to all tables that meet Level 2 criteria, plus all tables for which standard selectivity estimation used a guess for some predicate
that is a potential dynamic sampling predicate.
The number of blocks sampled is the default number of dynamic sampling blocks.
(根据level2的标准,应用动态采样到所有的表,以及为一些标准selectivity值的表使用一些采样预测,采样blocks的数量是默认的动态采样的数量)

Level 4: Apply dynamic sampling to all tables that meet Level 3 criteria, plus all tables that have single-table predicates that reference 2 or more columns.
The number of blocks sampled is the default number of dynamic sampling blocks.
(根据level3的标准,应用动态采样到所有的表,以及一些大于2列的单表的预测。采样blocks的数量是默认的动态采样的数量)

Level 5: Apply dynamic sampling to all tables that meet the Level 4 criteria using 2 times the default number of dynamic sampling blocks.
(根据level4的标准,应用动态采样到所有的表,并且采样blocks的数量是默认的动态采样的数量的2倍)

 Level 6: Apply dynamic sampling to all tables that meet the Level 5 criteria using 4 times the default number of dynamic sampling blocks.
(根据level5的标准,应用动态采样到所有的表,并且采样blocks的数量是默认的动态采样的数量的4倍)

Level 7: Apply dynamic sampling to all tables that meet the Level 6 criteria using 8 times the default number of dynamic sampling blocks.
(根据level6的标准,应用动态采样到所有的表,并且采样blocks的数量是默认的动态采样的数量的8倍)

Level 8: Apply dynamic sampling to all tables that meet the Level 7 criteria using 32 times the default number of dynamic sampling blocks.
(根据level7的标准,应用动态采样到所有的表,并且采样blocks的数量是默认的动态采样的数量的32倍)

Level 9: Apply dynamic sampling to all tables that meet the Level 8 criteria using 128 times the default number of dynamic sampling blocks.
(根据level8的标准,应用动态采样到所有的表,并且采样blocks的数量是默认的动态采样的数量的128倍)

 Level 10: Apply dynamic sampling to all tables that meet the Level 9 criteria using all blocks in the table.
(根据level9的标准,应用动态采样到所有的表,并且采样表中所有的blocks)

Increasing the value of the parameter results in more aggressive application of dynamic sampling, in terms of both the type of tables sampled (analyzed or unanalyzed) and the amount of I/O spent on sampling.
Dynamic sampling is repeatable if no rows have been inserted, deleted, or updated in the table being sampled.
(增加这个参数的值,从表的采样和I/O消耗的角度来说,动态采样将导致更多资源的征用。
在被采样的表中,即使没有记录被insert, deleted, update,采样的操作仍会被重复。)

举例如下:

SQL> select a,count(*) from t_zft group by a;

A   COUNT(*)
———- ———-
1     100000
2          1
SQL> set linesize 2000
SQL> show parameter dyna

NAME                                 TYPE                   VALUE
———————————— ———————- ——————————
optimizer_dynamic_sampling           integer                2                       –10g默认的方式
SQL> alter system set optimizer_dynamic_sampling=0;                     –改为0

系统已更改。

SQL> alter system flush shared_pool;

系统已更改。

SQL> set autotrace trace exp
SQL> select * from t_zft where a=1;

执行计划
———————————————————-
Plan hash value: 1844927459

—————————————————————————————–
| Id  | Operation                   | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
—————————————————————————————–
|   0 | SELECT STATEMENT            |           | 27409 |    52M|   231   (0)| 00:00:03 |
|   1 |  TABLE ACCESS BY INDEX ROWID| T_ZFT     | 27409 |    52M|   231   (0)| 00:00:03 |
|*  2 |   INDEX RANGE SCAN          | I_T_ZFT_A | 10964 |       |    97   (0)| 00:00:02 |
—————————————————————————————–

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

2 – access(“A”=1)

SQL> select * from t_zft where a=2;

执行计划
———————————————————-
Plan hash value: 1844927459

—————————————————————————————–
| Id  | Operation                   | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
—————————————————————————————–
|   0 | SELECT STATEMENT            |           | 27409 |    52M|   231   (0)| 00:00:03 |
|   1 |  TABLE ACCESS BY INDEX ROWID| T_ZFT     | 27409 |    52M|   231   (0)| 00:00:03 |
|*  2 |   INDEX RANGE SCAN          | I_T_ZFT_A | 10964 |       |    97   (0)| 00:00:02 |
—————————————————————————————–

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

2 – access(“A”=2)

—-默认情况下都是用索引扫描
SQL> alter system set optimizer_dynamic_sampling=2;             –重新改为2

系统已更改。

SQL> alter system flush shared_pool;

系统已更改。

SQL> select * from t_zft where a=1;

执行计划
———————————————————-
Plan hash value: 1060505680

—————————————————————————
| Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
—————————————————————————
|   0 | SELECT STATEMENT  |       |   102K|   196M|  9116   (1)| 00:01:50 |
|*  1 |  TABLE ACCESS FULL| T_ZFT |   102K|   196M|  9116   (1)| 00:01:50 |
—————————————————————————

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

1 – filter(“A”=1)

Note
—–
– dynamic sampling used for this statement
SQL>  select * from t_zft where a=2;

执行计划
———————————————————-
Plan hash value: 1844927459

—————————————————————————————–
| Id  | Operation                   | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
—————————————————————————————–
|   0 | SELECT STATEMENT            |           |     1 |  2015 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| T_ZFT     |     1 |  2015 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | I_T_ZFT_A |     1 |       |     1   (0)| 00:00:01 |
—————————————————————————————–

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

2 – access(“A”=2)

Note
—–
– dynamic sampling used for this statement

因为oracle采样了默认的采样,级别为2
Level 2:    Sample all unanalyzed tables referenced in teh query using default sampling amounts(small sample)
也就是说你实际上已经使用了直方图的信息,只是这个信息是执行的时

探讨oracle optimizer_dynamic_sampling 参数与执行计划的关系

在升级之前习惯备份整个Oracle程序目录,包括数据文件,这里介绍一种备份oracle主要程序文件(Oracle_home)的方式,可以使用多种方式备份 Oracle home 。你可以使用任何工具来压缩Oracle Home,比如zip,tar,cpio。

备份之前建议关闭源库上的任何数据库,监听进程,从而可以对Oracle Home软件进行冷备份,当然也可以不停机。 如果是在安装补丁或者补丁集,Readme中的步骤会要求关闭,这种情况下,建议关闭数据库和监听再执行ORACLE_HOME冷备份。在Oracle进程活跃状态下执行备份仍然是有效的,因为任何加载static binaries 或者libraries的进程都不应当持有write lock。备份必须由Oracle安装用户或者root用户执行。目的是保证文件的属主和权限正确。

如下是使用tar命令的例子。

1. 关闭数据库,监听或者任何其它关联到你在备份的ORACLE_HOME的进程

2. cd 到ORACLE_HOME所在的目录。例如:

cd /u01/app/oracle/product/11.2

3. 备份 ORACLE_HOME 。

tar -pcvf /u01/app/oracle/backup/oracle_home_bkup.tar db1

在上述命令中, ORACLE_HOME 是 /u01/app/oracle/product/11.2/db1 而备份目录是 /u01/app/oracle/backup/

如下是一个还原ORACLE_HOME的例子:

1. 关闭数据库,监听或者任何其它关联到你在还原的ORACLE_HOME的进程

2. 进入 ORACLE_HOME 所在的目录。例如:

cd /u01/app/oracle/product/11.2

3. 重命名或者移动 ORACLE_HOME 例如:

mv db1 db1_bkup

4. 还原ORACLE_HOME 例如:

tar -pxvf /u01/app/oracle/backup/oracle_home_bkup.tar

在备份前检查是否有足够的空间备份,Oracle_Home 所注册的Central Inventory建议一起与ORACLE_HOME同时备份,从而保证一致性。

 

在升级或者打补丁之前备份ORACLE_HOME目录

DBMS_JOB和DBMS_SCHEDULER之间存在内部事务机制,将对DBMS_JOB_MAP表中的重复名称进行内部检查。并且此检查可能导致进程挂起。通

过在一个会话中使用DBMS_JOB创建一个作业,但是不提交,可以非常轻松地重现此内容。然后在第二个会话中创建另一个作业,该作业将挂起。引起其他进程的阻塞

 

id:2645984.1 –在SYS.SCHEDULER $ _DBMSJOB_MAP上删除引起行锁,将补丁30835853应用于Oracle 19c主目录,目前19c linux平台的RU并没有解决此问题,可以提单独的SR申请补丁

 

 

To BottomTo Bottom

In this Document

Symptoms
Changes
Cause
Solution
References

APPLIES TO:

Oracle Database – Enterprise Edition – Version 19.4.0.0.0 and later
Information in this document applies to any platform.
Upgrade done from 12.1.0.2 to 19c

New dictionary table SYS.SCHEDULER$_DBMSJOB_MAP is created in 19c.

SYMPTOMS

Application jobs are slow with “enq: TX – row lock contention” event on the below recursive SQL:

DELETE FROM SYS.SCHEDULER$_DBMSJOB_MAP WHERE JOB_NAME NOT IN (SELECT NAME FROM SYS.OBJ$ WHERE NAME LIKE ‘DBMS_JOB$_%’)

CHANGES

Upgrade to 19c

CAUSE

The issue is due to the below bug:

Bug 30835853 – DBMS_JOB.SUBMIT PROCEDURE BEHAVIOR CHANGE IN 19C

After upgrade database to 19c, the new dictionary table SYS.SCHEDULER$_DBMSJOB_MAP is introduced.

Application jobs may be slow due to below recursive SQL statement causing “enq: TX – row lock contention”.

DELETE FROM SYS.SCHEDULER$_DBMSJOB_MAP WHERE JOB_NAME NOT IN (SELECT NAME FROM SYS.OBJ$ WHERE NAME LIKE ‘DBMS_JOB$_%’)

SOLUTION

Apply the Patch 30835853 for your version

Oracle 19.3.0 升级到 19.7.0需要DBMS_JOB额外补丁以解决hang的问题