Technology Blog Posts by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Sawa_Ito
Product and Topic Expert
Product and Topic Expert
0 Likes
587

このブログは、2022 年 11 月 17 日に SAP ジャパン公式ブログに掲載されたものを SAP ジャパン公式ブログ閉鎖に伴い転載したものです。




このブログは、markmumy が執筆したブログ「How to Capture Historical Database and DBSpace Sizes in SAP HANA Cloud, data lake and SAP IQ(2021 年 11 月 19 日)の抄訳です。最新の情報は、SAP Community の最新ブログマニュアルを参照してください。

 






 

最初に、このブログとコードは、SAP HANA Cloud, data lake (クラウドIQ) とSAP IQ(オンプレミスIQ)のどちらにも適用することができます。

SAP IQ の多くの利用ケースでは、お客様は長期のデータベースサイズや dbspace サイズなどの SAP IQ の情報を把握するためにカスタムで書かれたスクリプトと様々な job を用意しています。

また、SAP BW や SAP BW/4HANA の SAP Near Line Storage (NLS) や SAP ERP の SAP Information Lifecycle Management (ILM) など特定の SAP アプリケーションでは、リプレースされたフロントエンド機能が存在しており、その機能は失われています。

しかしながら、SAP HANA Cloud, data lake にはまだ継続的にデータベースや dbspace サイズを取得する機能がまだありません。

このイベントは、どちらの利用ケースでも利用できるよう書かれています。

毎日、夜中に1 回データベース情報を取得する簡単なイベント(下に記載したコード)を作成した。これは、お客様の業務やレポーティングのニーズに合わせて変更可能です。
このイベントでは、データベースの全体サイズと各メイン dbspace のサイズの両方を取得します。

データベースの全体サイズは、SAP IQ プロシーッジャー sp_iqspaceused (リンク先:SAP IQ 16.1 SP05 マニュアル)を使用して取得することができます。
このプロシージャーのアウトプットは、IQ_SYSTEM_MAIN を含む全メイン dbspace の総計です。このデータは、IQ_DBSize というカタログストア(SYSTEM) 内のテーブルストア内にキャプチャーされます。

各dbspace のサイズを取得するために、プロシージャー sp_iqdbspace (リンク先:SAP IQ 16.1 SP05 マニュアル)を使用しています。このプロシージャーは、軽量のプロシージャーで、システム内の各 dbspace を取得します。
欠点は、使用されているブロックをレポートしないことで、使用率や人が読める合計サイズはレポートします。100 % 正確ではないものの、これらの値を各 dbspace のおおよそのサイズを演算するために使用しています。このプロシージャーの例のアウトプットを参照してください。

 

sp_iqdbspace

DBSpaceName    DBSpaceType Writable Online Usage TotalSize Reserve NumFiles NumRWFiles Stripingon StripeSize BlkTypes                OkToDrop lsname is_dbspace_preallocated

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

IQ_SYSTEM_MAIN MAIN        T        T      21    9.76G     200M           1          1 T          1M         1H,255968F,32D,128M,36B N        (NULL) T

IQ_SYSTEM_TEMP TEMPORARY   T        T      1     9.76G     400M           2          2 T          1M         2H,96F,32A,16I          N        (NULL) T

user_main      MAIN        T        T      7     97.7G     400M           2          2 T          1M         2H,777474A              N        (NULL) T



(3 rows)


 

「user_main」のサイズは、97.7 G で、使用率は 7 (7%) です。Dbspace は、およそ (97.7GB *1024 *1024) * 7%、 7,171,211.264 KB です。正確ではありませんが、システムの計画には十分です。

ポイントは、軽量なプロシージャーに重点を置いており、イベントの SAP IQ システムプロシージャーのリバースエンジニアリングは避けていることです。

最初に、イベントがないことを確認し、SYSTEM テーブルを作成します。

 

drop table if exists IQ_DBSpaceSize;

drop table if exists IQ_DBSize;



create table IQ_DBSpaceSize (

        capture_timestamp datetime

        , dbspace_name varchar(255)

        , dbspace_sizeKB unsigned bigint

) on SYSTEM;



create table IQ_DBSize (

        capture_timestamp datetime

        , database_sizeKB unsigned bigint

        , database_usedKB unsigned bigint

) on SYSTEM;



drop event if exists capture_size;


 

次にイベントを作成します。

 

create event capture_size

    SCHEDULE size_schedule

        START TIME '00:00 AM' EVERY 24 HOURS

    HANDLER

