加快dba_hist_active_sess_history的查詢速度
核心資料庫的快照保留時間提高到1個月,導致從dba_hist_active_sess_history這張表裡找點東西非常慢。從v$session裡看髮型是對WRH$_ACTIVE_SESSION_HISTORY走direct path read,很吃IO,而且速度也不快。
看一下WRH$_ACTIVE_SESSION_HISTORY的定義:
17:01:51 SQL> select dbms_metadata.get_ddl('TABLE','WRH$_ACTIVE_SESSION_HISTORY','SYS') from dual;
DBMS_METADATA.GET_DDL('TABLE','WRH$_ACTIVE_SESSION_HISTORY','SYS')
--------------------------------------------------------------------------------
CREATE TABLE "SYS"."WRH$_ACTIVE_SESSION_HISTORY"
( "SNAP_ID" NUMBER NOT NULL ENABLE,
"DBID" NUMBER NOT NULL ENABLE,
"INSTANCE_NUMBER" NUMBER NOT NULL ENABLE,
"SAMPLE_ID" NUMBER NOT NULL ENABLE,
"SAMPLE_TIME" TIMESTAMP (3) NOT NULL ENABLE,
"SESSION_ID" NUMBER NOT NULL ENABLE,
"SESSION_SERIAL#" NUMBER,
"USER_ID" NUMBER,
"SQL_ID" VARCHAR2(13),
"SQL_CHILD_NUMBER" NUMBER,
"SQL_PLAN_HASH_VALUE" NUMBER,
"SERVICE_HASH" NUMBER,
"SESSION_TYPE" NUMBER,
"SQL_OPCODE" NUMBER,
"QC_SESSION_ID" NUMBER,
"QC_INSTANCE_ID" NUMBER,
"CURRENT_OBJ#" NUMBER,
"CURRENT_FILE#" NUMBER,
"CURRENT_BLOCK#" NUMBER,
"SEQ#" NUMBER,
"EVENT_ID" NUMBER,
"P1" NUMBER,
"P2" NUMBER,
"P3" NUMBER,
"WAIT_TIME" NUMBER,
"TIME_WAITED" NUMBER,
"PROGRAM" VARCHAR2(64),
"MODULE" VARCHAR2(64),
"ACTION" VARCHAR2(64),
"CLIENT_ID" VARCHAR2(64),
"FORCE_MATCHING_SIGNATURE" NUMBER,
"BLOCKING_SESSION" NUMBER,
"BLOCKING_SESSION_SERIAL#" NUMBER,
"XID" RAW(8),
"CONSUMER_GROUP_ID" NUMBER,
"PLSQL_ENTRY_OBJECT_ID" NUMBER,
"PLSQL_ENTRY_SUBPROGRAM_ID" NUMBER,
"PLSQL_OBJECT_ID" NUMBER,
"PLSQL_SUBPROGRAM_ID" NUMBER,
"QC_SESSION_SERIAL#" NUMBER,
"REMOTE_INSTANCE#" NUMBER,
"SQL_PLAN_LINE_ID" NUMBER,
"SQL_PLAN_OPERATION#" NUMBER,
"SQL_PLAN_OPTIONS#" NUMBER,
"SQL_EXEC_ID" NUMBER,
"SQL_EXEC_START" DATE,
"TIME_MODEL" NUMBER,
"TOP_LEVEL_SQL_ID" VARCHAR2(13),
"TOP_LEVEL_SQL_OPCODE" NUMBER,
"CURRENT_ROW#" NUMBER,
"FLAGS" NUMBER,
"BLOCKING_INST_ID" NUMBER,
"ECID" VARCHAR2(64),
"TM_DELTA_TIME" NUMBER,
"TM_DELTA_CPU_TIME" NUMBER,
"TM_DELTA_DB_TIME" NUMBER,
"DELTA_TIME" NUMBER,
"DELTA_READ_IO_REQUESTS" NUMBER,
"DELTA_WRITE_IO_REQUESTS" NUMBER,
"DELTA_READ_IO_BYTES" NUMBER,
"DELTA_WRITE_IO_BYTES" NUMBER,
"DELTA_INTERCONNECT_IO_BYTES" NUMBER,
"PGA_ALLOCATED" NUMBER,
"TEMP_SPACE_ALLOCATED" NUMBER,
"TOP_LEVEL_CALL#" NUMBER,
"MACHINE" VARCHAR2(64),
"PORT" NUMBER,
"DBREPLAY_FILE_ID" NUMBER,
"DBREPLAY_CALL_COUNTER" NUMBER,
"PX_FLAGS" NUMBER,
CONSTRAINT "WRH$_ACTIVE_SESSION_HISTORY_PK" PRIMARY KEY ("DBID", "SNAP_ID", "INSTANCE_NU
MBER", "SAMPLE_ID", "SESSION_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" LOCAL
(PARTITION "WRH$_ACTIVE_2127610945_35001"
PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_2127610945_47787"
PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_2127610945_49713"
PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_SES_MXDB_MXSN"
PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ) ENABLE
) PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSTEM"
PARTITION BY RANGE ("DBID","SNAP_ID")
(PARTITION "WRH$_ACTIVE_2127610945_35001" VALUES LESS THAN (2127610945, 36592)
PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_2127610945_47787" VALUES LESS THAN (2127610945, 49713)
PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_2127610945_49713" VALUES LESS THAN (2127610945, MAXVALUE)
PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_SES_MXDB_MXSN" VALUES LESS THAN (MAXVALUE, MAXVALUE)
PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ) ENABLE ROW MOVEMENT
看了主鍵和分割槽鍵的設定後,在查詢里加上dbid,snap_id的範圍,以及instance_number,速度快了不少而且大大降低對資料庫的壓力。
看一下WRH$_ACTIVE_SESSION_HISTORY的定義:
17:01:51 SQL> select dbms_metadata.get_ddl('TABLE','WRH$_ACTIVE_SESSION_HISTORY','SYS') from dual;
DBMS_METADATA.GET_DDL('TABLE','WRH$_ACTIVE_SESSION_HISTORY','SYS')
--------------------------------------------------------------------------------
CREATE TABLE "SYS"."WRH$_ACTIVE_SESSION_HISTORY"
( "SNAP_ID" NUMBER NOT NULL ENABLE,
"DBID" NUMBER NOT NULL ENABLE,
"INSTANCE_NUMBER" NUMBER NOT NULL ENABLE,
"SAMPLE_ID" NUMBER NOT NULL ENABLE,
"SAMPLE_TIME" TIMESTAMP (3) NOT NULL ENABLE,
"SESSION_ID" NUMBER NOT NULL ENABLE,
"SESSION_SERIAL#" NUMBER,
"USER_ID" NUMBER,
"SQL_ID" VARCHAR2(13),
"SQL_CHILD_NUMBER" NUMBER,
"SQL_PLAN_HASH_VALUE" NUMBER,
"SERVICE_HASH" NUMBER,
"SESSION_TYPE" NUMBER,
"SQL_OPCODE" NUMBER,
"QC_SESSION_ID" NUMBER,
"QC_INSTANCE_ID" NUMBER,
"CURRENT_OBJ#" NUMBER,
"CURRENT_FILE#" NUMBER,
"CURRENT_BLOCK#" NUMBER,
"SEQ#" NUMBER,
"EVENT_ID" NUMBER,
"P1" NUMBER,
"P2" NUMBER,
"P3" NUMBER,
"WAIT_TIME" NUMBER,
"TIME_WAITED" NUMBER,
"PROGRAM" VARCHAR2(64),
"MODULE" VARCHAR2(64),
"ACTION" VARCHAR2(64),
"CLIENT_ID" VARCHAR2(64),
"FORCE_MATCHING_SIGNATURE" NUMBER,
"BLOCKING_SESSION" NUMBER,
"BLOCKING_SESSION_SERIAL#" NUMBER,
"XID" RAW(8),
"CONSUMER_GROUP_ID" NUMBER,
"PLSQL_ENTRY_OBJECT_ID" NUMBER,
"PLSQL_ENTRY_SUBPROGRAM_ID" NUMBER,
"PLSQL_OBJECT_ID" NUMBER,
"PLSQL_SUBPROGRAM_ID" NUMBER,
"QC_SESSION_SERIAL#" NUMBER,
"REMOTE_INSTANCE#" NUMBER,
"SQL_PLAN_LINE_ID" NUMBER,
"SQL_PLAN_OPERATION#" NUMBER,
"SQL_PLAN_OPTIONS#" NUMBER,
"SQL_EXEC_ID" NUMBER,
"SQL_EXEC_START" DATE,
"TIME_MODEL" NUMBER,
"TOP_LEVEL_SQL_ID" VARCHAR2(13),
"TOP_LEVEL_SQL_OPCODE" NUMBER,
"CURRENT_ROW#" NUMBER,
"FLAGS" NUMBER,
"BLOCKING_INST_ID" NUMBER,
"ECID" VARCHAR2(64),
"TM_DELTA_TIME" NUMBER,
"TM_DELTA_CPU_TIME" NUMBER,
"TM_DELTA_DB_TIME" NUMBER,
"DELTA_TIME" NUMBER,
"DELTA_READ_IO_REQUESTS" NUMBER,
"DELTA_WRITE_IO_REQUESTS" NUMBER,
"DELTA_READ_IO_BYTES" NUMBER,
"DELTA_WRITE_IO_BYTES" NUMBER,
"DELTA_INTERCONNECT_IO_BYTES" NUMBER,
"PGA_ALLOCATED" NUMBER,
"TEMP_SPACE_ALLOCATED" NUMBER,
"TOP_LEVEL_CALL#" NUMBER,
"MACHINE" VARCHAR2(64),
"PORT" NUMBER,
"DBREPLAY_FILE_ID" NUMBER,
"DBREPLAY_CALL_COUNTER" NUMBER,
"PX_FLAGS" NUMBER,
CONSTRAINT "WRH$_ACTIVE_SESSION_HISTORY_PK" PRIMARY KEY ("DBID", "SNAP_ID", "INSTANCE_NU
MBER", "SAMPLE_ID", "SESSION_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" LOCAL
(PARTITION "WRH$_ACTIVE_2127610945_35001"
PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_2127610945_47787"
PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_2127610945_49713"
PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_SES_MXDB_MXSN"
PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ) ENABLE
) PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSTEM"
PARTITION BY RANGE ("DBID","SNAP_ID")
(PARTITION "WRH$_ACTIVE_2127610945_35001" VALUES LESS THAN (2127610945, 36592)
PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_2127610945_47787" VALUES LESS THAN (2127610945, 49713)
PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_2127610945_49713" VALUES LESS THAN (2127610945, MAXVALUE)
PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ,
PARTITION "WRH$_ACTIVE_SES_MXDB_MXSN" VALUES LESS THAN (MAXVALUE, MAXVALUE)
PCTFREE 1 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ) ENABLE ROW MOVEMENT
看了主鍵和分割槽鍵的設定後,在查詢里加上dbid,snap_id的範圍,以及instance_number,速度快了不少而且大大降低對資料庫的壓力。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26239116/viewspace-1425339/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [Hive]Hive中表連線的優化,加快查詢速度Hive優化
- 查詢DBA_HIST_ACTIVE_SESS_HISTORY緩慢
- 提高sql查詢速度SQL
- 提高count查詢速度
- 優化sql查詢速度優化SQL
- 提高查詢速度使用materizlizedZed
- 加快Vue專案的開發速度Vue
- 硬碟提速,加快硬碟速度的辦法硬碟
- 提高查詢速度方法總結
- 優化sql提高查詢速度優化SQL
- 加快Android編譯速度Android編譯
- hibernate跟jdbc的查詢速度相差10???JDBC
- Python程式碼微優化之加快查詢Python優化
- c++map 查詢元素和list查詢元素速度對比C++
- 檔案上傳速度查詢方法
- 【ASH】如何匯出檢視DBA_HIST_ACTIVE_SESS_HISTORY的查詢結果資料
- MySQL加速查詢速度的獨門武器:查詢快取(QueryCache)MySql快取
- 找出Mysql查詢速度慢的SQL語句MySql
- 加快Android編譯速度的技巧總結Android編譯
- 如何加快C++程式碼的編譯速度C++編譯
- ClickHouse為什麼查詢速度快?
- Oracle臨時表 優化查詢速度Oracle優化
- Effective前端--加快頁面開啟速度前端
- Grafana Loki查詢加速:如何在不新增資源的前提下提升查詢速度GrafanaLoki
- QL Server 百萬級資料提高查詢速度的方法Server
- 提高ORACLE資料庫的查詢統計速度(轉)Oracle資料庫
- Android加快編譯速度的另一種方法Android編譯
- 加快Win8系統上網速度的方法
- 加快網站訪問速度的9大方法網站
- 如何將 MySQL 查詢速度提升 300 倍MySql
- Oracle臨時表最佳化查詢速度Oracle
- Oracle臨時表 最佳化查詢速度Oracle
- SQL SERVER BACKUP DATABASE 加快備份速度方法SQLServerDatabase
- 提升網站訪問速度的 SQL 查詢優化技巧網站SQL優化
- SQL Server查詢速度慢的原因及優化方法SQLServer優化
- 加快你的網站響應速度-Vue懶載入網站Vue
- 加快RMAN增量備份的速度(block change tracking特性)BloC
- 提高跨庫查詢速度,你只需一個Smartbi