はじめに

こんにちは。Oracle Databaseの検証チームです。
今回は、Oracle Database 23aiの新機能であるSQL HISTORY(SQL履歴)をご紹介いたします。

過去のOracle Database 23aiの記事はこちら

SQL履歴とは

23aiで追加された新機能で、SQLの履歴および詳細な情報をセッション単位でレポートする機能です。

DDL文、DML文および問合せ文を監視し、表示されたエラー・メッセージも確認できます。
ただし、バックグラウンドで発行されたSQL文、SYSスキーマのSQL文、再帰的SQL文など一部例外は存在します。
SQL履歴の情報はV$SQL_HISTORYを参照することで確認できます。

検証

※本検証では、Oracle VM VirtualBoxにOracle Database 23ai Free Developer をインストールした環境を使用しています。

さっそく確認してみましょう

発行されたSQLの情報はv$sql_historyを参照することで確認できます。

SQL> SELECT * from v$sql_history ;

行が選択されていません

現在は何の情報も記載されていません。
この機能はデフォルトでは無効化されているため、「sql_history_enabled」というパラメータを有効化する必要があります。

SQL> col name format a15
SQL> col value format a10
SQL> col isdefault format a10
SQL> select name, value, default_value, isdefault from v$parameter where name = 'sql_history_enabled';

NAME VALUE DEFAULT_VALUE ISDEFAULT 
______________________ ________ ________________ ____________ 
sql_history_enabled FALSE FALSE TRUE

有効化

alter system文を使ってパラメータを有効化します。

SQL> alter system set sql_history_enabled=true scope=both;

Systemが変更されました。

SQL> 
SQL> select name, value, default_value, isdefault from v$parameter where name = 'sql_history_enabled';

NAME VALUE DEFAULT_VALUE ISDEFAULT 
______________________ ________ ________________ ____________ 
sql_history_enabled TRUE FALSE TRUE

VALUEの値がTRUEに変更できたので、早速情報が記載されるようになりました。

SQL> SELECT * from v$sql_history ;

