池偏一 | 博客 DEDICATED OPERATION AND MAINTENANCE DEVELOPMENT.
登录
X
X
  • oracle 常用命令
  • -- 查询数据库启动状态

    select status from v$instance;

    -- 查看归档内容

    su - oracle
    rman target /
    list archivelog all;

    -- 删除归档日志

    DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7'; //删除七天前的归档   
    DELETE ARCHIVELOG FROM TIME 'SYSDATE-7'; //删除七天到现在的归档

    -- 强制删除归档日志

    DELETE FORCE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7'; //删除七天前的归档   
    DELETE FORCE ARCHIVELOG FROM TIME 'SYSDATE-7'; //删除七天到现在的归档

    -- oracle 坏块处理方式:

    --- 1. 先找到坏块:

    select * from  v$database_block_corruption;

    --- 2. 备份块文件:

    rman target /
    backup validate datafile "FILE#";

    --- 3. 修复坏块文件:

    blockrecover datafile "FILE#" block "BLOCK#";

    --- 4. 修复完后并不会立即生效,需要重新备份块文件

    rman target /
    backup validate datafile "FILE#";

    --- 5. 重新打开sqlplus 查看坏块:

    select * from  v$database_block_corruption;

    -- 将undo 指向新的表空间

    alter system set undo_tablespace=UNDOTBS1 scope=both;

    --查看undo 表空间指向

    show parameter undo

    -- 查看所有被加锁的信息

    select * from v$locked_object;

    -- 查看加锁的Session_id编号

    select b.owner,b.object_name,a.session_id,a.locked_mode   from v$locked_object a,dba_objects b   where b.object_id = a.object_id;

    -- 获取sid,serial#进行解锁操作

    select b.username,b.sid,b.serial#,logon_time   from v$locked_object a,v$session b   where a.session_id = b.sid order by b.logon_time;

    -- 解锁操作

    alter system kill session'sid,serial#';

    --查看表空间对应的数据文件

    Select * FROM DBA_DATA_FILES;

    --扩展表空间数据文件

    alter database datafile '+SYSTEM2/otodb/datafile/sysaux.257.920747035' autoextend on next 8589934592  maxsize 17179869184

    --给表空间新增数据文件

    alter tablespace 表空间名 add datafile '数据文件路径' size 1000m autoextend on next 8589934592 maxsize 17179869184;

    --查看数据库表空间使用率

    select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",
    b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used" 
     from  (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name)   
     a,   (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by 
     tablespace_name)   b   where   a.tablespace_name=b.tablespace_name   order   
     by   ((a.bytes-b.bytes)/a.bytes)   desc;

    --查看数据库表空间使用大小

    select tablespace_name,megs_alloc init_sizeM,max total_sizeM,max - megs_used free_sizeM,megs_used 
    used_sizeM,round((max - megs_used) / (max + 0.001) * 100, 1) 
    free_rate from (select a.tablespace_name,round(a.bytes_alloc / 1024 / 1024, 2) megs_alloc,
    round(nvl(b.bytes_free, 0) / 1024 / 1024, 2) 
    megs_free,round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024, 2) megs_used,round(maxbytes / 1048576, 2) Max 
    from (select f.tablespace_name,sum(f.bytes) 
    bytes_alloc,sum(decode(f.autoextensible,'YES',f.maxbytes,'NO',f.bytes)) 
    maxbytes from dba_data_files f group by f.tablespace_name) a,(select f.tablespace_name, sum(f.bytes) bytes_free 
    from dba_free_space f group by f.tablespace_name) 
    b where a.tablespace_name = b.tablespace_name(+) union all select tablespace_name,round(sum(AllowUseSize_MB), 2) 
    megs_alloc,round(sum(FreeSize_MB), 2) megs_free,
    round(sum(UsedSize_MB), 2) megs_used,round(sum(MaxSize_MB), 2) max from (select d.tablespace_name,d.file_name,
    round(decode(d.autoextensible,'YES',greatest(d.maxbytes, d.bytes),
    d.bytes) / 1024 / 1024,2) MaxSize_MB,round(d.bytes / 1024 / 1024, 2) 
    AllowUseSize_MB,nvl(round((d.bytes - p.bytes_cached) / 1024 / 1024, 2),0) 
    FreeSize_MB,nvl(round(p.bytes_cached / 1024 / 1024, 2), 0) 
    UsedSize_MB from dba_temp_files  d,v$temp_extent_pool p,dba_tablespaces ts where 
    d.tablespace_name = p.tablespace_name(+) and d.file_id = p.file_id(+) and 
    d.tablespace_name = ts.tablespace_name(+)) group by tablespace_name) 
    order by 6;

    -- 查询数据库启动状态

    select status from v$instance;

    -- 查看指定表空间所有的表

    select table_name ,tablespace_name from dba_tables where tablespace_name = 'UNDOTBS2';

    -- 查看指定表空间的使用大小 MB

    SELECT ddf.file_name,ddf.bytes/1024/1024 "Sum MB" FROM Dba_Data_Files ddf  where ddf.tablespace_name = 'UNDOTBS1';


  • posted @ 2019-01-29 by 池偏一 阅读(62) 评论(0)
© 2017 池偏一 | 赣ICP备 17014207号