Key SQL Queries for Effective Oracle Database Administration

Key SQL Queries for Effective Oracle Database Administration

— active sessions
SELECT username, count(*) AS num_sessions
FROM v$session
WHERE status = ‘ACTIVE’
GROUP BY username;

— lock sessions
SELECT *
FROM v$lock l JOIN v$session s ON l.sid = s.sid
WHERE l.type = ‘TX’ AND l.lmode > 0 AND l.request > 0;

— to review time of query or number of executions
SELECT sql_text, elapsed_time, executions, parsing_schema_name, last_load_time
FROM v$sqlarea
WHERE executions > 0
ORDER BY elapsed_time DESC;

Subscribe to our newsletter

Follow Us

— to review events
SELECT event, total_waits, time_waited
FROM v$system_event
ORDER BY time_waited DESC;

— to review tablespaces
SELECT tablespace_name,
SUM(bytes) / 1024 / 1024 AS total_mb,
SUM(maxbytes) / 1024 / 1024 AS max_mb,
(SUM(bytes) / SUM(maxbytes)) * 100 AS used_pct
FROM dba_data_files
GROUP BY tablespace_name;

— to review blocks
SELECT owner, table_name, num_rows, blocks, empty_blocks, avg_row_len
FROM dba_tables
WHERE owner NOT IN (‘SYS’, ‘SYSTEM’)
ORDER BY blocks DESC;

— to review redologs
SELECT GROUP#, STATUS, MEMBERS, ARCHIVED, FIRST_CHANGE#, NEXT_CHANGE#
FROM V$LOG;

— to see size of archivelogs
SELECT SUM(BLOCKS * BLOCK_SIZE) / 1024 / 1024 AS total_mb
FROM V$ARCHIVED_LOG;
according to the mentioned details, please give me a perfect title for this article

Comments are closed.