Oracle statspack無法收集快照,及解決辦法

chenoracle發表於2014-08-30


Oracle statspack無法收集快照,及解決辦法


SQL> show user


USER is "PERFSTAT"

 

一: 手動收集一次快照,產生如下錯誤

SQL> execute statspack.snap  

BEGIN statspack.snap; END;

 

*

ERROR at line 1:

ORA-01401 : inserted value too large for column

ORA-06512 : at "PERFSTAT.STATSPACK", line 1148

ORA-06512: at "PERFSTAT.STATSPACK", line 2134

ORA-06512: at "PERFSTAT.STATSPACK", line 72

ORA-06512: at line 1

 

查資料:可以刪除重新建立 statspack

1 備份 perfstat 使用者下所有表

-bash-3.2$ exp perfstat/perfstat file='/home/oracle/perfstat_tab/perf.dmp' owner=perfstat

 

-bash-3.2$ cd perfstat_tab/

-bash-3.2$ ll -rth

總計 4.9M

-rw-r--r-- 1 oracle oinstall 4.9M 08-30 09:47 perf.dmp

 

2 刪除使用者及使用者下所有表

SQL> drop user perfstat cascade;

 

User dropped.

 

3 執行指令碼建立使用者,表,指定表空間,產生如下錯誤

SQL> @$ORACLE_HOME/rdbms/admin/spcreate.sql

 

ERROR at line 1:

ORA-00955 : name is already used by an existing object --- 說明 statspack 資訊沒有完全解除安裝

 

4 刪除收集資訊的表空間

SQL> select file_name,tablespace_name,bytes/1024/1024||'M' M from dba_data_files;

 

/home/oracle/oradata/orcl/statspack01.dbf     STATSPACK  100M

 

RMAN> run{     

2> allocate channel d1 type disk format '/home/oracle/perfstat_tab/tbs_%s_%p_%T.sp';

3> backup tablespace statspack filesperset 3;

4> }

 

SQL> drop tablespace statspack including contents and datafiles;

 

Tablespace dropped.

 

5 重新建立表空間

SQL> create tablespace statspack_chen datafile '/home/oracle/oradata/orcl/statspack_chen01.dbf' size 150M;

 

Tablespace created.

 

6 重新執行指令碼,仍然顯示同樣的錯誤

SQL> @$ORACLE_HOME/rdbms/admin/spcreate.sql

ERROR at line 1:

ORA-00955: name is already used by an existing object

 

7 執行指令碼 spdrop.sql ,刪除資訊

SQL> @$ORACLE_HOME/rdbms/admin/spdrop.sql

 

8 在重新執行 spcreate.sql 指令碼,建立使用者,表,指定表空間

SQL> @$ORACLE_HOME/rdbms/admin/spcreate.sql

 

SQL> show user

USER is "PERFSTAT"

 

SQL> select * from session_privs;

 

PRIVILEGE

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

CREATE SESSION

ALTER SESSION

CREATE TABLE

CREATE PUBLIC SYNONYM

DROP PUBLIC SYNONYM

CREATE SEQUENCE

CREATE PROCEDURE

 

7 rows selected.

 

SQL> select username,default_tablespace from dba_users;

 

USERNAME                       DEFAULT_TABLESPACE

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

SYS                            SYSTEM

SYSTEM                         SYSTEM

OUTLN                          SYSTEM

DBSNMP                         SYSTEM

CARD                           APP_DATA

PERFSTAT                       STATSPACK_CHEN

 

6 rows selected.

 

重新收集快照,仍然報相同的錯誤 --- 崩潰了

SQL>  execute statspack.snap

BEGIN statspack.snap; END;

 

*

ERROR at line 1:

ORA-01401 : inserted value too large for column

ORA-06512 : at "PERFSTAT.STATSPACK", line 1148

ORA-06512: at "PERFSTAT.STATSPACK", line 2134

ORA-06512: at "PERFSTAT.STATSPACK", line 72

ORA-06512: at line 1

 

SQL>  select 1 - (phy.value / (cur.value + con.value)) "HIT RATIO"

  from v$sysstat cur, v$sysstat con, v$sysstat phy

 where cur.name = 'db block gets'

  and con.name = 'consistent gets'

  and phy.name = 'physical reads';

  2    3    4    5 

 HIT RATIO