KEY SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS IO_INTERCONNECT_BYTES PHYSICAL_READ_REQUESTS PHYSICAL_READ_BYTES PHYSICAL_WRITE_REQUESTS PHYSICAL_WRITE_BYTES PLSQL_EXEC_TIME JAVA_EXEC_TIME CLUSTER_WAIT_TIME CONCURRENCY_WAIT_TIME APPLICATION_WAIT_TIME USER_IO_WAIT_TIME IO_CELL_UNCOMPRESSED_BYTES IO_CELL_OFFLOAD_ELIGIBLE_BYTES SQL_TEXT PLAN_HASH_VALUE SQL_EXEC_ID SQL_EXEC_START LAST_ACTIVE_TIME SESSION_USER# CURRENT_USER# CHILD_NUMBER SID SESSION_SERIAL# MODULE_HASH ACTION_HASH SERVICE_HASH IS_FULL_SQLTEXT ERROR_SIGNALLED ERROR_NUMBER ERROR_FACILITY STATEMENT_TYPE IS_PARALLEL CON_ID 
_______________ ________________ _______________ ___________ ______________ ________________________ _________________________ ______________________ __________________________ _______________________ __________________ _________________ ____________________ ________________________ ________________________ ____________________ _____________________________ _________________________________ _______________________________________________________________________________________________________ __________________ ______________ _________________ ___________________ ________________ ________________ _______________ ______ __________________ ______________ ______________ _______________ __________________ __________________ _______________ _________________ _________________ ______________ _________ 
188978561026 9b5j1zscxzg7q 14585 8124 55 32768 4 32768 0 0 0 0 0 0 0 4230 0 0 select GSMADMIN_INTERNAL.GETSHARDINGMODE from dual 1388734953 16777216 25-01-17 25-01-17 141 141 0 44 64740 2615955429 0 3032363729 Y N 0 QUERY N 3 
188978561282 awuwhfhgh5qz5 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777216 25-01-17 25-01-17 141 141 0 44 64740 2615955429 0 3032363729 Y N 0 QUERY N 3 
206158430210 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777218 25-01-17 25-01-17 141 141 0 48 25309 2615955429 0 3032363729 Y N 0 QUERY N 3 
210453397506 awuwhfhgh5qz5 16 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777220 25-01-17 25-01-17 141 141 0 49 54942 2615955429 0 3032363729 Y N 0 QUERY N 3 
214748364802 awuwhfhgh5qz5 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777221 25-01-17 25-01-17 141 141 0 50 32181 2615955429 0 3032363729 Y N 0 QUERY N 3 
219043332098 awuwhfhgh5qz5 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777225 25-01-17 25-01-17 141 141 0 51 27407 2615955429 0 3032363729 Y N 0 QUERY N 3 
906238100994 f8dzanrnkxys4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container=FREEPDB1 0 0 25-01-17 9 9 65535 211 10869 588800815 0 3032363729 Y N 0 OTHER N 3 
906238101250 gxxu53y9u3d2t 1239 449 0 0 0 0 0 0 65 0 0 0 0 0 0 0 DECLARE 
CHECKONE VARCHAR2(1000):=NULL; 
BEGIN 
BEGIN 
CHECKONE:=substr(SYS_CONTEXT ('USERENV', 0 16777216 25-01-17 25-01-17 9 9 0 211 10869 588800815 0 3032363729 N N 0 PLSQL N 3 
919123001346 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777217 25-01-17 25-01-17 141 141 0 214 13495 2615955429 0 3032363729 Y N 0 QUERY N 3 
923417968642 awuwhfhgh5qz5 24 23 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777219 25-01-17 25-01-17 141 141 0 215 21205 2615955429 0 3032363729 Y N 0 QUERY N 3 
927712935938 awuwhfhgh5qz5 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777222 25-01-17 25-01-17 141 141 0 216 58373 2615955429 0 3032363729 Y N 0 QUERY N 3 
932007903234 awuwhfhgh5qz5 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777223 25-01-17 25-01-17 141 141 0 217 49176 2615955429 0 3032363729 Y N 0 QUERY N 3 
936302870530 awuwhfhgh5qz5 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777224 25-01-17 25-01-17 141 141 0 218 44182 2615955429 0 3032363729 Y N 0 QUERY N 3

13行が選択されました。

SQL_TEXTの欄を確認すると、ユーザー側で発行していないものも記録されていることが確認できます。
ちなみに、SQL_TEXTにはSQL文の最初の100文字しか表示されません。
SQL文がすべて表示されているかどうかはIS_FULL_SQLTEXTの項目で確認できます。すべて表示されている場合は”Y”、そうでなければ”N”となります。

次に、任意のSQL文を発行して記録されることを確認してみましょう。

SQL> select sysdate;
SYSDATE 
___________ 
25-01-17

SQL> SELECT * from v$sql_history ;

KEY SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS IO_INTERCONNECT_BYTES PHYSICAL_READ_REQUESTS PHYSICAL_READ_BYTES PHYSICAL_WRITE_REQUESTS PHYSICAL_WRITE_BYTES PLSQL_EXEC_TIME JAVA_EXEC_TIME CLUSTER_WAIT_TIME CONCURRENCY_WAIT_TIME APPLICATION_WAIT_TIME USER_IO_WAIT_TIME IO_CELL_UNCOMPRESSED_BYTES IO_CELL_OFFLOAD_ELIGIBLE_BYTES SQL_TEXT PLAN_HASH_VALUE SQL_EXEC_ID SQL_EXEC_START LAST_ACTIVE_TIME SESSION_USER# CURRENT_USER# CHILD_NUMBER SID SESSION_SERIAL# MODULE_HASH ACTION_HASH SERVICE_HASH IS_FULL_SQLTEXT ERROR_SIGNALLED ERROR_NUMBER ERROR_FACILITY STATEMENT_TYPE IS_PARALLEL CON_ID 
_______________ ________________ _______________ ___________ ______________ ________________________ _________________________ ______________________ __________________________ _______________________ __________________ _________________ ____________________ ________________________ ________________________ ____________________ _____________________________ _________________________________ _______________________________________________________________________________________________________ __________________ ______________ _________________ ___________________ ________________ ________________ _______________ ______ __________________ ______________ ______________ _______________ __________________ __________________ _______________ _________________ _________________ ______________ _________ 
188978561026 9b5j1zscxzg7q 14585 8124 55 32768 4 32768 0 0 0 0 0 0 0 4230 0 0 select GSMADMIN_INTERNAL.GETSHARDINGMODE from dual 1388734953 16777216 25-01-17 25-01-17 141 141 0 44 64740 2615955429 0 3032363729 Y N 0 QUERY N 3 
188978561282 awuwhfhgh5qz5 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777216 25-01-17 25-01-17 141 141 0 44 64740 2615955429 0 3032363729 Y N 0 QUERY N 3 
206158430210 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777218 25-01-17 25-01-17 141 141 0 48 25309 2615955429 0 3032363729 Y N 0 QUERY N 3 
210453397506 awuwhfhgh5qz5 16 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777220 25-01-17 25-01-17 141 141 0 49 54942 2615955429 0 3032363729 Y N 0 QUERY N 3 
214748364802 awuwhfhgh5qz5 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777221 25-01-17 25-01-17 141 141 0 50 32181 2615955429 0 3032363729 Y N 0 QUERY N 3 
219043332098 awuwhfhgh5qz5 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777225 25-01-17 25-01-17 141 141 0 51 27407 2615955429 0 3032363729 Y N 0 QUERY N 3 
906238100994 f8dzanrnkxys4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container=FREEPDB1 0 0 25-01-17 9 9 65535 211 10869 588800815 0 3032363729 Y N 0 OTHER N 3 
906238101250 gxxu53y9u3d2t 1239 449 0 0 0 0 0 0 65 0 0 0 0 0 0 0 DECLARE 
CHECKONE VARCHAR2(1000):=NULL; 
BEGIN 
BEGIN 
CHECKONE:=substr(SYS_CONTEXT ('USERENV', 0 16777216 25-01-17 25-01-17 9 9 0 211 10869 588800815 0 3032363729 N N 0 PLSQL N 3 
906238101506 4wa87vtt127jg 387 388 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT * from v$sql_history 1076639199 16777216 25-01-17 25-01-17 9 9 0 211 10869 588800815 0 3032363729 Y N 0 QUERY N 3 
906238101762 bw2c1d6sqyjpy 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sysdate 1388734953 16777216 25-01-17 25-01-17 9 9 0 211 10869 588800815 0 3032363729 Y N 0 QUERY N 3 
919123001346 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777217 25-01-17 25-01-17 141 141 0 214 13495 2615955429 0 3032363729 Y N 0 QUERY N 3 
923417968642 awuwhfhgh5qz5 24 23 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777219 25-01-17 25-01-17 141 141 0 215 21205 2615955429 0 3032363729 Y N 0 QUERY N 3 
927712935938 awuwhfhgh5qz5 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777222 25-01-17 25-01-17 141 141 0 216 58373 2615955429 0 3032363729 Y N 0 QUERY N 3 
932007903234 awuwhfhgh5qz5 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777223 25-01-17 25-01-17 141 141 0 217 49176 2615955429 0 3032363729 Y N 0 QUERY N 3 
936302870530 awuwhfhgh5qz5 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777224 25-01-17 25-01-17 141 141 0 218 44182 2615955429 0 3032363729 Y N 0 QUERY N 3

15行が選択されました。

ユーザー側で発行したSQLも確認できました。

セッションが切れると

セッションを切ってもう一度見てみましょう

SQL> SELECT * from v$sql_history ;

KEY SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS IO_INTERCONNECT_BYTES PHYSICAL_READ_REQUESTS PHYSICAL_READ_BYTES PHYSICAL_WRITE_REQUESTS PHYSICAL_WRITE_BYTES PLSQL_EXEC_TIME JAVA_EXEC_TIME CLUSTER_WAIT_TIME CONCURRENCY_WAIT_TIME APPLICATION_WAIT_TIME USER_IO_WAIT_TIME IO_CELL_UNCOMPRESSED_BYTES IO_CELL_OFFLOAD_ELIGIBLE_BYTES SQL_TEXT PLAN_HASH_VALUE SQL_EXEC_ID SQL_EXEC_START LAST_ACTIVE_TIME SESSION_USER# CURRENT_USER# CHILD_NUMBER SID SESSION_SERIAL# MODULE_HASH ACTION_HASH SERVICE_HASH IS_FULL_SQLTEXT ERROR_SIGNALLED ERROR_NUMBER ERROR_FACILITY STATEMENT_TYPE IS_PARALLEL CON_ID 
_______________ ________________ _______________ ___________ ______________ ________________________ _________________________ ______________________ __________________________ _______________________ __________________ _________________ ____________________ ________________________ ________________________ ____________________ _____________________________ _________________________________ ______________________________________________________ __________________ ______________ _________________ ___________________ ________________ ________________ _______________ ______ __________________ ______________ ______________ _______________ __________________ __________________ _______________ _________________ _________________ ______________ _________ 
188978561026 9b5j1zscxzg7q 14585 8124 55 32768 4 32768 0 0 0 0 0 0 0 4230 0 0 select GSMADMIN_INTERNAL.GETSHARDINGMODE from dual 1388734953 16777216 25-01-17 25-01-17 141 141 0 44 64740 2615955429 0 3032363729 Y N 0 QUERY N 3 
188978561282 awuwhfhgh5qz5 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777216 25-01-17 25-01-17 141 141 0 44 64740 2615955429 0 3032363729 Y N 0 QUERY N 3 
206158430210 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777218 25-01-17 25-01-17 141 141 0 48 25309 2615955429 0 3032363729 Y N 0 QUERY N 3 
210453397506 awuwhfhgh5qz5 16 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777220 25-01-17 25-01-17 141 141 0 49 54942 2615955429 0 3032363729 Y N 0 QUERY N 3 
214748364802 awuwhfhgh5qz5 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777221 25-01-17 25-01-17 141 141 0 50 32181 2615955429 0 3032363729 Y N 0 QUERY N 3 
219043332098 awuwhfhgh5qz5 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777225 25-01-17 25-01-17 141 141 0 51 27407 2615955429 0 3032363729 Y N 0 QUERY N 3 
906238100738 f8dzanrnkxys4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container=FREEPDB1 0 0 25-01-17 9 9 65535 211 64749 588800815 0 3032363729 Y N 0 OTHER N 3 
919123001346 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777217 25-01-17 25-01-17 141 141 0 214 13495 2615955429 0 3032363729 Y N 0 QUERY N 3 
923417968642 awuwhfhgh5qz5 24 23 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777219 25-01-17 25-01-17 141 141 0 215 21205 2615955429 0 3032363729 Y N 0 QUERY N 3 
927712935938 awuwhfhgh5qz5 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777222 25-01-17 25-01-17 141 141 0 216 58373 2615955429 0 3032363729 Y N 0 QUERY N 3 
932007903234 awuwhfhgh5qz5 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777223 25-01-17 25-01-17 141 141 0 217 49176 2615955429 0 3032363729 Y N 0 QUERY N 3 
936302870530 awuwhfhgh5qz5 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777224 25-01-17 25-01-17 141 141 0 218 44182 2615955429 0 3032363729 Y N 0 QUERY N 3

12行が選択されました。

先ほどのセッションで発行していたselect sysdate;の情報が消えています。
V$SQL_HISTORYの情報はセッションが切れると消えてしまうので、
情報を残したい場合は別のテーブルへ退避するなど工夫が必要ですね。

別のセッションから確認してみると

セッションを2つ立ち上げて、一方で発行したSQLの情報がどのようになるか見てみましょう。

SQL> SELECT SYS_CONTEXT('USERENV', 'SESSIONID');

SYS_CONTEXT('USERENV','SESSIONID') 
_____________________________________ 
210165

SQL> SELECT SYSDATE;

SYSDATE 
___________ 
25-01-22

SQL> SELECT * from v$sql_history ;

KEY SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS IO_INTERCONNECT_BYTES PHYSICAL_READ_REQUESTS PHYSICAL_READ_BYTES PHYSICAL_WRITE_REQUESTS PHYSICAL_WRITE_BYTES PLSQL_EXEC_TIME JAVA_EXEC_TIME CLUSTER_WAIT_TIME CONCURRENCY_WAIT_TIME APPLICATION_WAIT_TIME USER_IO_WAIT_TIME IO_CELL_UNCOMPRESSED_BYTES IO_CELL_OFFLOAD_ELIGIBLE_BYTES SQL_TEXT PLAN_HASH_VALUE SQL_EXEC_ID SQL_EXEC_START LAST_ACTIVE_TIME SESSION_USER# CURRENT_USER# CHILD_NUMBER SID SESSION_SERIAL# MODULE_HASH ACTION_HASH SERVICE_HASH IS_FULL_SQLTEXT ERROR_SIGNALLED ERROR_NUMBER ERROR_FACILITY STATEMENT_TYPE IS_PARALLEL CON_ID 
_______________ ________________ _______________ ___________ ______________ ________________________ _________________________ ______________________ __________________________ _______________________ __________________ _________________ ____________________ ________________________ ________________________ ____________________ _____________________________ _________________________________ ______________________________________________________ __________________ ______________ _________________ ___________________ ________________ ________________ _______________ ______ __________________ ______________ ______________ _______________ __________________ __________________ _______________ _________________ _________________ ______________ _________ 
197568495618 awuwhfhgh5qz5 16 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777217 25-01-22 25-01-22 141 141 0 46 30169 2615955429 0 3032363729 Y N 0 QUERY N 3 
201863462914 awuwhfhgh5qz5 13 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777219 25-01-22 25-01-22 141 141 0 47 41669 2615955429 0 3032363729 Y N 0 QUERY N 3 
206158430210 awuwhfhgh5qz5 15 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777221 25-01-22 25-01-22 141 141 0 48 34318 2615955429 0 3032363729 Y N 0 QUERY N 3 
210453397506 awuwhfhgh5qz5 14 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777223 25-01-22 25-01-22 141 141 0 49 18881 2615955429 0 3032363729 Y N 0 QUERY N 3 
214748364802 awuwhfhgh5qz5 16 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777225 25-01-22 25-01-22 141 141 0 50 7817 2615955429 0 3032363729 Y N 0 QUERY N 3 
833223656706 6pa94qjn5swha 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container = freepdb1 0 0 25-01-22 9 9 65535 194 49762 588800815 0 3032363729 Y N 0 OTHER N 3 
833223656962 3n8qysr5ckat6 10 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT SYS_CONTEXT('USERENV', 'SESSIONID') 1388734953 16777216 25-01-22 25-01-22 9 9 0 194 49762 588800815 0 3032363729 Y N 0 QUERY N 3 
833223657218 6khpctg9jhths 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT SYSDATE 1388734953 16777216 25-01-22 25-01-22 9 9 0 194 49762 588800815 0 3032363729 Y N 0 QUERY N 3 
850403525890 6pa94qjn5swha 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container = freepdb1 0 0 25-01-22 9 9 65535 198 55165 588800815 0 3032363729 Y N 0 OTHER N 3 
850403526146 3n8qysr5ckat6 11 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT SYS_CONTEXT('USERENV', 'SESSIONID') 1388734953 16777217 25-01-22 25-01-22 9 9 0 198 55165 588800815 0 3032363729 Y N 0 QUERY N 3 
884763262978 9b5j1zscxzg7q 14201 4861 55 32768 4 32768 0 0 0 0 0 0 0 4421 0 0 select GSMADMIN_INTERNAL.GETSHARDINGMODE from dual 1388734953 16777216 25-01-22 25-01-22 141 141 0 206 20586 2615955429 0 3032363729 Y N 0 QUERY N 3 
884763263234 awuwhfhgh5qz5 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777216 25-01-22 25-01-22 141 141 0 206 20586 2615955429 0 3032363729 Y N 0 QUERY N 3 
893353197570 awuwhfhgh5qz5 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777220 25-01-22 25-01-22 141 141 0 208 44410 2615955429 0 3032363729 Y N 0 QUERY N 3 
901943132162 awuwhfhgh5qz5 21 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777218 25-01-22 25-01-22 141 141 0 210 37240 2615955429 0 3032363729 Y N 0 QUERY N 3 
906238099458 awuwhfhgh5qz5 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777222 25-01-22 25-01-22 141 141 0 211 16632 2615955429 0 3032363729 Y N 0 QUERY N 3 
910533066754 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777224 25-01-22 25-01-22 141 141 0 212 32613 2615955429 0 3032363729 Y N 0 QUERY N 3

16行が選択されました。

SQL>

SELECT SYSDATE;の情報が記録されています。
この状態で、セッション(210165)を切らずにもう一つのセッション(210166)で確認してみましょう。

SQL> SELECT SYS_CONTEXT('USERENV', 'SESSIONID');

SYS_CONTEXT('USERENV','SESSIONID') 
_____________________________________ 
210166

SQL> SELECT * from v$sql_history ;

KEY SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS IO_INTERCONNECT_BYTES PHYSICAL_READ_REQUESTS PHYSICAL_READ_BYTES PHYSICAL_WRITE_REQUESTS PHYSICAL_WRITE_BYTES PLSQL_EXEC_TIME JAVA_EXEC_TIME CLUSTER_WAIT_TIME CONCURRENCY_WAIT_TIME APPLICATION_WAIT_TIME USER_IO_WAIT_TIME IO_CELL_UNCOMPRESSED_BYTES IO_CELL_OFFLOAD_ELIGIBLE_BYTES SQL_TEXT PLAN_HASH_VALUE SQL_EXEC_ID SQL_EXEC_START LAST_ACTIVE_TIME SESSION_USER# CURRENT_USER# CHILD_NUMBER SID SESSION_SERIAL# MODULE_HASH ACTION_HASH SERVICE_HASH IS_FULL_SQLTEXT ERROR_SIGNALLED ERROR_NUMBER ERROR_FACILITY STATEMENT_TYPE IS_PARALLEL CON_ID 
_______________ ________________ _______________ ___________ ______________ ________________________ _________________________ ______________________ __________________________ _______________________ __________________ _________________ ____________________ ________________________ ________________________ ____________________ _____________________________ _________________________________ ______________________________________________________ __________________ ______________ _________________ ___________________ ________________ ________________ _______________ ______ __________________ ______________ ______________ _______________ __________________ __________________ _______________ _________________ _________________ ______________ _________ 
197568495618 awuwhfhgh5qz5 16 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777217 25-01-22 25-01-22 141 141 0 46 30169 2615955429 0 3032363729 Y N 0 QUERY N 3 
201863462914 awuwhfhgh5qz5 13 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777219 25-01-22 25-01-22 141 141 0 47 41669 2615955429 0 3032363729 Y N 0 QUERY N 3 
206158430210 awuwhfhgh5qz5 15 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777221 25-01-22 25-01-22 141 141 0 48 34318 2615955429 0 3032363729 Y N 0 QUERY N 3 
210453397506 awuwhfhgh5qz5 14 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777223 25-01-22 25-01-22 141 141 0 49 18881 2615955429 0 3032363729 Y N 0 QUERY N 3 
214748364802 awuwhfhgh5qz5 16 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777225 25-01-22 25-01-22 141 141 0 50 7817 2615955429 0 3032363729 Y N 0 QUERY N 3 
833223656706 6pa94qjn5swha 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container = freepdb1 0 0 25-01-22 9 9 65535 194 49762 588800815 0 3032363729 Y N 0 OTHER N 3 
833223656962 3n8qysr5ckat6 10 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT SYS_CONTEXT('USERENV', 'SESSIONID') 1388734953 16777216 25-01-22 25-01-22 9 9 0 194 49762 588800815 0 3032363729 Y N 0 QUERY N 3 
833223657218 6khpctg9jhths 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT SYSDATE 1388734953 16777216 25-01-22 25-01-22 9 9 0 194 49762 588800815 0 3032363729 Y N 0 QUERY N 3 
833223657474 4wa87vtt127jg 554 554 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT * from v$sql_history 1076639199 16777216 25-01-22 25-01-22 9 9 0 194 49762 588800815 0 3032363729 Y N 0 QUERY N 3 
850403525890 6pa94qjn5swha 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container = freepdb1 0 0 25-01-22 9 9 65535 198 55165 588800815 0 3032363729 Y N 0 OTHER N 3 
850403526146 3n8qysr5ckat6 11 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT SYS_CONTEXT('USERENV', 'SESSIONID') 1388734953 16777217 25-01-22 25-01-22 9 9 0 198 55165 588800815 0 3032363729 Y N 0 QUERY N 3 
884763262978 9b5j1zscxzg7q 14201 4861 55 32768 4 32768 0 0 0 0 0 0 0 4421 0 0 select GSMADMIN_INTERNAL.GETSHARDINGMODE from dual 1388734953 16777216 25-01-22 25-01-22 141 141 0 206 20586 2615955429 0 3032363729 Y N 0 QUERY N 3 
884763263234 awuwhfhgh5qz5 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777216 25-01-22 25-01-22 141 141 0 206 20586 2615955429 0 3032363729 Y N 0 QUERY N 3 
893353197570 awuwhfhgh5qz5 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777220 25-01-22 25-01-22 141 141 0 208 44410 2615955429 0 3032363729 Y N 0 QUERY N 3 
901943132162 awuwhfhgh5qz5 21 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777218 25-01-22 25-01-22 141 141 0 210 37240 2615955429 0 3032363729 Y N 0 QUERY N 3 
906238099458 awuwhfhgh5qz5 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777222 25-01-22 25-01-22 141 141 0 211 16632 2615955429 0 3032363729 Y N 0 QUERY N 3 
910533066754 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777224 25-01-22 25-01-22 141 141 0 212 32613 2615955429 0 3032363729 Y N 0 QUERY N 3

17行が選択されました。

SQL>

別のセッションで実行したSQLの情報も確認できました。

セッション(210165)を切った状態でもう一つのセッション(210166)で確認してみるとどうなるでしょうか。

SQL> SELECT SYS_CONTEXT('USERENV', 'SESSIONID');

SYS_CONTEXT('USERENV','SESSIONID') 
_____________________________________ 
210165

SQL> exit
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.4.0.24.05から切断されました
[oracle@localhost ~]$
SQL> SELECT SYS_CONTEXT('USERENV', 'SESSIONID'); 
SYS_CONTEXT('USERENV','SESSIONID') 
_____________________________________ 
210166

SQL> SELECT * from v$sql_history ;

KEY SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS IO_INTERCONNECT_BYTES PHYSICAL_READ_REQUESTS PHYSICAL_READ_BYTES PHYSICAL_WRITE_REQUESTS PHYSICAL_WRITE_BYTES PLSQL_EXEC_TIME JAVA_EXEC_TIME CLUSTER_WAIT_TIME CONCURRENCY_WAIT_TIME APPLICATION_WAIT_TIME USER_IO_WAIT_TIME IO_CELL_UNCOMPRESSED_BYTES IO_CELL_OFFLOAD_ELIGIBLE_BYTES SQL_TEXT PLAN_HASH_VALUE SQL_EXEC_ID SQL_EXEC_START LAST_ACTIVE_TIME SESSION_USER# CURRENT_USER# CHILD_NUMBER SID SESSION_SERIAL# MODULE_HASH ACTION_HASH SERVICE_HASH IS_FULL_SQLTEXT ERROR_SIGNALLED ERROR_NUMBER ERROR_FACILITY STATEMENT_TYPE IS_PARALLEL CON_ID 
_______________ ________________ _______________ ___________ ______________ ________________________ _________________________ ______________________ __________________________ _______________________ __________________ _________________ ____________________ ________________________ ________________________ ____________________ _____________________________ _________________________________ ______________________________________________________ __________________ ______________ _________________ ___________________ ________________ ________________ _______________ ______ __________________ ______________ ______________ _______________ __________________ __________________ _______________ _________________ _________________ ______________ _________ 
214748364802 awuwhfhgh5qz5 16 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777225 25-01-22 25-01-22 141 141 0 50 7817 2615955429 0 3032363729 Y N 0 QUERY N 3 
850403525890 6pa94qjn5swha 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container = freepdb1 0 0 25-01-22 9 9 65535 198 55165 588800815 0 3032363729 Y N 0 OTHER N 3 
850403526146 3n8qysr5ckat6 11 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT SYS_CONTEXT('USERENV', 'SESSIONID') 1388734953 16777217 25-01-22 25-01-22 9 9 0 198 55165 588800815 0 3032363729 Y N 0 QUERY N 3 
850403526402 4wa87vtt127jg 574 574 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT * from v$sql_history 1076639199 16777217 25-01-22 25-01-22 9 9 0 198 55165 588800815 0 3032363729 Y N 0 QUERY N 3 
910533066754 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777224 25-01-22 25-01-22 141 141 0 212 32613 2615955429 0 3032363729 Y N 0 QUERY N 3

SQL>

切断したセッション(210165)で実行したSQL情報が消えています。
このことからV$SQL_HISTORYはセッションが残っている間だけ情報を格納しておく機能ということがわかりました。

また、セッションが残っていれば別のセッションから確認することができるので、定期的なバッチ処理等で情報を残しておくこともできそうです。

V$SQL_HISTORYの列

SQL> desc v$sql_history;

名前                               Nullかどうか  タイプ 
_________________________________  ___________  ________________ 
KEY                                             NUMBER 
SQL_ID                                          VARCHAR2(13) 
ELAPSED_TIME                                    NUMBER 
CPU_TIME                                        NUMBER 
BUFFER_GETS                                     NUMBER 
IO_INTERCONNECT_BYTES                           NUMBER 
PHYSICAL_READ_REQUESTS                          NUMBER 
PHYSICAL_READ_BYTES                             NUMBER 
PHYSICAL_WRITE_REQUESTS                         NUMBER 
PHYSICAL_WRITE_BYTES                            NUMBER 
PLSQL_EXEC_TIME                                 NUMBER 
JAVA_EXEC_TIME                                  NUMBER 
CLUSTER_WAIT_TIME                               NUMBER 
CONCURRENCY_WAIT_TIME                           NUMBER 
APPLICATION_WAIT_TIME                           NUMBER 
USER_IO_WAIT_TIME                               NUMBER 
IO_CELL_UNCOMPRESSED_BYTES                      NUMBER 
IO_CELL_OFFLOAD_ELIGIBLE_BYTES                  NUMBER 
SQL_TEXT                                        VARCHAR2(100) 
PLAN_HASH_VALUE                                 NUMBER 
SQL_EXEC_ID                                     NUMBER 
SQL_EXEC_START                                  DATE 
LAST_ACTIVE_TIME                                DATE 
SESSION_USER#                                   NUMBER 
CURRENT_USER#                                   NUMBER 
CHILD_NUMBER                                    NUMBER 
SID                                             NUMBER 
SESSION_SERIAL#                                 NUMBER 
MODULE_HASH                                     NUMBER 
ACTION_HASH                                     NUMBER 
SERVICE_HASH                                    NUMBER 
IS_FULL_SQLTEXT                                 VARCHAR2(1) 
ERROR_SIGNALLED                                 VARCHAR2(1) 
ERROR_NUMBER                                    NUMBER 
ERROR_FACILITY                                  VARCHAR2(4) 
STATEMENT_TYPE                                  VARCHAR2(5) 
IS_PARALLEL                                     VARCHAR2(1) 
CON_ID                                          NUMBER

V$SQL_HISTORYには以上の列が用意されています。
SQLの実行時間やDiskI/Oなどの情報が確認できるようです。

様々なIDやハッシュ値を持っているので他のパラメータと連携させることもできそうですね。
例えば以下のようにV$SESSIONのSIDを紐づけて現在のセッションの情報のみを動的に取得することができました。

サンプルSQL>
SELECT * FROM V$SQL_HISTORY where SID = (
SELECT SID from V$SESSION where AUDSID = (
SELECT SYS_CONTEXT(‘USERENV’, ‘SESSIONID’) from dual
)
);

SQL> select sysdate;

SYSDATE 
___________ 
25-01-23

SQL> 
SQL> SELECT * FROM V$SQL_HISTORY;

KEY SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS IO_INTERCONNECT_BYTES PHYSICAL_READ_REQUESTS PHYSICAL_READ_BYTES PHYSICAL_WRITE_REQUESTS PHYSICAL_WRITE_BYTES PLSQL_EXEC_TIME JAVA_EXEC_TIME CLUSTER_WAIT_TIME CONCURRENCY_WAIT_TIME APPLICATION_WAIT_TIME USER_IO_WAIT_TIME IO_CELL_UNCOMPRESSED_BYTES IO_CELL_OFFLOAD_ELIGIBLE_BYTES SQL_TEXT PLAN_HASH_VALUE SQL_EXEC_ID SQL_EXEC_START LAST_ACTIVE_TIME SESSION_USER# CURRENT_USER# CHILD_NUMBER SID SESSION_SERIAL# MODULE_HASH ACTION_HASH SERVICE_HASH IS_FULL_SQLTEXT ERROR_SIGNALLED ERROR_NUMBER ERROR_FACILITY STATEMENT_TYPE IS_PARALLEL CON_ID 
_______________ ________________ _______________ ___________ ______________ ________________________ _________________________ ______________________ __________________________ _______________________ __________________ _________________ ____________________ ________________________ ________________________ ____________________ _____________________________ _________________________________ ______________________________________________________ __________________ ______________ _________________ ___________________ ________________ ________________ _______________ ______ __________________ ______________ ______________ _______________ __________________ __________________ _______________ _________________ _________________ ______________ _________ 
201863462914 awuwhfhgh5qz5 19 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777217 25-01-23 25-01-23 141 141 0 47 8458 2615955429 0 3032363729 Y N 0 QUERY N 3 
206158430210 awuwhfhgh5qz5 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777219 25-01-23 25-01-23 141 141 0 48 43949 2615955429 0 3032363729 Y N 0 QUERY N 3 
210453397506 awuwhfhgh5qz5 20 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777222 25-01-23 25-01-23 141 141 0 49 26903 2615955429 0 3032363729 Y N 0 QUERY N 3 
214748364802 awuwhfhgh5qz5 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777223 25-01-23 25-01-23 141 141 0 50 32438 2615955429 0 3032363729 Y N 0 QUERY N 3 
219043332098 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777225 25-01-23 25-01-23 141 141 0 51 9649 2615955429 0 3032363729 Y N 0 QUERY N 3 
893353197570 9b5j1zscxzg7q 33161 18382 55 32768 4 32768 0 0 0 0 0 0 0 8784 0 0 select GSMADMIN_INTERNAL.GETSHARDINGMODE from dual 1388734953 16777216 25-01-23 25-01-23 141 141 0 208 25766 2615955429 0 3032363729 Y N 0 QUERY N 3 
893353197826 awuwhfhgh5qz5 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777216 25-01-23 25-01-23 141 141 0 208 25766 2615955429 0 3032363729 Y N 0 QUERY N 3 
897648164866 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777218 25-01-23 25-01-23 141 141 0 209 63068 2615955429 0 3032363729 Y N 0 QUERY N 3 
901943132162 awuwhfhgh5qz5 17 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777220 25-01-23 25-01-23 141 141 0 210 55860 2615955429 0 3032363729 Y N 0 QUERY N 3 
906238099458 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777221 25-01-23 25-01-23 141 141 0 211 24718 2615955429 0 3032363729 Y N 0 QUERY N 3 
910533066754 awuwhfhgh5qz5 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sys_context('userenv','con_name') from dual 1388734953 16777224 25-01-23 25-01-23 141 141 0 212 33242 2615955429 0 3032363729 Y N 0 QUERY N 3 
919123002626 6pa94qjn5swha 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container = freepdb1 0 0 25-01-23 9 9 65535 214 4629 588800815 0 3032363729 Y N 0 OTHER N 3 
919123002882 cxpb33fsdby3x 398 398 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT * FROM V$SQL_HISTORY 1076639199 16777216 25-01-23 25-01-23 9 9 0 214 4629 588800815 0 3032363729 Y N 0 QUERY N 3 
919123003138 bw2c1d6sqyjpy 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sysdate 1388734953 16777216 25-01-23 25-01-23 9 9 0 214 4629 588800815 0 3032363729 Y N 0 QUERY N 3

14行が選択されました。

SQL> 
SQL> SELECT * FROM V$SQL_HISTORY where SID = (SELECT SID from V$SESSION where AUDSID = (SELECT SYS_CONTEXT('USERENV', 'SESSIONID') from dual));

KEY SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS IO_INTERCONNECT_BYTES PHYSICAL_READ_REQUESTS PHYSICAL_READ_BYTES PHYSICAL_WRITE_REQUESTS PHYSICAL_WRITE_BYTES PLSQL_EXEC_TIME JAVA_EXEC_TIME CLUSTER_WAIT_TIME CONCURRENCY_WAIT_TIME APPLICATION_WAIT_TIME USER_IO_WAIT_TIME IO_CELL_UNCOMPRESSED_BYTES IO_CELL_OFFLOAD_ELIGIBLE_BYTES SQL_TEXT PLAN_HASH_VALUE SQL_EXEC_ID SQL_EXEC_START LAST_ACTIVE_TIME SESSION_USER# CURRENT_USER# CHILD_NUMBER SID SESSION_SERIAL# MODULE_HASH ACTION_HASH SERVICE_HASH IS_FULL_SQLTEXT ERROR_SIGNALLED ERROR_NUMBER ERROR_FACILITY STATEMENT_TYPE IS_PARALLEL CON_ID 
_______________ ________________ _______________ ___________ ______________ ________________________ _________________________ ______________________ __________________________ _______________________ __________________ _________________ ____________________ ________________________ ________________________ ____________________ _____________________________ _________________________________ __________________________________________ __________________ ______________ _________________ ___________________ ________________ ________________ _______________ ______ __________________ ______________ ______________ _______________ __________________ __________________ _______________ _________________ _________________ ______________ _________ 
919123002626 6pa94qjn5swha 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 alter session set container = freepdb1 0 0 25-01-23 9 9 65535 214 4629 588800815 0 3032363729 Y N 0 OTHER N 3 
919123002882 cxpb33fsdby3x 398 398 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT * FROM V$SQL_HISTORY 1076639199 16777216 25-01-23 25-01-23 9 9 0 214 4629 588800815 0 3032363729 Y N 0 QUERY N 3 
919123003138 bw2c1d6sqyjpy 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 select sysdate 1388734953 16777216 25-01-23 25-01-23 9 9 0 214 4629 588800815 0 3032363729 Y N 0 QUERY N 3 
919123003394 cxpb33fsdby3x 95 95 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SELECT * FROM V$SQL_HISTORY 1076639199 16777217 25-01-23 25-01-23 9 9 0 214 4629 588800815 0 3032363729 Y N 0 QUERY N 3

SQL>

※各項目の説明は詳しいこちらのページをご確認ください

おわりに

今回はSQL HISTORY(SQL履歴)について紹介してみました。

一度パラメータを変更すればすぐに利用することができます。
セッションが切れれば収集した情報リセットされるため容量を気にする必要もありません。
簡易的ではありますが、AWRやStatspackを使用していない環境でもSQLの性能を確認することができるので、アプリケーション開発の場面で利用する機会があるかもしれません。

最後までお読みいただきありがとうございました。

Oracle Databaseに関してお困りごとがあれば、ぜひ当社へご相談ください。

投稿者プロフィール

技術チーム
技術チーム
DBひとりでできるもんを盛り上げるべく、技術チームが立ち上がり早6年。ひとりでできるもんと言いつつ、技術者が読んでプッとなるような、極めてピンポイントでマニアックな技術ネタを執筆しています!