PR

Oracle Database Statspackレポートの取得方法

スポンサーリンク
ORACLE

Diagnostics PackライセンスがあればAWRレポートを取得できますが、ライセンスが無い場合はStatspackレポートにて性能を評価します。

Statspackを使うための準備

Statspackインストールスクリプトの場所

spcreate.sql というスクリプトを流すことにより、Statspack取得用のユーザー・オブジェクトが作成されます。

スクリプトは以下の場所に存在します。

[oracle@ol77 ~]$ cd $ORACLE_HOME/rdbms/admin
[oracle@ol77 admin]$ ls -l spcreate.sql
-rw-r--r-- 1 oracle oinstall 1796 May 29  2017 spcreate.sql

Statspackインストールスクリプトの実行

Statspackインストールスクリプトを実行すると、以下を聞かれた後専用のユーザーとオブジェクトが作成されます。

  • PERFSTAT(Statspack取得ユーザ)のパスワード
  • PERFSTATユーザーの表領域
  • PERFSTATユーザの一時表領域

入力箇所は★を付けています。

[oracle@ol77 admin]$ sqlplus / as sysdba @spcreate.sql

SQL*Plus: Release 19.0.0.0.0 - Production on Sun May 23 11:07:23 2021
Version 19.3.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0


Session altered.


Choose the PERFSTAT user's password
-----------------------------------
Not specifying a password will result in the installation FAILING

Enter value for perfstat_password: ★perfstat
perfstat


Choose the Default tablespace for the PERFSTAT user
---------------------------------------------------
Below is the list of online tablespaces in this database which can
store user data.  Specifying the SYSTEM tablespace for the user's
default tablespace will result in the installation FAILING, as
using SYSTEM for performance data is not supported.

Choose the PERFSTAT users's default tablespace.  This is the tablespace
in which the STATSPACK tables and indexes will be created.

TABLESPACE_NAME                CONTENTS
------------------------------ ---------------------
STATSPACK DEFAULT TABLESPACE
----------------------------
SYSAUX                         PERMANENT
*

USERS                          PERMANENT



Pressing  will result in STATSPACK's recommended default
tablespace (identified by *) being used.

Enter value for default_tablespace: ★SYSAUX

Using tablespace SYSAUX as PERFSTAT default tablespace.


Choose the Temporary tablespace for the PERFSTAT user
-----------------------------------------------------
Below is the list of online tablespaces in this database which can
store temporary data (e.g. for sort workareas).  Specifying the SYSTEM
tablespace for the user's temporary tablespace will result in the
installation FAILING, as using SYSTEM for workareas is not supported.

Choose the PERFSTAT user's Temporary tablespace.

TABLESPACE_NAME                CONTENTS              DB DEFAULT TEMP TABLESPACE
------------------------------ --------------------- --------------------------
TEMP                           TEMPORARY             *

Pressing  will result in the database's default Temporary
tablespace (identified by *) being used.

Enter value for temporary_tablespace: ★TEMP

Using tablespace TEMP as PERFSTAT temporary tablespace.


... Creating PERFSTAT user


... Installing required packages


... Creating views


... Granting privileges

<省略>

SQL> set echo off;
Creating Package STATSPACK...

Package created.

No errors.
Creating Package Body STATSPACK...

Package body created.

No errors.

NOTE:
SPCPKG complete. Please check spcpkg.lis for any errors.

Session altered.

SQL> exit

Statspackスナップショットの取得

PERFSTATユーザで接続

[oracle@ol77 admin]$ sqlplus perfstat

SQL*Plus: Release 19.0.0.0.0 - Production on Sun May 23 11:35:44 2021
Version 19.3.0.0.0

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

Enter password:

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL>

Statspackスナップショットの取得レベルを変更

レベルは10までありますが、10はシステム全体に負荷がかかるのでその下の7に設定します。

SQL> execute statspack.modify_statspack_parameter(i_snap_level=> 7);

PL/SQL procedure successfully completed.

Statspackスナップショット取得と確認

スナップショットが取得できているかは、STATS$SNAPSHOT にて確認することができます。

SQL> execute statspack.snap;

SQL> alter session set nls_date_format='YYYY/MM/DD HH24:MI:SS';

Session altered.

SQL> select snap_id, snap_time, snap_level from stats$snapshot order by snap_id;

   SNAP_ID SNAP_TIME           SNAP_LEVEL
---------- ------------------- ----------
         1 2021/05/23 11:40:16          7

ここでOracle Databaseへ負荷を掛け、その後、もう一度スナップショットを取得し、2点間のスナップショットを元にレポートを作成します。

SQL> execute statspack.snap;

PL/SQL procedure successfully completed.

SQL> select snap_id, snap_time, snap_level from stats$snapshot order by snap_id;

   SNAP_ID SNAP_TIME           SNAP_LEVEL
---------- ------------------- ----------
         1 2021/05/23 11:40:16          7
        11 2021/05/23 13:31:32          7

