檢視歸檔日誌是否開啟
archive log list;
檢視預設表空間
select default_tablespace from user_users;
修改預設永久表空間
alter database default tablespace tablespacename
修改零時預設表空間
alter database default temporary tablespace tablespacename
檢視所有表空間名稱
select tablespace_name from user_tablespaces;
檢視資料庫例項名
select instance_name from v$instance;
檢視資料庫服務名
select name from v$database;
查詢正在執行的oracle語句
select a.username, a.sid,b.sql_text, b.sql_fulltext from v$session a, v$sqlarea b where a.sql_address = b.address;
查詢表空間資料檔案使用情況
select
b.file_id,
b.tablespace_name,
b.bytes/1024/1024||'m',
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024||'m',
sum(nvl(a.bytes,0))/1024/1024||'m',
100 - sum(nvl(a.bytes,0))/(b.bytes)*100
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_id,b.bytes
order by b.file_id;
列出使用頻率最高的5個查詢:
select sql_text,executions
from (select sql_text,executions,
rank() over
(order by executions desc) exec_rank
from v$sql)
where exec_rank <=5;
消耗磁碟讀取最多的sql top5:
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 <=5;
找出需要大量緩衝讀取(邏輯讀)操作的查詢:
select buffer_gets,sql_text
from (select sql_text,buffer_gets,
dense_rank() over
(order by buffer_gets desc) buffer_gets_rank
from v$sql)
where buffer_gets_rank<=5;
查詢cpu使用率最高的10條語句
select * from (select sql_text,sql_id,cpu_time from v$sql order by cpu_time desc) where rownum<=10 order by rownum asc ;
select * from (select sql_text,sql_id,cpu_time from v$sqlarea order by cpu_time desc) where rownum<=10 order by rownum asc ;
占用cpu及時間最長的語句
select
a.username, a.command, a.status,
a.program, a.machine, a.client_identifier,
b.sql_text,
b.cpu_time,
b.sharable_mem,
round((b.disk_reads + b.buffer_gets)/b.executions)
as resource_cost
from
v$session a,
v$sqlstats b
where
a.sql_id = b.sql_id
and b.executions >0
and a.wait_class <> 'idle'
order by
resource_cost desc;
歸檔日誌的清理
su - oracle
rman target /
crosscheck archivelog all;
delete expired archivelog all;
delete force archivelog all completed before 'sysdate-7';(指定刪除7天前的歸檔日誌)
備份資料庫
rman target/
backup databaseplus archivelog delete input format '/dbbackup/phycal/full_%u.bak';
還原小貸資料庫:
tar -xjvf creditfull_20171214.tar.bz2 -c ./ ----解壓檔案
impdp credit/123456 directory=dpump_dir dumpfile=creditfull_20171026.dmp schemas=credit table_exists_action=replace
還原資料庫
impdp test/test directory=dmp dumpfile=creditfull_20180810.dmp logfile=export_201808102201.log schemas=credit transform=segment_attributes:n table_exists_action=replace skip_unusable_indexes=y
檢視oracle邏輯目錄
select * from dba_directories;
建立邏輯目錄
create directory dmp as '/oracle/dmp'
資料幫浦備份指令碼
#!/bin/bash
source /home/oracle/.bash_profile
time=`date "+%y%m%d"`
expdp test/test schemas=test dumpfile=creditfull_$time.dmp directory=dmp
echo $time
#mv /oralog/dmp/creditfull.dmp /oralog/dmp/creditfull_$time.dmp
mv /oralog/dmp/export.log /oralog/dmp/export_$time.log
tar cjvf /oralog/dmp/creditfull_$time.tar.bz2 /oralog/dmp/creditfull_$time.dmp
rm /oralog/dmp/creditfull_$time.dmp -rf
find /oralog/dmp/ -mtime +5 -exec rm -f {} \;
oracle 常用語句
oracle 產看表空間 select total.name tablespace name free space,total space free space used space,total space from select tablespace name,sum bytes 1024 102...
oracle常用語句
drop tablespace crm online space including contents and datafiles 刪除表空間 drop user wuliu01 cascade 刪除使用者 exp orcl file d dmp 匯出資料庫 imp orcl file e alen...
oracle 常用語句
oracle 常用語句 查詢表的大小 select t.owner,t.segment name,sum t.blocks 8 1024 m as s,t.segment type from dba segments t where t.owner user name group by t.owne...