In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Xiaobian to share with you how to achieve table space monitoring scripts in the database, I hope you have gained something after reading this article, let's discuss it together!
----Query Tablespace Usage
SELECT TABLESPACE_NAME,
ROUND(TABLESPACE_SIZE / 128 * 1024 / 1024 /1024, 3) "Total Space (GB)",
ROUND(USED_SPACE / 128 * 1024 / 1024 / 1024, 3) "GB",
ROUND(TABLESPACE_SIZE / 128 * 1024 / 1024 / 1024 -
USED_SPACE / 128 * 1024 / 1024 / 1024,
3)"Remaining (GB)",
ROUND(USED_SPACE / TABLESPACE_SIZE * 100, 2) ||'%' Usage
FROM SYS.DBA_TABLESPACE_USAGE_METRICS T
/* WHERE ROUND(TABLESPACE_SIZE / 128 * 1024 / 1024 / 1024 -
USED_SPACE / 128 * 1024 / 1024 / 1024,
3)
< '80' AND TABLESPACE_NAME LIKE 'TBS_%'*/ ORDER BY TABLESPACE_NAME ASC; 2. -----查询某个表空间下储存的表 SELECT OWNER || '.' || SEGMENT_NAME, SUM(BYTES) / 1024 / 1024 / 1024 BYTES FROM DBA_SEGMENTS WHERE TABLESPACE_NAME = 'TBS_YYFX' AND SEGMENT_NAME ='###表名###' AND BYTES >196608 --196608 is the size of the empty table, BYTES>196608 throws an empty table
GROUP BY OWNER || '. ' || SEGMENT_NAME
ORDER BY BYTES DESC;
3. Two Ways to Clean Tablespace
(1)
----Clear data of a table
SELECT BYTES / 1024 / 1024 / 1024,
'ALTER TABLE ' || OWNER || '. ' || SEGMENT_NAME ||
' TRUNCATE PARTITION ' || PARTITION_NAME || ';'
FROM DBA_SEGMENTS
WHERE OWNER || '. ' ||SEGMENT_NAME ='###table name ###'
AND BYTES > 196608 --196608 is the size of an empty table, BYTES>196608 throws an empty table
ORDER BY BYTES DESC;
(2)
----Compress tables Migrate part of a table's data to another table space
SELECT BYTES / 1024 / 1024 / 1024,
'ALTER TABLE ' || OWNER || '. ' || SEGMENT_NAME || ' MOVE PARTITION ' ||
PARTITION_NAME ||' TABLESPACE TBS_DWD;'--Tablespace to migrate to
FROM DBA_SEGMENTS
WHERE TABLESPACE_NAME = 'TBS_DWD' --The table space in which the table resides
AND OWNER || '. ' ||SEGMENT_NAME = '###table name ###'
AND BYTES > 196608 --196608 is the size of an empty table, BYTES>196608 throws an empty table
ORDER BY BYTES DESC;
After reading this article, I believe you have a certain understanding of "how to implement table space monitoring scripts in databases." If you want to know more about this knowledge, please pay attention to the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.