Oracle数据库数据恢复、性能优化

找回密码
注册
搜索
热搜: 活动 交友 discuz
发新帖

87

积分

0

好友

5

主题
1#
发表于 2013-11-18 16:40:57 | 查看: 6417| 回复: 8
本帖最后由 anbob 于 2013-11-22 09:22 编辑

有个库版本11204,发现很严重的parse问题
  1. Load Profile

  2. Per Second        Per Transaction        Per Exec        Per Call
  3. DB Time(s):         0.7         0.0         0.00         0.00
  4. DB CPU(s):         0.4         0.0         0.00         0.00
  5. Redo size (bytes):         469,220.8         1,272.4                  
  6. Logical read (blocks):         5,820.7         15.8                  
  7. Block changes:         3,166.9         8.6                  
  8. Physical read (blocks):         0.0         0.0                  
  9. Physical write (blocks):         27.1         0.1                  
  10. Read IO requests:         0.0         0.0                  
  11. Write IO requests:         5.3         0.0                  
  12. Read IO (MB):         0.0         0.0                  
  13. Write IO (MB):         0.2         0.0                  
  14. User calls:         2,131.7         5.8                  
  15. Parses (SQL):         841.7         2.3                  
  16. Hard parses (SQL):         0.0         0.0                  
  17. SQL Work Area (MB):         0.2         0.0                  
  18. Logons:         0.6         0.0                  
  19. Executes (SQL):         1,207.4         3.3                  
  20. Rollbacks:         0.0         0.0                  
  21. Transactions:         368.8                           
  22. Instance Efficiency Percentages (Target 100%)

  23. Buffer Nowait %:         100.00        Redo NoWait %:         100.00
  24. Buffer Hit %:         100.00        In-memory Sort %:         100.00
  25. Library Hit %:         100.25        Soft Parse %:         99.99
  26. Execute to Parse %:         30.28        Latch Hit %:         99.85
  27. Parse CPU to Parse Elapsd %:         14.60        % Non-Parse CPU:         98.95
  28. Top 10 Foreground Events by Total Wait Time

  29. Event        Waits        Total Wait Time (sec)        Wait Avg(ms)        % DB time        Wait Class
  30. log file sync        1,180,970        1630.1        1        67.8        Commit
  31. DB CPU                 1239.6                 51.5         
  32. library cache: mutex X        8,437        125.1        15        5.2        Concurrency
  33. latch: shared pool        713        45.9        64        1.9        Concurrency
  34. SQL*Net message to client        4,597,267        13.9        0        .6        Network
  35. latch: enqueue hash chains        188        3.1        17        .1        Other
  36. cursor: pin S        693        2.9        4        .1        Concurrency
  37. latch free        144        1.6        11        .1        Other
  38. cursor: pin S wait on X        20        .2        12        .0        Concurrency
  39. cursor: mutex S        2        .2        114        .0        Concurrency
复制代码
后来做了个测试,怀疑11204 没用 softer soft parse ,session_cached_cursor不为0
  1. --####################### 11203

  2. sys@ANBOB>alter system flush shared_pool;
  3. System altered.

  4. sys@ANBOB>select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'select /*weejar11203*/%';
  5. no rows selected

  6. sys@ANBOB>conn weejar/weejar
  7. Connected.

  8. weejar@ANBOB>select /*anbob11203*/ count(*) from test;
  9.             COUNT(*)
  10. --------------------
  11.                    1
  12. -- 执行同样sql 5次

  13. weejar@ANBOB>select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'select /*anbob11203*/%';

  14.      LOADED_VERSIONS        OPEN_VERSIONS           EXECUTIONS                LOADS          PARSE_CALLS
  15. -------------------- -------------------- -------------------- -------------------- --------------------
  16.                    1                    1                    5                    1                    3

  17. weejar@ANBOB>show parameter session_cached

  18. NAME                                 TYPE        VALUE
  19. ------------------------------------ ----------- ------------------------------
  20. session_cached_cursors               integer     50
  21. weejar@ANBOB>select * from v$version;

  22. BANNER
  23. --------------------------------------------------------------------------------
  24. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  25. PL/SQL Release 11.2.0.3.0 - Production
  26. CORE    11.2.0.3.0      Production
  27. TNS for Linux: Version 11.2.0.3.0 - Production
  28. NLSRTL Version 11.2.0.3.0 - Production

  29. ############  11204
  30. sys@ORA11204>conn weejar;
  31. Enter password:
  32. Connected.
  33. weejar@ORA11204>select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'select /*anbob11204*/%';
  34. no rows selected

  35. weejar@ORA11204>select /*anbob11204*/ count(*) from test1;
  36.             COUNT(*)
  37. --------------------
  38.                    0
  39. -- 同样执行5次


  40. weejar@ORA11204>select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'select /*anbob11204*/%';

  41.      LOADED_VERSIONS        OPEN_VERSIONS           EXECUTIONS                LOADS          PARSE_CALLS
  42. -------------------- -------------------- -------------------- -------------------- --------------------
  43.                    1                    1                    5                    1                    5

  44. sys@ORA11204>show parameter session_cache

  45. NAME                                 TYPE        VALUE
  46. ------------------------------------ ----------- ------------------------------
  47. session_cached_cursors               integer     50
  48. sys@ORA11204>select * from v$version;

  49. BANNER
  50. --------------------------------------------------------------------------------
  51. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  52. PL/SQL Release 11.2.0.4.0 - Production
  53. CORE    11.2.0.4.0      Production
  54. TNS for Linux: Version 11.2.0.4.0 - Production
  55. NLSRTL Version 11.2.0.4.0 - Production
