Job Seekers   Employers
dbapool: Authors | Submissions | Contact Us
   Forgot password? | Sign up
  Home   Discussion Forum   Articles   Interview Questions   FAQs   Scripts   Rewards   Analyzer   White Papers   Blog   Certification   Downloads   Tools
   
Slow Running SQL results in Oracle performance degradation




By R. Wang
Aug 03, 2007

Digg! digg!     Print    email to friend Email to Friend

Note: This article was written for educational purpose only. Please refer to the related vendor documentation for detail.




Download Free Confio Software

Slow Running SQL results in Oracle performance degradation

ChunPei Feng  &  R. Wang 

Environment

Oracle 9iR2 and Unix, production database and standby database

Circumstance

In the morning, routine daily database checking shows that the database has an unusual heavy load. As DBA, definitely, the first checking step is to monitor the top OS processes with command TOP or PRSTAT, which offer an ongoing look at processor activity in real time. In this case, however, a list of the most CPU-intensive processes on the system does not tell us anything special which might particularly cause the database performance degradation.

Next, information fetching about TOP SQL and long-running SQL also fail to figure out the possible reason of this performance problem.

Also, the team of application development confirms that no change has been made at the application level. And, application log doesn¡¯t show exception on heavy jobs and excessive user logon.

According to the information above, it can be concluded that the corrupt database performance is caused by issues relating to the database server.

Steps to diagnose:

1. Check and Compare Historical Statspack Reports

So far, no one is able to tell which job attributes to performance degradation because hundreds of processes, which reside on tens of Unix servers, make DBAs difficult to track process by process. Here, the more feasible action is to recur to Statspack, which provides a great deal of performance information about an Oracle database. By keeping historical Statspack reports, it makes possible to compare current Statspack report to the one in last week. The report, generated at peak period (
9:00AM - 10:00AM), is sampled to compare to one of report created in last week at same period.

 Upon comparison, the instant finding is that CPU time is increased by 1,200 (2341 vs. 1175) seconds. Usually, the significant increase on CPU time very likely attribute to the following two scenarios:

  • More jobs loaded
  • The execution plan of SQLs is changed

  Top 5 Timed Events in Statspack Reports
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~      

  • Current Stataspack Report 

Event

Waits

% Total

    Time(s)  

Ela Time

--------------------------------------------

------------

-----------

--------

CPU time                                                             

 

2,341       

42.60

db file sequential read                          

387,534   

2,255       

41.04

global cache cr request                         

745,170   

231

4.21

log file sync                                         

98,041     

229

4.17

log file parallel write                              

96,264    

158

2.88

  • Statspack Report in Last Week

Event

Waits

% Total

    Time(s)  

Ela Time

--------------------------------------------

------------

-----------

--------

db file sequential read                         

346,851   

1,606       

47.60

CPU time                                                            

 

1,175       

34.83

global cache cr request                        

731,368   

206 

6.10

log file sync                                        

90,556      

91

2.71

db file scattered read                           

37,746     

90

2.66


2. Narrow down by examining SQL Part of Statspack Reports
            
Next, we examine the SQL part of Statspack report and find the following SQL statement (Query 1) is listed at the very beginning of ¡°Buffer Gets part. It tells us that this SQL statement is the consumer of 1161.27 seconds¡¯ CPU Time. In last week¡¯s report, no information about this SQL statement has been reported at the very beginning part.  And, it only took 7.39 seconds to be finished. It¡¯s obvious that this SQL statement must be one of the attributors of performance degradation. 

        SELECT login_id, to_char(gmt_create, 'YYYY-MM-DD HH24:MI:SS')
        from IM_BlackList where black_id = :b1

        Query 1: Query on table IM_BlackList with bind variable

SQL Part of Statspack Report

~~~~~~~~~~~~~~~~~~~~~~~~~~~~      

  • Current Stataspack Report 

Buffer Gets   

Executions

Gets per Exec

%Total    

CPU

Times (s)

Elapsd

Times (s)

Hash Value

------------

-------------

---------------

--------

----------

----------

