--日誌查詢命令:
select t.value || '/' || lower(rtrim(i.instance, chr(0))) || '_ora_' ||
p.spid || '.trc' trace_file_name
from (select p.spid
from v$mystat m, v$session s, v$process p
where m.statistic# = 1
and s.sid = m.sid
and p.addr = s.paddr) p,
(select t.instance
from v$thread t, v$parameter v
where v.name = 'thread'
and (v.value = 0 or t.thread# = to_number(v.value))) i,
(select value from v$parameter where name = 'user_dump_dest') t
--確定資料檔案可以收縮的空間及命令:
select a.file#,
a.name,
a.bytes / 1024 / 1024 currentmb,
ceil(hwm * a.block_size) / 1024 / 1024 resizeto,
(a.bytes - hwm * a.block_size) / 1024 / 1024 releasemb,
'alter database datafile ''' || a.name || ''' resize ' ||
ceil(hwm * a.block_size) / 1024 / 1024 || 'm;' resizecmd
from v$datafile a,
(select file_id, max(block_id + blocks - 1) hwm
from dba_extents
group by file_id) b
where a.file# = b.file_id(+)
and (a.bytes - hwm * a.block_size) > 0
order by 5;
----當前資料庫邏輯讀最高的10個物件
select *
from (select object_name, statistic_name, value
from v$segment_statistics
where statistic_name = 'logical reads'
order by 3 desc)
where rownum < 11;
--從v$sqlarea中查詢最占用資源的查詢
select b.username username,
a.disk_reads reads,
a.executions exec,
a.disk_reads / decode(a.executions, 0, 1, a.executions) rds_exec_ratio,
a.sql_text statement
from v$sqlarea a, dba_users b
where a.parsing_user_id = b.user_id
and a.disk_reads > 10000
order by a.disk_reads desc;
----使用頻率最高的10個查詢
select sql_text, executions
from (select sql_text,
executions,
rank() over(order by executions desc) exec_rank
from v$sql)
where exec_rank <= 10;
----消耗磁碟讀取最多的sql top 10
select disk_reads, sql_text
from (select sql_text,
disk_reads,
dense_rank() over(order by disk_reads desc) disk_reads_rank
from v$sql)
where disk_reads_rank <= 10;
--- 二進位制位址轉儲檔案號和塊號(select getbfno('') from dual):
create or replace function getbfno (p_dba in varchar2)
return varchar2
isl_str varchar2 (255) default null;
l_fno varchar2 (15);
l_bno varchar2 (15);
begin
l_fno :=
dbms_utility.data_block_address_file (to_number (ltrim (p_dba, '0x'),
'******xx'));
l_bno :=
dbms_utility.data_block_address_block (to_number (ltrim (p_dba, '0x'),
'******xx'));
l_str :=
'datafile# is:'
|| l_fno
|| chr (10)
|| 'datablock is:'
|| l_bno
|| chr (10)
|| 'dump command:alter system dump datafile '
|| l_fno
|| ' block '
|| l_bno
|| ';';
return l_str;
end;
/
Oracle 常用命令
1 檢視當前所有物件 sql select from tab 2 建乙個和a表結構一樣的空表 sql create table b as select from a where 1 2 sql create table b b1,b2,b3 as select a1,a2,a3 from a whe...
oracle常用命令
create insert delete select 建立使用者必須在sys超級管理員下 連線到超級管理員 conn sys as sysdba sys zhuangyan system zhuangyan scott tiger 查出所有 clerk 辦事員 的姓名及其部門名稱,部門的人數.找出...
oracle 常用命令
建立臨時表空間 02createtemporarytablespace os temp 03tempfile c oracle product 10.2.0 oradata os temp.dbf 04size100m 05autoextendon 06next100m maxsize 1024m ...