begin

  declare _ServerType char(1);

  declare _ServerCnt unsigned bigint;

  declare _ServerCoordCnt unsigned bigint;



  declare _dbsize unsigned bigint;

  declare _dbused unsigned bigint;



  -- use sp_iqmpxinfo (works in IQ and HDL) to know if this is simplex or the coordination on MPX

  select count(*) into _ServerCnt from sp_iqmpxinfo();

  select count(*) into _ServerCoordCnt from sp_iqmpxinfo()

    where server_name = @@servername and role = 'coordinator';



  if _ServerCnt = 0 then

      set _ServerType = 's';

  elseif _ServerCoordCnt = 1 then

      set _ServerType = 'c';

  else

      set _ServerType = 'o';

  end if;





  if lcase(_ServerType) = 's' or lcase(_ServerType) = 'c'

  then

      call dbo.sp_iqlogtoiqmsg( 'DBSIZE: can run on this server type: '|| _ServerType );



        -- capture dbspace usage

        -- the size is a rough number since it is a reverse of the usage, a percentage,

        -- and the size, which was converted to human readable format.

        -- this was easier than reverse engineering all of sp_iqdbspace.

      insert into IQ_DBSpaceSize

        select

          getdate()

          , dbspacename

          , ( usage / 100 ) * case lower ( right( totalsize, 1 ) )

          when 'k' then replace( lower( totalsize ), 'k','')

          when 'm' then replace( lower( totalsize ), 'm','') * 1024

          when 'g' then replace( lower( totalsize ), 'g','') * 1024 * 1024

          when 't' then replace( lower( totalsize ), 't','') * 1024 * 1024 * 1024

          when 'p' then replace( lower( totalsize ), 'p','') * 1024 * 1024 * 1024 * 1024

          end

          from sp_iqdbspace() where lower( dbspacetype ) = 'main'

            and dbspacename not in (  'hotsql_dbspace' );

          -- exclude any dbspaces you don't want to see in the above line

          -- hotsql_dbspace is an HDL reserved dbspace and shouldn't be captured.



        -- capture overall MAIN STORE (user and system) usage and store that

      call sp_iqspaceused ( _dbsize, _dbused, null, null, null, null, null, null, null, null );

      call dbo.sp_iqlogtoiqmsg( 'DBSIZE: '|| getdate()||' '|| _dbsize||' '|| _dbused );

      insert into IQ_DBSize values( getdate(), _dbsize, _dbused );

      commit;

    return

  else

      call dbo.sp_iqlogtoiqmsg( 'DBSIZE: cannot run on this server of type: '|| _ServerType );

  end if

end;


 

プロシージャーがどのようにデータをテーブルにアウトプットするのか示すために、イベントタイマーを毎分実行するように変更します。

 

SAP IQ 15.1 SP05 では、3 回繰り返すと、このイベントのアウトプットは以下のようになります。

 

select * from IQ_DBSize;

capture_timestamp          database_sizeKB database_usedKB

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

2021-11-19 14:29:50.099509       112640000         8269128

2021-11-19 14:30:00.016558       112640000         8269128

2021-11-19 14:31:00.01503        112640000         8269128



(3 rows)



select * from IQ_DBSpaceSize;

capture_timestamp          dbspace_name   dbspace_sizeKB

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

2021-11-19 14:29:50.087938 IQ_SYSTEM_MAIN        2149161

2021-11-19 14:29:50.087938 user_main             7171211

2021-11-19 14:30:00.007595 IQ_SYSTEM_MAIN        2149161

2021-11-19 14:30:00.007595 user_main             7171211

2021-11-19 14:31:00.005074 IQ_SYSTEM_MAIN        2149161

2021-11-19 14:31:00.005074 user_main             7171211



(6 rows)


 

SAP HANA Cloud, data lake では、同じイベントのアウトプットは以下のようになります。

 

select * from IQ_DBSize;

capture_timestamp          database_sizeKB database_usedKB

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

2021-11-19 14:30:00.54169      96503070720      1971885120

2021-11-19 14:31:00.237194     96503070720      1971879456

2021-11-19 14:32:00.236421     96503070720      1971886752



(3 rows)



select * from IQ_DBSpaceSize;

capture_timestamp          dbspace_name   dbspace_sizeKB

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

2021-11-19 14:30:00.039703 IQ_SYSTEM_MAIN      252544077

2021-11-19 14:30:00.039703 user_main          1906965479

2021-11-19 14:31:00.030404 IQ_SYSTEM_MAIN      252544077

2021-11-19 14:31:00.030404 user_main          1906965479

2021-11-19 14:32:00.032755 IQ_SYSTEM_MAIN      252544077

2021-11-19 14:32:00.032755 user_main          1906965479



(6 rows)


 

 




オリジナルのブログはここまでです。




 

多くのやりとりが、オリジナルのブログのコメント欄で繰り広げられていますので、チェックください。