Giới thiệu
Bài viết này tổng hợp các câu lệnh gather statistics hay dùng cho Oracle Database
Gather statistics cho toàn bộ database
Bạn có thể chọn 1 trong những câu lệnh sau để gather statistics cho toàn bộ database
EXEC DBMS_STATS.gather_database_stats; EXEC DBMS_STATS.gather_database_stats(estimate_percent => 15); EXEC DBMS_STATS.gather_database_stats(estimate_percent => 15, cascade => TRUE); EXEC DBMS_STATS.gather_database_stats(estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,degree => 8);
Gather statistics cho toàn bộ schema
Bạn có thể chọn 1 trong những câu lệnh sau để gather statistics cho toàn bộ schema
EXEC DBMS_STATS.gather_schema_stats('SOE'); EXEC DBMS_STATS.gather_schema_stats('SOE', estimate_percent => 15); EXEC DBMS_STATS.gather_schema_stats('SOE', estimate_percent => 100, cascade => TRUE); EXEC DBMS_STATS.gather_schema_stats( ownname => 'SOE',method_opt => 'FOR ALL COLUMNS SIZE 1', granularity => 'ALL', degree => 8, cascade => TRUE, estimate_percent=>dbms_stats.auto_sample_size);
Gather statistics cho 1 table cụ thể
exec dbms_stats.gather_table_stats('SOE', 'CUSTOMERS'); exec dbms_stats.gather_table_stats('SOE', 'CUSTOMERS', estimate_percent => 15); exec dbms_stats.gather_table_stats('SOE', 'CUSTOMERS', estimate_percent => 15, cascade => true); exec dbms_stats.gather_table_stats (ownname => 'SOE' , tabname => 'CUSTOMERS',cascade => true, method_opt => 'for all indexed columns size 1', granularity => 'all', degree => 8); exec dbms_stats.gather_table_stats (ownname => 'SOE' , tabname => 'CUSTOMERS', cascade => true, method_opt => 'for all columns size 1', granularity => 'all', degree => 8);
Gather statistics cho 1 partition cụ thể
BEGIN DBMS_STATS.GATHER_TABLE_STATS ( ownname => 'SOE', tabname => 'CUSTOMERS', --- TABLE NAME partname => 'PARTITION2022' --- PARTITION NAME method_opt =>'for all indexed columns size 1', GRANULARITY => 'APPROX_GLOBAL AND PARTITION', degree => 8); END;
Gather dictionary và fixed object statistics
EXEC DBMS_STATS.gather_dictionary_stats; EXEC DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;
Lock/unlock statistics:
Lock stats schema:
EXEC DBMS_STATS.lock_schema_stats('SOE');
Lock stats table:
EXEC DBMS_STATS.lock_table_stats('SOE', 'CUSTOMERS');
Lock stats partition:
EXEC DBMS_STATS.lock_partition_stats('SOE', 'CUSTOMERS', 'PARTITION2022');
Unlock stats schema:
EXEC DBMS_STATS.unlock_schema_stats('SOE');
Unlock stats table:
EXEC DBMS_STATS.unlock_table_stats('SOE', 'CUSTOMERS');
Unlock stats partition:
EXEC DBMS_STATS.unlock_partition_stats('SOE', 'CUSTOMERS', 'PARTITION2022');
Check stats status:
SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = 'CUSTOMERS' and owner = 'SOE';
Kiểm tra xem object đã bị stale statistics hay chưa
Kiểm tra stale stats cho table:
select owner,table_name, STALE_STATS from dba_tab_statistics where owner='SOE' and table_name='CUSTOMERS';
Kiểm tra stale stats cho index:
select owner, INDEX_NAME, TABLE_NAME from DBA_IND_STATISTICS where owner='SOE' and index_name='CUSTOMERS_IDX1';
Nguồn: https://dangxuanduy.com/
Hiện tại, tôi có tổ chức đều đặn các khóa học về quản trị Oracle Database, tôi sẽ để thông tin ở đây, để bạn nào quan tâm về lịch học cũng như chương trình học có thể theo dõi nhé.
KHOÁ DÀNH CHO NGƯỜI MỚI
KHÓA HỌC: QUẢN TRỊ ORACLE DATABASE THẬT LÀ ĐƠN GIẢN (ADMIN 1)
CÁC KHOÁ NÂNG CAO:
KHÓA HỌC ORACLE NÂNG CAO: QUẢN TRỊ KIẾN TRÚC MULTITENANT 12c
KHÓA HỌC ORACLE NÂNG CAO: QUẢN TRỊ HỆ THỐNG DATA GUARD
CÁC KHOÁ COMBO:
COMBO 1: ADMIN 1 + MULTITENANT 12c
COMBO 3: ADMIN 1 + MULTITENANT 12c + DATA GUARD
LỊCH HỌC:
Mời bạn xem tại đây: LỊCH HỌC CÁC LỚP ORACLE
ĐĂNG KÝ:
Form đăng ký
Hãy tham gia group “Kho tài liệu kiến thức database” để cùng học hỏi và chia sẻ nhé.