复制代码
问题:
11204 解析有问题还是v$sql.parse_calls显示有问题,有人知道么?

thanks.
追求卓越
2#
发表于 2013-11-18 23:14:12
这个问题延迟到明天白天回答

回复 只看该作者 道具 举报

3#
发表于 2013-11-19 12:07:33
本帖最后由 anbob 于 2013-11-19 12:19 编辑

同样的方法 在12C 一样
  1. sys@ORA12C>select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'select /*weejar12101*/%';

  2.      LOADED_VERSIONS        OPEN_VERSIONS           EXECUTIONS                LOADS          PARSE_CALLS
  3. -------------------- -------------------- -------------------- -------------------- --------------------
  4.                    1                    1                    5                    1                    5

  5. sys@ORA12C>select * from v$version;

  6. BANNER                                                                                         CON_ID
  7. -------------------------------------------------------------------------------- --------------------
  8. Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production                        0
  9. PL/SQL Release 12.1.0.1.0 - Production                                                              0
  10. CORE    12.1.0.1.0      Production                                                                          0
  11. TNS for Linux: Version 12.1.0.1.0 - Production                                                      0
  12. NLSRTL Version 12.1.0.1.0 - Production                                                              0
复制代码
10204,10205 也是5:5

回复 只看该作者 道具 举报

4#
发表于 2013-11-19 15:09:38
11.2.0.4 确实有该问题
  1. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  2. With the Partitioning, OLAP, Data Mining and Real Application Testing options

  3. SQL> conn maclean/oracle
  4. Connected.
  5. SQL>
  6. SQL>
  7. SQL>
  8. SQL> create table testparse(t1 int);

  9. Table created.

  10. SQL>
  11. SQL> select /* macleanparse */ 1 from testeparse;
  12. select /* macleanparse */ 1 from testeparse
  13.                                  *
  14. ERROR at line 1:
  15. ORA-00942: table or view does not exist


  16. SQL> select /* macleanparse */ 1 from testparse;

  17. no rows selected

  18. SQL>
  19. SQL>    select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'select /*macleanparse*/%';

  20. no rows selected

  21. SQL> select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'select /* macleanparse */%';

  22. LOADED_VERSIONS OPEN_VERSIONS EXECUTIONS      LOADS PARSE_CALLS
  23. --------------- ------------- ---------- ---------- -----------
  24.               1             0          1          1           1

  25. SQL> select /* macleanparse */ 1 from testparse;

  26. no rows selected

  27. SQL> /

  28. no rows selected

  29. SQL> /

  30. no rows selected

  31. SQL> /

  32. no rows selected

  33. SQL> /

  34. no rows selected

  35. SQL> select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'select /* macleanparse */%';

  36. LOADED_VERSIONS OPEN_VERSIONS EXECUTIONS      LOADS PARSE_CALLS
  37. --------------- ------------- ---------- ---------- -----------
  38.               1             1          6          1           6

  39. SQL> select /* macleanparse */ 1 from testparse;

  40. no rows selected

  41. SQL> /

  42. no rows selected

  43. SQL> /

  44. no rows selected

  45. SQL> /

  46. no rows selected

  47. SQL> /

  48. no rows selected

  49. SQL> /

  50. no rows selected

  51. SQL> select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'select /* macleanparse */%';

  52. LOADED_VERSIONS OPEN_VERSIONS EXECUTIONS      LOADS PARSE_CALLS
  53. --------------- ------------- ---------- ---------- -----------
  54.               1             1         12          1          12

  55. SQL> select vs.name,vm.value from v$mystat vm,v$statname vs where  vm.statistic#=vs.statistic# and name like '%parse count%';

  56. NAME                                                                  VALUE
  57. ---------------------------------------------------------------- ----------
  58. parse count (total)                                                     167
  59. parse count (hard)                                                       34
  60. parse count (failures)                                                    1
  61. parse count (describe)                                                    0

  62. SQL> select /* macleanparse */ 1 from testparse;

  63. no rows selected

  64. SQL> /

  65. no rows selected

  66. SQL> /

  67. no rows selected

  68. SQL> /

  69. no rows selected

  70. SQL> /

  71. no rows selected

  72. SQL> select vs.name,vm.value from v$mystat vm,v$statname vs where  vm.statistic#=vs.statistic# and name like '%parse count%';

  73. NAME                                                                  VALUE
  74. ---------------------------------------------------------------- ----------
  75. parse count (total)                                                     173
  76. parse count (hard)                                                       34
  77. parse count (failures)                                                    1
  78. parse count (describe)                                                    0


  79. SQL> alter session set events 'immediate trace name errorstack level 3';

  80. Session altered.