Statspackレポートの作成

Statspackレポート作成スクリプトの場所

spreport.sql というスクリプトを流すことにより、Statspackレポートを作成することができます。
スクリプトは以下の場所に存在します。

[oracle@ol77 ~]$ cd $ORACLE_HOME/rdbms/admin
[oracle@ol77 admin]$ ls -l spreport.sql
-rw-r--r-- 1 oracle oinstall 1577 May 29  2017 spreport.sql

Statspackレポートの作成

2点間のスナップショットを元にStatspackレポートを作成します。

Statspackレポート作成スクリプトを実行すると、以下を聞かれた後にレポートが出力されます。

  • 開始時点のSnap Id(begin_snap)
  • 終了時点のSnap Id(end_snap)
  • Statspackレポートの出力ファイル名

入力箇所は★を付けています。

[oracle@ol77 admin]$ sqlplus perfstat @spreport.sql

SQL*Plus: Release 19.0.0.0.0 - Production on Sun May 23 13:35:30 2021
Version 19.3.0.0.0

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

Enter password:
Last Successful login time: Sun May 23 2021 11:35:47 +09:00

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0


Current Instance
~~~~~~~~~~~~~~~~

   DB Id    DB Name      Inst Num Instance
----------- ------------ -------- ------------
 3176943179 HOGE                1 hoge



Instances in this Statspack schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   DB Id    Inst Num DB Name      Instance     Host
----------- -------- ------------ ------------ ------------
 3176943179        1 HOGE         hoge         ol77

Using 3176943179 for database Id
Using          1 for instance number


Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed.  Pressing  without
specifying a number lists all completed snapshots.



Listing all Completed Snapshots

                                                       Snap
Instance     DB Name        Snap Id   Snap Started    Level Comment
------------ ------------ --------- ----------------- ----- --------------------
hoge         HOGE                 1 23 May 2021 11:40     7
                                 11 23 May 2021 13:31     7



Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: ★1
Begin Snapshot Id specified: 1

Enter value for end_snap: ★11
End   Snapshot Id specified: 11



Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is sp_1_11.  To use this name,
press  to continue, otherwise enter an alternative.

Enter value for report_name: ★/tmp/spreport.txt

Using the report name /tmp/spreport.txt

STATSPACK report for

Database    DB Id    Instance     Inst Num  Startup Time   Release     RAC
~~~~~~~~ ----------- ------------ -------- --------------- ----------- ---
          3176943179 hoge                1 23-May-21 11:06 19.0.0.0.0  NO

Host Name             Platform                CPUs Cores Sockets   Memory (G)
~~~~ ---------------- ---------------------- ----- ----- ------- ------------
     ol77             Linux x86 64-bit           4     4       1         15.4

<省略>

remote_login_passwordfile     EXCLUSIVE
undo_tablespace               UNDOTBS1
          -------------------------------------------------------------

End of Report ( /tmp/spreport.txt )

Statspackレポートの確認

今回の例では /tmp/spreport.txt に出力したので、テキストとしてStatspackレポートが出力されています。

[oracle@ol77 admin]$ more /tmp/spreport.txt

STATSPACK report for

Database    DB Id    Instance     Inst Num  Startup Time   Release     RAC
~~~~~~~~ ----------- ------------ -------- --------------- ----------- ---
          3176943179 hoge                1 23-May-21 11:06 19.0.0.0.0  NO

Host Name             Platform                CPUs Cores Sockets   Memory (G)
~~~~ ---------------- ---------------------- ----- ----- ------- ------------
     ol77             Linux x86 64-bit           4     4       1         15.4

Snapshot       Snap Id     Snap Time      Sessions Curs/Sess Comment
~~~~~~~~    ---------- ------------------ -------- --------- ------------------
Begin Snap:          1 23-May-21 11:40:16       50       1.5
  End Snap:         11 23-May-21 13:31:32       49       1.9
   Elapsed:     111.27 (mins) Av Act Sess:       0.0
   DB time:       0.12 (mins)      DB CPU:       0.11 (mins)

Cache Sizes            Begin        End
~~~~~~~~~~~       ---------- ----------
    Buffer Cache:       100M        96M   Std Block Size:         8K
     Shared Pool:       232M                  Log Buffer:     7,128K

Load Profile              Per Second    Per Transaction    Per Exec    Per Call
~~~~~~~~~~~~      ------------------  ----------------- ----------- -----------
      DB time(s):                0.0                0.0        0.00        0.01

コメント

  1. […] ・statspackのインストールと使い方(12c)・statspackのインストール手順・STATSPACKのインストールと使用・StatsPackを使ってみる(その1)導入編・Oracle Database Statspackレポートの取得方法・Oracle Statspack のセットアップ(RDS)・サポートのトップエンジニアが語るワンランク上のStatspack活用術!・RDS for OracleのStatspackでデフォルト表領域を任意の場所へ変更する・「SQL 実行計画」と「実行統計情報」の取得方法 […]