oracle日常诊断语句
欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 18. 清除已删除的arch log 信息 crosscheck archivelog all; delete expired archivelog all; ――――――――――――――――――――――――――――――――――――――――――――――――
欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入
18. 清除已删除的arch log 信息
crosscheck archivelog all;
delete expired archivelog all;
――――――――――――――――――――――――――――――――――――――――――――――――
19。查找等待时间最长的语句
select a.USERNAME,a.OSUSER,a.PROCESS,a.MACHINE,a.ACTION,a.sid, a.last_call_et ,b.sql_text
from v$session a
,v$sqltext b
where a.username is not null
and a.status = 'ACTIVE'
and a.sql_address = b.address
order by a.last_call_et,a.sid,b.piece ;
根据查出来的sid判断等待的对象
select owner,segment_name,segment_type
from (select p1 file#, p2 block# from v$session_wait
where sid = 284
and event in ('buffer busy waits'
,'db file sequential read'
,'db file scattered read'
,'free buffer waits')) b
,dba_extents a
where a.file_id = b.file#
and b.block# between a.block_id and (a.block_id+blocks-1);
――――――――――――――――――――――――――――――――――――――――――――――――
20. 监控索引使用
select * from V$OBJECT_USAGE where used='YES'
select * from V$OBJECT_USAGE where used='NO'
select 'alter index '||index_name||' monitoring usage;' from dba_indexes where owner='ABSYS';
――――――――――――――――――――――――――――――――――――――――――――――――
21. 查找正在执行的存储过程
create or replace procedure sys.who_is_using(obj_name varchar2) is
begin
dbms_output.enable(1000000);
for i in (SELECT distinct b.username,b.sid
FROM SYS.x$kglpn a,v$session b,SYS.x$kglob c
WHERE a.KGLPNUSE = b.saddr
and upper(c.KGLNAOBJ) like upper(OBJ_NAME)
and a.KGLPNHDL = c.KGLHDADR)
loop
dbms_output.put_line('('||to_char(i.sid)||') - '||i.username);
end loop;
end;
――――――――――――――――――――――――――――――――――――――――――――――――
22.查找全表扫描的SQL语句
Select sql_text from v$sqltext t, v$sql_plan p
Where t.hash_value=p.hash_value
And p.operation='INDEX'
And p.OPTIONS='FULL SCAN'
Order by p.HASH_VALUE, t.piece;
查找Fast Full index 扫描的Sql语句可以这样;
Select sql_text from v$sqltext t, v$sql_plan p
Where t.hash_value=p.hash_value
And p.operation='INDEX'
And p.OPTIONS='FULL SCAN'
Order by p.HASH_VALUE, t.piece;
――――――――――――――――――――――――――――――――――――――――――――――――
23.已经alter system kill session 但是没有kill干净,查找进程号
select p.addr from v$process p where pid 1
minus
select s.paddr from v$session s;
――――――――――――――――――――――――――――――――――――――――――――――――
24.10g自动收集数据
select JOB_NAME,ENABLED,state from dba_scheduler_jobs;
exec dbms_scheduler.disable('GATHER_STATS_JOB');
exec dbms_scheduler.enable('GATHER_STATS_JOB');
――――――――――――――――――――――――――――――――――――――――――――――――
25.查询有enqueue等待的事件
SELECT b.SID, b.serial#, b.username, machine, event, wait_time,
CHR (BITAND (p1, -16777216) / 16777215)
|| CHR (BITAND (p1, 16711680) / 65535) "Enqueue Type"
FROM v$session_wait a, v$session b
WHERE a.event NOT LIKE 'SQL*N%'
AND a.event NOT LIKE 'rdbms%'
AND a.SID = b.SID
AND b.SID > 8
AND a.event = 'enqueue'
ORDER BY username;
――――――――――――――――――――――――――――――――――――――――――――――――
26.如何确定哪个表空间读写频繁?
select name,phyrds,phywrts,readtim,writetim
from v$filestat a,v$dbfile b
where a.file# = b.file#
order by readtim desc
――――――――――――――――――――――――――――――――――――――――――――――――
27.在磁盘上的物理写入和读取次数上如果出现很大的差别,就表明肯定有哪个磁盘负载过多!
如果出现磁盘负载不平衡,可以通过移动数据文件来均衡文件I/O:
alter tablespace tablespace_name offline;
$cp /disk1/a.dbf /disk2/a.dbf;
alter tablespace tablespace_name rename datafile ‘/disk1/a.dbf’ to ‘/disk2/a.dbf’;
alter tablespace tablespace online;
$rm /disk1/a.dbf
――――――――――――――――――――――――――――――――――――――――――――――――
28. 查询SQL语句执行时,硬语法分析的次数
select name,value
from v$sysstat
where name like ‘parse count%’;
――――――――――――――――――――――――――――――――――――――――――――――――
29.查询SQL语句中没有帮定变量的SQL语句,按执行次数排序
SELECT SUBSTR (sql_text, 1, 40) “SQL”, COUNT (*),
SUM (executions) “TotExecs” FROM v$sqlarea WHERE executions
GROUP BY SUBSTR (sql_text, 1, 40) HAVING COUNT (*) > 20 ORDER BY 2;
――――――――――――――――――――――――――――――――――――――――――――――――
30.该项显示buffer cache大小是否合适
公式:1-((physical reads-physical reads direct-physical reads direct (lob)) / session logical reads)
执行:
select 1-((a.value-b.value-c.value)/d.value)
from v$sysstat a,v$sysstat b,v$sysstat c,v$sysstat d
where a.name=’physical reads’ and
b.name=’physical reads direct’ and
c.name=’physical r
[1] [2]

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The function in Oracle to calculate the number of days between two dates is DATEDIFF(). The specific usage is as follows: Specify the time interval unit: interval (such as day, month, year) Specify two date values: date1 and date2DATEDIFF(interval, date1, date2) Return the difference in days

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

The INTERVAL data type in Oracle is used to represent time intervals. The syntax is INTERVAL <precision> <unit>. You can use addition, subtraction, multiplication and division operations to operate INTERVAL, which is suitable for scenarios such as storing time data and calculating date differences.

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

The method of replacing strings in Oracle is to use the REPLACE function. The syntax of this function is: REPLACE(string, search_string, replace_string). Usage steps: 1. Identify the substring to be replaced; 2. Determine the new string to replace the substring; 3. Use the REPLACE function to replace. Advanced usage includes: multiple replacements, case sensitivity, special character replacement, etc.