----------

 .72201289

 

 

查詢資料

資料內容:Run statspack.snap report error ora-1401

fact:  Oracle Server - Enterprise Edition 8.1.7.2
fact: PL/SQL
fact: SYSPKG - SYSTEM PACKAGES
symptom: Error running STATSPACK report
symptom: Execute STATSPACK.SNAP fails
symptom: ORA-01401 inserted value too large for column
cause:
ORA-1401 WHEN STATPACK.SNAP IS EXECUTED

If a sql statement contains Multibyte characters, and STATSPACK.SNAP needs to
store information about the sql statement, an ORA-01401 may occur.

fix:


is fixed in 8.1.7.3, 9.0.1.2 and 9.0.2.

Workaround:

Edit $ORACLE_HOME/rdbms/admin/spcpkg.sql, and change the one occurance  of 
"substr" to "substrb".
Rerun spcpkg.sql to apply changes.

==========================================================================

----------- ,又是 bug

 

修改指令碼 spcpkg.sql

-bash-3.2$ vim spcpkg.sql

select l_snap_id

            , p_dbid

            , p_instance_number

            , substr (sql_text,1,31)

 

select l_snap_id

            , p_dbid

            , p_instance_number

            , substrb (sql_text,1,31)

 

原因: 這個問題只會出現在多位的字符集 ,

substr 會將多位的字元 , 當作一個 byte.

substrb 則會當作多個 byte.

因位 statpack 會將   top 10 sql 31 個字 存入 table ,

若在 SQL 的前 31 個字有中文,則會有此錯誤。

 

再次執行指令碼,刪除 重建

SQL> @$ORACLE_HOME/rdbms/admin/spdrop.sql

 

SQL> @$ORACLE_HOME/rdbms/admin/spcreate.sql

 

收集快照 ------- 成功!!!

SQL> execute statspack.snap

 

PL/SQL procedure successfully completed.

 

SQL> select snap_id,to_char(snap_time,'yyyy-mm-dd hh24:mi:ss') time from stats$snapshot;

 

   SNAP_ID TIME

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

         1 2014-08-30 10:55:48

 

SQL> execute statspack.snap

 

PL/SQL procedure successfully completed.

 

SQL>  select snap_id,to_char(snap_time,'yyyy-mm-dd hh24:mi:ss') time from stats$snapshot;

 

   SNAP_ID TIME

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

         1 2014-08-30 10:55:48

         2 2014-08-30 11:04:47

 

SQL> @$ORACLE_HOME/rdbms/admin/spreport.sql

1

2

20140830chen_report.txt

 

-bash-3.2$ cd perfstat_tab/

-bash-3.2$ ls

20140830chen_report.txt  spcpkg.lis  spcusr.lis  spdusr.lis

perf.dmp                 spctab.lis  spdtab.lis  tbs_45_1_20140830.sp

 

 

-bash-3.2$ vim 20140830chen_report.txt

STATSPACK report for

 

DB Name         DB Id    Instance     Inst Num Release     Cluster Host

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

ORCL          1278871612 orcl                1 9.0.1.0.0   NO      server1

 

            Snap Id     Snap Time      Sessions Curs/Sess Comment

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

Begin Snap:       1 30-Aug-14 10:55:48       48       5.9

  End Snap:       2 30-Aug-14 11:04:47       48       6.3

   Elapsed:                8.98 (mins)

 

Cache Sizes (end)

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

               Buffer Cache:        92M      Std Block Size:         4K

           Shared Pool Size:       128M          Log Buffer:       400K

 

 

 

 

Instance Efficiency Percentages (Target 100%)

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

            Buffer Nowait %:  100.00       Redo NoWait %:  100.00

            Buffer  Hit   %:   99.15    In-memory Sort %:   99.61

            Library Hit   %:   99.33        Soft Parse %:   97.63

         Execute to Parse %:   21.12         Latch Hit %:  100.00

 

…………………………………….

 

   歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!!

Oracle statspack無法收集快照,及解決辦法

Oracle statspack無法收集快照,及解決辦法



 

 

 

 

 

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29785807/viewspace-1260544/,如需轉載,請註明出處,否則將追究法律責任。

相關文章