复制代码

回复 只看该作者 道具 举报

5#
发表于 2013-11-19 15:09:56
怀疑与SQLPLUS这个客户端有关, 需要尝试jdbc是否会导致该问题

回复 只看该作者 道具 举报

6#
发表于 2013-11-20 13:46:15
Maclean Liu(刘相兵 发表于 2013-11-19 15:09
怀疑与SQLPLUS这个客户端有关, 需要尝试jdbc是否会导致该问题

ML, thanks for your reply. take a sample

JAVA CODE
  1. import java.sql.*;
  2. public class parsetest{

  3. public static Connection getConnection() throws Exception {
  4.     String driver = "oracle.jdbc.driver.OracleDriver";
  5.     String url = "jdbc:oracle:thin:@192.168.168.231:1521:ora11204";
  6.     String username = "weejar";
  7.     String password = "weejar";

  8.     Class.forName(driver);
  9.     Connection conn = DriverManager.getConnection(url, username, password);
  10.     return conn;
  11.   }

  12.   public static int countRows(Connection conn, String tableName) throws SQLException {
  13.     // select the number of rows in the table
  14.     Statement stmt = null;
  15.     ResultSet rs = null;
  16.     int rowCount = -1;
  17.     try {
  18.       stmt = conn.createStatement();
  19.           for (int i =0; i<10; i++){
  20.             rs = stmt.executeQuery("SELECT /*ojdbc_parse*/ COUNT(*) FROM " + tableName);
  21.           }
  22.       
  23.       // get the number of rows from the result set
  24.       rs.next();
  25.       rowCount = rs.getInt(1);
  26.     } finally {
  27.       rs.close();
  28.       stmt.close();
  29.     }

  30.     return rowCount;
  31.   }


  32. public static void main(String[] args) {
  33.     Connection conn = null;
  34.     try {
  35.       conn = getConnection();
  36.       String tableName = "test1";
  37.       System.out.println("tableName=" + tableName);
  38.       System.out.println("conn=" + conn);
  39.           
  40.           System.out.println("rowCount=" + countRows(conn, tableName));
  41.     } catch (Exception e) {
  42.       e.printStackTrace();
  43.       System.exit(1);
  44.     } finally {
  45.       // release database resources
  46.       try {
  47.         conn.close();
  48.       } catch (SQLException e) {
  49.         e.printStackTrace();
  50.       }
  51.     }
  52.   }
  53. }
复制代码
D:\>set CLASSPATH=E:\oracle\product\11.2.0\client_1\jdbc\lib\ojdbc6.jar;%CLASSPATH%

D:\>set CLASSPATH
CLASSPATH=E:\oracle\product\11.2.0\client_1\jdbc\lib\ojdbc6.jar;.;D:\jdk1_7\jre\lib\rt.jar;D:\jdk1_7\lib;D:\jdk1_7\lib\tools.jar

D:\>javac parsetest.java

D:\>java parsetest
tableName=test1
conn=oracle.jdbc.driver.T4CConnection@2f0e07
rowCount=0

  1. weejar@ORA11204>select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'SELECT /*ojdbc_parse*/%';

  2.      LOADED_VERSIONS        OPEN_VERSIONS           EXECUTIONS                LOADS          PARSE_CALLS
  3. -------------------- -------------------- -------------------- -------------------- --------------------
  4.                    1                    0                   10                    1                   10
复制代码
修改JAVA CODE 在11203 上执行
  1. sys@ANBOB>select LOADED_VERSIONS ,OPEN_VERSIONS ,EXECUTIONS,LOADS,PARSE_CALLS from v$sql where sql_text like 'SELECT /*ojdbc_parse*/%';

  2.      LOADED_VERSIONS        OPEN_VERSIONS           EXECUTIONS                LOADS          PARSE_CALLS
  3. -------------------- -------------------- -------------------- -------------------- --------------------
  4.                    1                    0                   10                    1                    3
复制代码
这算bug? ML 可有参数可以降11204 的parse方法为11203么?

回复 只看该作者 道具 举报

7#
发表于 2013-11-20 14:18:27
Steve Adams said
If an SQL statement is parsed in a cursor and then executed repeatedly without closing the cursor or parsing another statement in it, then the V$SQLAREA statistics will show many more EXECUTIONS than PARSE_CALLS for that statement. If statements are never reused, then EXECUTIONS and PARSE_CALLS are normally identical. Note that the count of parse calls includes hits in the session cursor cache, which don't even touch the shared cursor. This is done by updating the statistics when the shared cursor is unpinned after execution.

回复 只看该作者 道具 举报

8#
发表于 2013-11-20 16:21:52
11.2.0.4 +session_cached_cursors               integer     50

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0      Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

SQL> conn maclean/oracle
Connected.
SQL> select /* macleanparse */ 1 from testparse;

no rows selected

SQL> select distinct sid from v$mystat;

       SID
----------
       145

SQL> SELECT cach.value cache_hits, prs.value all_parses,round((cach.value/prs.value)*100,2) as "%found in cache"
  2  FROM v$sesstat cach, v$sesstat prs, v$statname nm1, v$statname nm2
  3  WHERE cach.statistic# = nm1.statistic#
  4  AND nm1.name = 'session cursor cache hits'
  5  AND prs.statistic#=nm2.statistic#
  6  AND nm2.name= 'parse count (total)'
  7  AND cach.sid= 145 and prs.sid= cach.sid;

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
        20         45           44.44

SQL>
SQL> select /* macleanparse */ 1 from testparse;

no rows selected

SQL>
SQL> /

no rows selected

SQL> /

no rows selected

SQL> /

no rows selected


在session B 中对应每一步 做查询

SQL> SELECT cach.value cache_hits, prs.value all_parses,round((cach.value/prs.value)*100,2) as "%found in cache"
  2  FROM v$sesstat cach, v$sesstat prs, v$statname nm1, v$statname nm2
  3  WHERE cach.statistic# = nm1.statistic#
  4  AND nm1.name = 'session cursor cache hits'
  5  AND prs.statistic#=nm2.statistic#
  6  AND nm2.name= 'parse count (total)'
  7  AND cach.sid= 145 and prs.sid= cach.sid;

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
        21         46           45.65

SQL> /

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
        22         47           46.81

SQL> /

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
        23         48           47.92

SQL> /

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
        24         49           48.98

对应可以看到session cursor cache hits的增长

回复 只看该作者 道具 举报

9#
发表于 2013-11-20 16:24:17
11.2.0.4 + session_cached_cursors=0
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

session A sid 143

SQL> conn maclean/oracle
Connected.
SQL>
SQL> select /* macleanparse */ 1 from testparse;

no rows selected

SQL> select distinct sid from v$mystat;

       SID
----------
       143

SQL> select /* macleanparse */ 1 from testparse;

no rows selected

SQL> /

no rows selected

SQL> /

no rows selected

SQL> /

no rows selected

SQL> /

no rows selected

SQL> /

no rows selected

SQL> /

no rows selected


session B 对应session A每一个步骤查询

SQL> SELECT cach.value cache_hits, prs.value all_parses,round((cach.value/prs.value)*100,2) as "%found in cache"
  2  FROM v$sesstat cach, v$sesstat prs, v$statname nm1, v$statname nm2
  3  WHERE cach.statistic# = nm1.statistic#
  4  AND nm1.name = 'session cursor cache hits'
  5  AND prs.statistic#=nm2.statistic#
  6  AND nm2.name= 'parse count (total)'
  7  AND cach.sid= 143 and prs.sid= cach.sid;

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
         0        261               0

SQL> /

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
         0        262               0

SQL> /

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
         0        268               0

SQL> /

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
         0        268               0

SQL> /

CACHE_HITS ALL_PARSES %found in cache
---------- ---------- ---------------
         0        268               0


看来仅仅是 PARSE_CALLS这个指标发生了变化

回复 只看该作者 道具 举报

您需要登录后才可以回帖 登录 | 注册

QQ|手机版|Archiver|Oracle数据库数据恢复、性能优化

GMT+8, 2024-5-19 12:00 , Processed in 0.053187 second(s), 20 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部
TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569