--------------

17,899,606   

47,667      

375.5            

55.6      

1161.27

1170.22

3481369999

Module: /home/oracle/AlitalkSrv/config/../../AlitalkSrv/
SELECT login_id, to_char(gmt_create, ¡®YYYY-MM-DD HH24:MI:SS¡¯)
from IM_BlackList where black_id = :b1

  • Statspack Report in Last Week

Buffer Gets   

Executions

Gets per Exec

%Total    

CPU

Times (s)

Elapsd

Times (s)

Hash Value

------------

------------

---------------

-------

----------

----------

--------------

107,937        

47,128     

2.3                

0.8        

7.39       

6.94    

3481369999

Module: /home/oracle/AlitalkSrv/config/../../AlitalkSrv/
SELECT login_id, to_char(gmt_create, 'YYYY-MM-DD HH24:MI:SS')
from IM_BlackList where black_id = :b1

Now, our investigation has been significantly narrowed down to single SQL statement. That is

SELECT login_id, to_char(gmt_create, 'YYYY-MM-DD HH24:MI:SS')
from IM_BlackList where black_id = :b1

This is a typical SQL query with binding variable and it should benefit from b-tree index created. But, the statistics show that it seems conduct full table scan rather than using proper index.

The following checking on index of field black_id in table IM_BlackList clearly demonstrates the availability of the index.

SQL> select index_name,column_name from user_ind_columns where table_name = 'IM_BLACKLIST';

IM_BLACKLIST_PK LOGIN_ID
IM_BLACKLIST_PK BLACK_ID
IM_BLACKLIST_LID_IND BLACK_ID

The question now is, how come full table scan replace usage of index for this SQL statement? In order to testify our supposition, we simply execute this SQL statement against production database and it¡¯s clear that full table scan is conducted rather than index access.

3. Go Check Histograms generated by Objects Analyzing

To figure out the problem, we then check histograms on the field of BLACK_ID against standby database. That¡¯s also a comparison practice between production database and standby database. Because the activity of gathering statistics does happen on production database, but not on standby database, we are hoping to find some difference between the histograms on the filed BLACK_ID and then to measure the impact of statistics collecting. We select histograms as criteria because histograms is cost-based optimizer (CBO) feature that allows Oracle to see the possible number of values of a particular column, which is known as data skewing, and histograms can track the number of occurrences of a particular data values when CBO decide on what type of index to use or even whether to use an index.

To gather histograms information against standby database, we run:

SQL> select COLUMN_NAME ,ENDPOINT_NUMBER, ENDPOINT_VALUE ,        from dba_histograms where table_name = 'IM_BLACKLIST' and column_name = 'BLACK_ID';

Query 2:gather histograms information  from dba_hisrograms

Then, we get:

COLUMN_NAME

ENDPOINT_NUMBER

ENDPOINT_VALUE

--------------------

-----------------------

---------------------

BLACK_ID

0

2.5031E+35

BLACK_ID

1

2.5558E+35

BLACK_ID 

2

2.8661E+35

BLACK_ID 

3

5.0579E+35

BLACK_ID 

4

5.0585E+35

BLACK_ID 

5

5.0585E+35

BLACK_ID 

6

5.0589E+35

BLACK_ID 

7

5.0601E+35

BLACK_ID 

8

5.1082E+35

BLACK_ID 

9

5.1119E+35

BLACK_ID 

10

5.1615E+35

BLACK_ID 

11

5.1616E+35

BLACK_ID 

12

5.1628E+35

BLACK_ID 

13

5.1646E+35

BLACK_ID 

14

5.2121E+35

BLACK_ID 

15

5.2133E+35

BLACK_ID 

16

5.2155E+35

BLACK_ID 

17

5.2662E+35

BLACK_ID 

18

5.3169E+35

BLACK_ID 

19

5.3193E+35

BLACK_ID 

20

5.3686E+35

BLACK_ID 

21

5.3719E+35

BLACK_ID 

22

5.4198E+35

BLACK_ID 

23

5.4206E+35

BLACK_ID 

24

