查看归档日志是否打开
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;
增加用户表空间文件
alter tablespace users add datafile '/home/u01/app/oracle/oradata/orcl/users04.dbf' size 10240m autoextend on next 500m maxsize unlimited; unlimited最大支持32G
查询表空间数据文件使用情况 https://blog.csdn.net/michaelzhou224/article/details/20688365
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 {} \;