查看表空间相关信息SELECT TABLESPACE_NAME, BLOCK_SIZE, --
查看表空间相关信息
SELECT TABLESPACE_NAME,
BLOCK_SIZE, --db_block_size大小
INITIAL_EXTENT
FROM DBA_TABLESPACES
2. 表空间对应文件名称及大小
SELECT TABLESPACE_NAME,
FILE_ID,
FILE_NAME,
ROUND(BYTES / (1024 * 1024), 0) TOTAL_SPACE
FROM DBA_DATA_FILES
ORDER BY TABLESPACE_NAME;
3. 查看表空间大小,使用情况
SELECT UPPER(F.TABLESPACE_NAME) AS TABLESPACE_NAME, --表空间名称
D.TOTAL_BYTES AS TOTAL_BYTES, --表空间大小M
F.FREE_BYTES AS FREE_BYTES, --空闲大小M
D.TOTAL_BYTES - F.FREE_BYTES AS USEAGE_BYTES, --使用大小M
TO_CHAR(ROUND((D.TOTAL_BYTES - F.FREE_BYTES) / D.TOTAL_BYTES * 100, 2), '990.99')
AS USEAGE_PERCENT, --使用占比
F.MAX_BYTES AS BLOCK_MAX_BYTES --最大BLOCK块
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) FREE_BYTES,
ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOTAL_BYTES
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 4 DESC;
4.查看数据库版本相关信息
SELECT PRODUCT,VERSioN,STATUS FROM PRODUCT_COMPONENT_VERSION;
5.查看表大小
analyze table tablename compute statistics;
SELECT NUM_ROWS * AVG_ROW_LEN FROM USER_TABLES WHERE TABLE_NAME = 'tablename';
6.查看正在执行的sql
SELECT b.sid oracleID,
b.username,
b.Machine,
b.PROGRAM,
b.serial#,
spid ,
STATUS,
paddr,
sql_text,
c.CPU_TIME
FROM v$process a, v$session b, v$sqlarea c
WHERE a.addr = b.paddr
AND b.sql_hash_value = c.hash_value;
7.查看当前表被锁对象
SELECT SESS.SID,
SESS.SERIAL#,
LO.ORACLE_USERNAME,
LO.OS_USER_NAME,
AO.OBJECT_NAME,
LO.LOCKED_MODE,
SESS.MACHINE,
SESS.TERMINAL,
SESS.LOGoN_TIME
FROM V$LOCKED_OBJECT LO, DBA_OBJECTS AO, V$SESSION SESS
WHERE AO.OBJECT_ID = LO.OBJECT_ID
AND LO.SESSION_ID = SESS.SID;
ALTER SYSTEM KILL SESSION 'SID,SERIAL#'; --杀掉锁表进程
--结束END--
本文标题: Oracle常用SQL汇总(持续更新)
本文链接: https://lsjlt.com/news/37123.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0