5.4214E+35

BLACK_ID 

25

5.4224E+35

BLACK_ID 

26

5.4238E+35

BLACK_ID 

27

5.4246E+35

BLACK_ID

28

5.4743E+35

BLACK_ID 

29

5.5244E+35

BLACK_ID 

30

5.5252E+35

BLACK_ID 

31

5.5252E+35

BLACK_ID 

32

5.5272E+35

BLACK_ID 

33

5.5277E+35

BLACK_ID 

34

5.5285E+35

BLACK_ID 

35

5.5763E+35

BLACK_ID 

36

5.6274E+35

BLACK_ID 

37

5.6291E+35

BLACK_ID

38

5.6291E+35

BLACK_ID 

39

5.6291E+35

BLACK_ID 

40

5.6291E+35

BLACK_ID 

41

5.6305E+35

BLACK_ID 

42

5.6311E+35

BLACK_ID 

43

5.6794E+35

BLACK_ID 

44

5.6810E+35

BLACK_ID 

45

5.6842E+35

BLACK_ID 

46

5.7351E+35

BLACK_ID 

47

5.8359E+35

BLACK_ID 

48

5.8887E+35

BLACK_ID 

49

5.8921E+35

BLACK_ID 

50

5.9430E+35

BLACK_ID 

51

5.9913E+35

BLACK_ID 

52

5.9923E+35

BLACK_ID 

53

5.9923E+35

BLACK_ID 

54

5.9931E+35

BLACK_ID 

55

5.9947E+35

BLACK_ID 

56

5.9959E+35

BLACK_ID 

57

6.0428E+35

BLACK_ID 

58

6.0457E+35

BLACK_ID 

59

6.0477E+35

BLACK_ID

60

6.0479E+35

BLACK_ID  

61

6.1986E+35

BLACK_ID 

62

6.1986E+35

BLACK_ID 

63

6.1994E+35

BLACK_ID 

64

6.2024E+35

BLACK_ID 

65

6.2037E+35

BLACK_ID 

66

6.2521E+35

BLACK_ID 

67

6.2546E+35

BLACK_ID 

68

6.3033E+35

BLACK_ID 

69

6.3053E+35

BLACK_ID 

70

6.3069E+35

BLACK_ID

71

6.3553E+35

BLACK_ID 

72

6.3558E+35

BLACK_ID 

73

6.3562E+35

BLACK_ID 

74

6.3580E+35

BLACK_ID 

75

1.1051E+36

Output 1: Histograms data on standby database

Subsequently, then same command has been executed against production database. The output looks like followings:

COLUMN_NAME

ENDPOINT_NUMBER

ENDPOINT_VALUE

--------------------

-----------------------

---------------------

BLACK_ID

0

1.6715E+35

BLACK_ID

1

2.5558E+35

BLACK_ID 

2

2.7619E+35

BLACK_ID 

3

2.9185E+35

BLACK_ID 

4

5.0579E+35

BLACK_ID 

5

5.0589E+35

BLACK_ID 

6

5.0601E+35

BLACK_ID 

7

5.1100E+35

BLACK_ID 

8

5.1601E+35

BLACK_ID 

9

5.1615E+35

BLACK_ID 

10

5.1624E+35

BLACK_ID 

11

5.1628E+35

BLACK_ID 

12

5.1642E+35

BLACK_ID 

13

5.2121E+35

BLACK_ID 

14

5.2131E+35

BLACK_ID 

15

5.2155E+35

BLACK_ID 

16

5.2676E+35

BLACK_ID 

17

5.3175E+35

BLACK_ID 

18

5.3684E+35

BLACK_ID 

19

5.3727E+35

BLACK_ID 

20

5.4197E+35

BLACK_ID 

21

5.4200E+35

BLACK_ID 

22

5.4217E+35

BLACK_ID 

23

5.4238E+35

BLACK_ID 

24

5.4244E+35

BLACK_ID 

25

5.4755E+35

BLACK_ID 

26

5.5252E+35

BLACK_ID 

27

5.5252E+35

BLACK_ID