1. 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

2. 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);

3. 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);

4. 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);

5. 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;

6. Gather dictionary và fixed object statistics

EXEC DBMS_STATS.gather_dictionary_stats;
EXEC DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;

7. Lock/unlock statistics:

1. Lock stats schema:

EXEC DBMS_STATS.lock_schema_stats('SOE');

2. Lock stats table:

EXEC DBMS_STATS.lock_table_stats('SOE', 'CUSTOMERS');

3. Lock stats partition:

EXEC DBMS_STATS.lock_partition_stats('SOE', 'CUSTOMERS', 'PARTITION2022');

4. Unlock stats schema:

EXEC DBMS_STATS.unlock_schema_stats('SOE');

5. Unlock stats table:

EXEC DBMS_STATS.unlock_table_stats('SOE', 'CUSTOMERS');

6. Unlock stats partition:

EXEC DBMS_STATS.unlock_partition_stats('SOE', 'CUSTOMERS', 'PARTITION2022');

7. Check stats status:

SELECT stattype_locked FROM dba_tab_statistics
WHERE table_name = 'CUSTOMERS' and owner = 'SOE';

8. Kiểm tra xem object đã bị stale statistics hay chưa

1. Kiểm tra stale stats cho table:

select owner,table_name, STALE_STATS
from dba_tab_statistics
where owner='SOE' and table_name='CUSTOMERS';

2. 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/

Đọc thêm  Chuyển database Oracle về Archive log mode

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 2: ADMIN 1 + DATA GUARD

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Ý:

https://forms.gle/MtCAoRQFenP886y79

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é.

0 0 đánh giá
Article Rating
Theo dõi
Thông báo của
guest


0 Comments
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất
Phản hồi nội tuyến
Xem tất cả bình luận
0
Rất thích suy nghĩ của bạn, hãy bình luận.x