第一步要先抓到資料筆數比較多跟Size比較大的資料表,
所以找到了一些SQL的寫法,如下:
/* 資料筆數 */
SELECT TABLE_NAME, AVG_ROW_LEN, NUM_ROWS
FROM DBA_TABLES
WHERE NUM_ROWS > 1000000
ORDER BY NUM_ROWS DESC;
/* Table size */
SELECT SEGMENT_NAME AS TABLE_NAME,
ROUND(SUM(BYTES) /(1024*1024*1024),2) AS TABLE_SIZE_GB
FROM USER_EXTENTS
GROUP BY SEGMENT_NAME
HAVING ROUND(SUM(BYTES) /(1024*1024*1024),2) > 0.5
ORDER BY ROUND(SUM(BYTES) /(1024*1024*1024),2) DESC;
/* Data size */
SELECT TABLE_NAME, AVG_ROW_LEN, NUM_ROWS,
ROUND (AVG_ROW_LEN * NUM_ROWS /(1024*1024*1024),2) AS DATA_SIZE_GB
FROM DBA_TABLES
WHERE ROUND(AVG_ROW_LEN * NUM_ROWS /(1024*1024*1024),2) > 0.1
ORDER BY ROUND(AVG_ROW_LEN * NUM_ROWS /(1024*1024*1024),2) DESC;
有聽過不太會寫PL/SQL,然後要來調效能的八卦嗎?
沒有留言:
張貼留言