小言_互联网的博客

一线运维 DBA 五年经验常用 SQL 大全(二)

670人阅读  评论(0)

作者 | JiekeXu

来源 | JiekeXu之路(ID: JiekeXu_IT)

转载请联系授权 | (微信ID:JiekeXu_DBA)

大家好,我是 JiekeXu,分开这么久,很高兴又和大家见面了,祝大家新年快乐,牛气冲天发大财,欢迎点击上方蓝字关注我,标星或置顶,更多干货第一时间到达!

本文 SQL 及相关命令均是在运维工作中总结整理而成的,对于运维 DBA 来说可提高很大的工作效率,值得收藏。当然如果你全部能够背下来那就很牛逼了,如果不能,还是建议收藏下来慢慢看,每条 SQL 的使用频率都很高,肯定能够帮助到你。

当然,由于本编辑器原因以下 SQL 可能出现格式错误不能执行,导致出错,这里将其保存至文本文件中方便复制粘贴执行,如有需要的小伙伴们在本公众号后台回复【SQL大全二】 即可获取,这里也有 2020 年的精华文章汇总,如有需要可点击此处查看【精华文章】

1、查看数据文件信息:


   
  1. col file_name for a55
  2. select tablespace_name,file_name, bytes/ 1024/ 1024/ 1024 gb,AUTOEXTENSIBLE
  3. from dba_data_files where tablespace_name= 'AM_DATA';
  4. alter tablespace AM_DATA add datafile '+DATA' size 30G;

2、查看 ASM 磁盘组信息:


   
  1. su - grid
  2. sqlplus / as sysasm
  3. select group_number, name,total_mb/ 1024 total_gb,free_mb/ 1024 free_gb, TYPE
  4. from v$asm_diskgroup;
  5. ---调整ASM磁盘均衡级别
  6. ALTER  DISKGROUP  DATA REBALANCE  POWER  10
  7. ---查看ASM磁盘均衡时间:
  8. select * from v$asm_operation;

3、查看 ASM 磁盘组磁盘的信息


   
  1. set lin 1000 pagesize 999
  2. col PATH for a33
  3. col NAME for a15
  4. col FAILGROUP for a15
  5. select GROUP_NUMBER,DISK_NUMBER,TOTAL_MB/ 1024,FREE_MB/ 1024, NAME,FAILGROUP, PATH,FAILGROUP_TYPE
  6. from v$asm_disk  where GROUP_NUMBER= '1';

4、查看表空间大小:


   
  1. SELECT a.tablespace_name, round(total/ 1024/ 1024/ 1024) "Total g",
  2. round(free/ 1024/ 1024/ 1024) "Free g", ROUND((total-free)/total, 4)* 100 "USED%"
  3. FROM ( SELECT tablespace_name, SUM( bytes) free FROM
  4. DBA_FREE_SPACE
  5. GROUP BY tablespace_name ) a,
  6. ( SELECT tablespace_name, SUM( bytes) total FROM DBA_DATA_FILES
  7. GROUP BY tablespace_name) b
  8. WHERE a.tablespace_name=b.tablespace_name
  9. ORDER BY 4;

5、查某个表空间内的前五个大表


   
  1. col TABLE_NAME for a30
  2. set pagesize 200
  3. set linesize 200
  4. col TABLE_NAME for a30
  5. set linesize 200
  6. select *  from ( select TABLESPACE_NAME,OWNER,SEGMENT_NAME  "TABLE_NAME",to_number( decode( substr( BYTES/ 1024/ 1024, 1, 1), '.', '0'|| BYTES/ 1024/ 1024, BYTES/ 1024/ 1024)) total_MB
  7. from dba_segments where TABLESPACE_NAME = '&tablespacename' and SEGMENT_TYPE= 'TABLE' order by total_MB desc ) where rownum<= 5;
  8. SELECT *  FROM ( SELECT OWNER,SEGMENT_NAME,  SUM( BYTES) /  1024 /  1024 MB  FROM DBA_SEGMENTS  WHERE TABLESPACE_NAME =  'SYSTEM'  GROUP  BY SEGMENT_NAME,OWNER   ORDER  BY  3  DESCWHERE  ROWNUM <= 5;
  9. OWNER SEGMENT_NAME MB
  10. ------------------------------ --------------------------------------------------------------------------------- ----------
  11. SYS XX_RECNAME_RB_IX 11136
  12. SYS XXXXX_ORIGINNOTE_IX 9152
  13. SYS XXXXX_ABSTRACT_IX 6388
  14. SYS XXX_PAYDATE_NU_NC 5490
  15. SELECT OWNER,SEGMENT_NAME ,segment_type FROM DBA_SEGMENTS WHERE segment_name in ( 'PAYMENTS_RECNAME_RB_IX', 'XXXXX_ORIGINNOTE_IX', 'XXXXX_ABSTRACT_IX', 'XXX_PAYDATE_NU_NC');
  16. OWNER SEGMENT_NAME SEGMENT_TYPE
  17. ------------------------------ --------------------------------------------------------------------------------- ------------------
  18. SYS XXX_PAYDATE_NU_NC INDEX
  19. SYS XXXXX_ORIGINNOTE_IX INDEX
  20. SYS XXXXX_ABSTRACT_IX INDEX
  21. SYS XXXMENTS_RECNAME_RB_IX INDEX

6、查看 shared_pool 的大小


   
  1. select sum( bytes)/ 1024/ 1024/ 1024 from v$sgastat where pool= 'shared pool';
  2. --查看空闲的:
  3. select * from v$sgastat where name = 'free memory' and pool = 'shared pool';
  4. --统计活动的undo
  5. select sum( bytes /( 1024* 1024* 1024)) from dba_undo_extents where status= 'ACTIVE';

7、查看占用内存 100k 的 sql 语句:

select sql_text ,sharable_mem from v$sql where sharable_mem > '100000' order by sharable_mem;

8、查看字符集


   
  1. select userenv( 'language') from dual;
  2. select * from nls_database_parameters;

9、Oracle 查询 temp 表空间的名字和位置


   
  1. select tablespace_name,file_name from dba_temp_files;
  2. col FILE_NAME for a55
  3. select TABLESPACE_NAME,FILE_NAME, BYTES/ 1024/ 1024/ 1024 total_gb,USER_BYTES/ 1021/ 1024/ 1024 gb from dba_temp_files;
  4. create temporary tablespace temp1 tempfile '/rhzxdata/tempdata/pbc/temp01.dbf' size 20G autoextend on maxsize 30G
  5. Oracle查询 temp 表空间的使用率
  6. select tablespace_name, round(free_space/ 1024/ 1024/ 1024, 2) "free(GB)", round(tablespace_size/ 1024/ 1024/ 1024, 2) "total(GB)", round(nvl(free_space, 0)* 100/tablespace_size, 3) "Free percent"
  7. from dba_temp_free_space;
  8. 注意:Primary 端涉及到的临时表空间创建维护、临时文件创建的操作是不会传导到 standby 端的。

10、查看数据库版本


   
  1. set line 150
  2. col ACTION_TIME for a30
  3. col ACTION for a8
  4. col NAMESPACE for a8
  5. col VERSION for a10
  6. col BUNDLE_SERIES for a5
  7. col COMMENTS for a20
  8. select * from dba_registry_history;

======================================================

本文 SQL 命令由于微信编辑器原因可能出现格式错误不能执行,这里将其保存至文本文件中方便复制粘贴执行,如有需要的小伙伴们在本公众号【JiekeXu DBA之路】扫描最下方二维码后台回复 【SQL大全二】即可获取。

=======================================================

11、查看补丁版本:

JIEKED2:/app/product/11.2.0/db/OPatch$opatch lsinventory

12、查看锁表


   
  1. SELECT l.session_id sid, s.serial #, l.locked_mode,l.oracle_username,
  2. l.os_user_name,s.machine, s.terminal, o.object_name, s.logon_time
  3. FROM v$locked_object l, all_objects o, v$ session s
  4. WHERE l.object_id = o.object_id
  5. AND l.session_id = s.sid
  6. ORDER BY sid, s.serial # ;
  7. 查出锁定表的 sessionsid, serial #,os_user_name, machine name, terminal 和执行的语句:
  8. SELECT l.session_id sid, s.serial #, l.locked_mode, l.oracle_username, s.user#,
  9. l.os_user_name,s.machine, o.object_name,s.terminal,a.sql_text, a.action
  10. FROM v$sqlarea a,v$ session s, v$locked_object l,all_objects o
  11. WHERE l.session_id = s.sid
  12. AND s.prev_sql_addr = a.address
  13.   ORDER  BY  sid, s.serial #;

13、查看视图对应的表:

select * from dba_dependencies where NAME='视图名' and TYPE='VIEW';

14、杀会话命令

alter system kill session 'sid,serial#';

15、查看表大小


   
  1. select TABLESPACE_NAME,OWNER,SEGMENT_NAME, sum( BYTES)/ 1024/ 1024 total_mb
  2. from dba_segments where TABLESPACE_NAME= 'NEWCAR02'
  3. group by TABLESPACE_NAME,OWNER,SEGMENT_NAME;

16、查看 GI 兼容版本

 select name,compatibility,database_compatibility from  v$asm_diskgroup;

17、查看aix操作系统的资源情况


   
  1. prtconf|more
  2. lparstat -i
  3. ortconf
  4. AIX 磁盘扫描命令
  5. root 执行
  6. cfgmgr -v
  7. --查看那个进程占用磁盘空间
  8. fuser -dV /app
  9. AIX 查看错误日志并输出到 messages
  10. JIekeXuY1: /#errpt -dH
  11. IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION
  12. DE3B8540 1012214419 P H hdisk18 PATH HAS FAILED
  13. 4B436A3D 1012214119 T H fscsi0 LINK ERROR
  14. 4B436A3D 1012214119 T H fscsi0 LINK ERROR
  15. 4B436A3D 1012214119 T H fscsi0 LINK ERROR
  16. /bin/errpt -a > messages.out
  17. AIX查看LUNID信息
  18. lscfg -vpl hdisk187 输出结果里的 serial number就是存储要的lunid
  19. # lscfg -vpl hdisk11
  20.   hdisk11          U9080.MME.680A6E8-V7-C2-T1-W500507680C25ADBA-LB000000000000  MPIO FC 2145
  21. Manufacturer................IBM
  22. Machine Type and Model......2145
  23. ROS Level and ID............0000
  24. Device Specific.(Z0)........0000063268181002
  25. Device Specific.(Z1)........0203202
  26.         Serial Number...............600507680C808570080000000000042B
  27. PLATFORM SPECIFIC
  28. Name: disk
  29. Node: disk
  30.     Device Type:   block  


   
  1. --- 检查磁盘大小(单位M)
  2. bootinfo -s hdisk12
  3. --- 查看磁盘的详细信息
  4. lsattr -El hdisk12
  5. HP:machinfo
  6. (diskinfo /dev/rdisk/disk*  查看磁盘大小)
  7. WIN:msinfo32
  8. SUSE:cat /proc/cpuinfo  (model name )
  9. ---查看资源使用情况:
  10. HP:glance/top
  11. AIX:nmon/topas
  12. --AIX查看版本号
  13. oslevel
  14. JIEKEXuR2:/app/product/11.2.0/grid/network/log$oslevel
  15. 6.1.0.0
  16. ---查看内存大小:
  17. HP:/usr/contrib/bin/machinfo | grep -i Memory
  18. AIX: /usr/sbin/lsattr -E -l sys0 -a realmem
  19. ---查看swap分区:
  20. HP:/usr/sbin/swapinfo -a
  21. AIX:/usr/sbin/lsps -s

18、用户相关操作


   
  1. select USERNAME,DEFAULT_TABLESPACE,TEMPORARY_TABLESPACE from dba_users;
  2. create user agriproduct identified by product default tablespace users;
  3. grant conncet, resource, create view to product;
  4. --解锁用户
  5. set linesize 500
  6. col USERNAME for a15
  7. col ACCOUNT_STATUS for a15
  8. select USERNAME,ACCOUNT_STATUS,LOCK_DATE,EXPIRY_DATE,DEFAULT_TABLESPACE from dba_users where USERNAME = 'SQLMON';
  9. alter user SQLMON identified by "SQLMON" account unlock;
  10. alter user SQLMON account unlock;
  11. alter user SQLMON identified by "SQLMON";
  12. conn SQLMON/SQLMON
  13. #查看用户具有的权限
  14. 1、查询用户有哪些角色:
  15. select * from dba_role_privs where grantee= '&username';
  16. 2、查询角色包含哪些权限:
  17. select * from role_sys_privs where role= '&role';
  18. 3、查询用户系统权限:
  19. select * from dba_sys_privs where grantee= '&username';
  20. select * from dba_tab_privs where grantee= '&username';
  21. --创建 dblink 权限
  22. grant create database link to user ;
  23. grant create public database link to user ;
  24. 删除用户: drop user XXX cascade;
  25. 解锁用户
  26. alter user muar_rb account unlock identified by & PASSWORD;
  27. 查看表空间下的用户
  28. select distinct s.owner from dba_segments s where s.tablespace_name = '&TBSNAME'

19、查看数据量:

select sum(bytes)/1024/1024/1024 Gb from dba_segments;

20、查看 REDOLOG 大小

select group#,members,bytes/1024/1024,status from v$log; 

21、清理垃圾文件


   
  1. cd &DIR
  2. find ./ -ctime +3 |xargs rm
  3. 查看大于1024M的文件
  4. find / -type f -size +1024M -print0 | xargs -0 du -h | sort -nr

22、AIX 操作系统下 ASM 磁盘相关操作


   
  1. --- 检查磁盘大小(单位M)
  2. bootinfo -s hdisk0
  3. --- 查看磁盘的详细信息
  4. lsattr -El hdisk0
  5. JIEKEXu:/dev#lsattr -El /dev/hdisk322
  6. lsattr: 0514-519 The following device was not found in the customized
  7. device configuration database:
  8. /dev/hdisk322
  9. JIEKEXu:/dev#su - grid
  10. JIEKEXu:/home/grid$kfed read /dev/rhdisk322
  11. kfbh.endian: 0 ; 0x000: 0x00
  12. kfbh.hard: 130 ; 0x001: 0x82
  13. kfbh.type: 1 ; 0x002: KFBTYP_DISKHEAD
  14. kfbh.datfmt: 1 ; 0x003: 0x01
  15. kfbh.block.blk: 0 ; 0x004: blk=0
  16. kfbh.block.obj: 2147483953 ; 0x008: disk=305
  17. kfbh.check: 3956950460 ; 0x00c: 0xebda45bc
  18. kfbh.fcn.base: 2632 ; 0x010: 0x00000a48
  19. kfbh.fcn.wrap: 0 ; 0x014: 0x00000000
  20. --- 检查权限 hdisk是块设备,而rhdisk是字符设备。
  21. ls -l /dev/hdisk*
  22. 【排序查看ls -ltr /dev |grep rhdisk】
  23. 运行命令lsattr -E -a rw_timeout -F value -l Name,查看rw_timeout的值。
  24. JIEKEY1:/app/grid/diag/asm/+asm/+ASM1/trace$lsattr -E -a rw_timeout -F value -l hdisk16
  25. 60
  26. --- 检查PVID
  27. lspv | grep hdiskn
  28. --- 检查保留策略
  29. lsattr -E -l hdisk5 | grep reserve_policy  
  30. --- 查看磁盘是否为共享磁盘
  31. lsattr -El hdisk0
  32. 比对两个主机对应的磁盘号是否一致:unique_id
  33. --- 查看磁盘是否可用
  34. lspv
  35. 看PVID是否为none,若为none则数据库可用,再查看数据库当前有没有使用,若没有则可用来扩容ASM磁盘组

23、AIX 下按用户查看占用多少内存              


   
  1. svmon -U grid -w |more
  2. svmon -U oracle -w | more

24、AIX 下查看用户下有多少进程


   
  1. svmon -PO unit=GB |grep aioserver |wc
  2. svmon -PO unit=GB |grep oracle |wc
  3. lsvg |lsvg -i -p
  4. lsdev -c disk

25、查看服务器底层用的存储类型:

lscfg -vpl hdisk40

26、生成AWR报告


   
  1. -----某个节点的 AWR
  2. @?/rdbms/admin/awrrpti.sql
  3. -----AWR报告
  4. @?/rdbms/admin/awrrpt.sql
  5. -- AWR 两个时间段的比较报告
  6. @?/rdbms/admin/awrddrpt.sql
  7. -----ASH报告
  8. @$ORACLE_HOME/rdbms/admin/ashrpt.sql
  9. -----细粒度的 ASH (Enter value for slot_width:1)slot 槽为 1 的 ASH
  10. @$ORACLE_HOME/rdbms/admin/ashrpti.sql
  11. 关于physical reads ,db block gets 和 consistent gets 这三个参数之间有一个换算公式:
  12. 数据缓冲区的使用命中率=1 - ( physical reads / (db block gets + consistent gets) )。
  13. 用以下语句可以查看数据缓冲区的命中率:
  14. SELECT  namevalue  FROM v$sysstat  WHERE  name  IN ( 'db block gets''consistent gets', 'physical reads');
  15. 查询出来的结果 Buffer Cache 的命中率应该在 90% 以上,否则需要增加数据缓冲区的大小。

27、查看ASM磁盘挂载时间:


   
  1. set lines 500 pages 2000
  2. col g_name format a10
  3. col g_n format 99
  4. col d_n format 999
  5. col m_status format a7
  6. col mo_status format a7
  7. col h_status format a11
  8. col name format a20
  9. col path format a20
  10. col failgroup format a15
  11. select g.group_number g_n,
  12. g.disk_number d_n,
  13. g.name name,
  14. g.failgroup,
  15. g.mount_status m_status,
  16. g.header_status h_status,
  17. g.mode_status mo_status,
  18. g.path ,
  19. to_char(g.mount_date, 'YYYY/MM/DD HH24:MI:SS') m_date
  20. from v$asm_disk g
  21. order by g_n, d_n

28、查看某个用户所拥有的角色

select * from dba_role_privs where grantee='JKX_NEW_QRY ';

29、查看某个角色所拥有的权限


   
  1. select * from dba_sys_privs where grantee= 'SKDATA';
  2. select *  from DBA_TAB_PRIVS  where grantee= 'SKDATA';

30、修改 LINUX 操作系统 /dev/shm 文件系统大小


   
  1. 开机自启动:
  2. tmpfs /dev/shm tmpfs defaults,size=20G 0 0
  3. 立即生效:
  4. mount -t tmpfs shmfs -o size=20g /dev/shm

31、trace 追踪监听文件


   
  1. $ ps aux |sort -rnk3 |more
  2. 侦听器进程的Pstack / Truss / Strace / Tusc 注意110888.1如何跟踪Unix系统调用
  3. Pstack <PID_of_listener>
  4. Sun:truss -aefdDo /tmp/truss-lsnr.log -p <PID_of_listener>
  5. Linux:strace -frT -o /tmp/strace-lsnr.log -p <PID_of_listener>
  6. HP:tusc -aef -o /tmp/tusc-lsnr.log -T“%H:%M:%S” -p <PID_of_listener>

32、删除当前目录下十天前 *.dmp 文件  

find ./ -name '*.dmp' -mtime +10 -exec rm -f {}

33、dds 同步软件


   
  1. su - ddsdt 用户,vshmt -c 可以看到同步情况
  2. /ddssoftware/ddt/ddsdt/bin/dds_pput -x
  3. DDS同步软件 类似于OGG的同步软件
  4. 10.10.19X.XXX localhost
  5. 10.10.19X.XX JiekeADG
  6. JiekeADG: /app/oracle/diag/rdbms/picccash/picccash/trace$
  7. hostname: /#su - ddsdt
  8. JiekeADG: /ddssoftware/ddt/ddsdt/dt$vshmt -c
  9. SHM:
  10. SHM-VER : Ver2.13.009
  11. type : T
  12. MULTI_SOURCE : 1
  13. size : 34675744
  14. SystemStat : Normal
  15. OracleLoginStr : ddsdt/ddsdt
  16. DB-Charset : 852
  17. DB-N-Charset : 2000
  18. Conv-Charset : 0
  19. AuthStr : ddsdt/ddsdt
  20. DDS_DATA : /ddssoftware/ddt/ddsdt/dt
  21. Audit : No
  22. QueueCount : 2
  23. comm_param : TCP:10.10.19X.XX:7915
  24. Source : TCP:10.10.19X.XXX:7910
  25. SourceWebport : 8303
  26. SizeLogFile : 104857600
  27. ReserveTableCNT: 50
  28. put_retry_cnt : 3
  29. alarm_wait_dtf : 300
  30. has_split_rids : 0
  31. large_table_blo: 1000
  32. lob_piece_len : 8388608
  33. RM_Blk_Count : 128
  34. PutData : InQueue: 0:0 PutOK: 12510654:945115120084
  35. HisData : InQueue: 0:0 PutOK: 8893:87198847301
  36. ChkData : InQueue: 0:0 PutOK: 0:0
  37. AudData : InQueue: 0:0 PutOK: 0:0
  38. dbfInASM : 1
  39. DELAY : 0
  40. DML_MODE : RowID
  41. PackBak : 5
  42. Modules : 0x87
  43. DDS_RB_HOURS : 0
  44. MachineTime : 20190904182630
  45. inode-log : 294
  46. inode-err : 281
  47. DISK-REMAIN(MB): 512
  48. restart_mem(MB): 256
  49. DDS_LOBDIR :
  50. sem_count : 121
  51. sem_pput : 8
  52. sem_pput_h : 40
  53. sem_pput_v : 72
  54. sem_pput_cmt : 89
  55. max_num_pput : 32
  56. max_num_pput_h : 32
  57. max_num_pput_v : 16
  58. max_num_pput_a : 1
  59. adjust_op : 0
  60. index_retry_cou: 0
  61. index_retry_del: 60
  62. SyncTime0 : 2018/07/26 00:35:05
  63. SCN-PUT00 : SCN-0x83d659c71 SUB:0 Time:2019/09/04 10:29:57
  64. SCN-PUT01 : SCN-0x83d659c71 SUB:0 Time:2019/09/04 10:29:57
  65. StopPutIncremen: Normal, Load Increments
  66. StopCreateIndex: Normal, Load Indexes
  67. Total : IRP-160361545 URP-1100746241 DRP-130759 DDL-7 TXN-593096960
  68. DelayTime : MIN-28591 MAX-1353324 AVG-229
  69. PUT-NO-CUR : 136533
  70. put0 : 6296809/6296809
  71. put1 : 6296809/6296809
  72. his0 : 12033/12033 ATS001
  73. WaitCommit : 0-N 1-N
  74. SRC#0 : SOURCE 10.10.19X.XXX:7910:8303
  75. JiekeADG: /ddssoftware/ddt/ddsdt/dt$

=======================================================

关于 SQL 命令还有很多,由于篇幅就先写这么多,有机会在分享。上述 SQL 命令由于微信编辑器原因断句不明显,可能出现格式错误不能执行,这里将其保存至文本文件中方便复制粘贴执行,如有需要的小伙伴们在本公众号【ID 为 JiekeXu_IT】后台回复 【SQL大全二】 即可获取。也可添加微信 ID:JiekeXu_DBA 一起学习数据库。

=======================================================

34、根据归档号从带库恢复归档日志


   
  1. rman target /
  2. run
  3. {
  4. Allocate channel t1 type 'sbt_tape' parms 'ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/bin64/tdpo.opt)';
  5. restore archivelog sequence between 63145 and 63149 thread 1;
  6. restore archivelog sequence between 62697 and 62700 thread 2;
  7. Release channel t1;
  8. }

35、JDBC 连接串

jdbc:Oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(HOST=10.1XX.XXX.XXX)(PROTOCOL=TCP)(PORT=1521))(ADDRESS=(HOST=10.1XX.XXX.XXX)(PROTOCOL=TCP)(PORT=1521)))(LOAD_BALANCE=yes)(FAILOVER=yes)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=Jieker)))

36、数据泵导入 


   
  1. impdp user/password dumpfile=temp.dmp directory=dump remap_tablespace=[old_table_space]:[new_table_space]
  2. old是指server1机器上的tablespace_name, new是指server2上的

37、切换日志打检查点,关闭实例时使用


   
  1. alter system switch logfile;
  2. alter system switch logfile;
  3. alter system checkpoint;

38、修改内存


   
  1. alter system set memory_max_target= 0 scope= spfile;
  2. alter system set memory_target = 0 scope= spfile;
  3. alter system set sga_max_size= 13G scope= spfile;
  4. alter system set sga_target= 13G scope= spfile;
  5. alter system set pga_aggregate_target= 6G scope= spfile;

###########################################################

安装数据库报错:

/bin/dd if=/var/tmp/.oracle/npohasd of=/dev/null bs=1024 count=1

$GRID_HOME/crs/install/roothas.pl -deconfig -force -verbose //GI回退 root.sh 脚本

###########################################################

39、停 oem 杀会话


   
  1. 停 oem 服务再停数据库
  2. /app/oms/bin/emctl start/stop oms
  3. Ps -ef | grep -i local= no | grep -v grep | awk '{print $2}'| xargs kill - 9

40、ASM 掉盘重新挂盘重启 crsd 进程


   
  1. su - grid
  2. crsctl query crs softwareversion --查看集群版本
  3. asmcmd
  4. lsdg
  5. mount ocr
  6. exit
  7. crsctl start res ora.crsd -init

41、Linux 6 下查看数据库有哪些 IP 连接进来


   
  1. netstat -anop | grep ESTABLISHED | awk '$4 ~/:1521/'
  2. --解压  10g 的 cpio 类型安装软件
  3. cpio -idmvc < *.cpio ----cpio解压

42、清理垃圾文件


   
  1. cd &DIR
  2. find ./ -ctime +3 |xargs rm
  3. 查看大于20M的文件
  4. find / -type f -size +20M -print0 | xargs -0 du -h | sort -nr

43、查看备库进程:


   
  1. set pages 9999
  2. set lines 200
  3. select process,client_process, sequence #,thread#,status from v$managed_standby;
  4. ---mrp0当前正在应用的日志序列
  5. select process, status, sequence # from v$managed_standby;
  6. ---查询dg应用情况
  7. set linesize 150;
  8. set pagesize 20;
  9. column name format a13;
  10. column value format a20;
  11. column unit format a30;
  12. column TIME_COMPUTED format a30;
  13. select name, value,unit,time_computed from v$dataguard_stats where name in ( 'transport lag', 'apply lag');

44、查询数据库负载 dbtime


   
  1. set pages 9999
  2. set lines 200
  3. alter session set nls_date_format= 'yyyy-mm-dd hh24:mi:ss';
  4. SELECT *
  5. FROM ( SELECT A.INSTANCE_NUMBER,
  6. A.SNAP_ID,
  7. B.BEGIN_INTERVAL_TIME + 0 BEGIN_TIME,
  8. B.END_INTERVAL_TIME + 0 END_TIME,
  9. ROUND( VALUE - LAG( VALUE, 1 , '0')
  10. OVER( ORDER BY A.INSTANCE_NUMBER, A.SNAP_ID)) "DB TIME"
  11. FROM ( SELECT B.SNAP_ID,
  12. INSTANCE_NUMBER,
  13. SUM( VALUE ) / 1000000 / 60 VALUE
  14. FROM DBA_HIST_SYS_TIME_MODEL B
  15. WHERE B.DBID = ( SELECT DBID FROM V$ DATABASE)
  16. AND UPPER (B.STAT_NAME) IN UPPER(( 'DB TIME' ))
  17. GROUP BY B.SNAP_ID, INSTANCE_NUMBER) A,
  18. DBA_HIST_SNAPSHOT B
  19. WHERE A.SNAP_ID = B.SNAP_ID
  20. AND B.DBID = ( SELECT DBID FROM V$ DATABASE)
  21. AND B.INSTANCE_NUMBER = A.INSTANCE_NUMBER)
  22. WHERE TO_CHAR(BEGIN_TIME, 'YYYY-MM-DD') = TO_CHAR( SYSDATE , 'YYYY-MM-DD')
  23. ORDER BY BEGIN_TIME;

=======================================================

本文 SQL 命令由于微信编辑器原因可能出现格式错误不能执行,这里将其保存至文本文件中方便复制粘贴执行,如有需要的小伙伴们在本公众号后台回复 【SQL大全二】即可获取,点击下方公众号即可回复。

=======================================================

45、连接数相关查看


   
  1. show parameter process
  2. --查看最大连接数
  3. select  value  from v$parameter  where  name = 'processes'
  4. --查两个节点连接数
  5. select INST_ID, count(*)  from gv$ session  group  by inst_id;
  6. --查看起库以来最大连接数
  7. select resource_name,MAX_UTILIZATION,LIMIT_VALUE from v$resource_limit where resource_name in ( 'processes', 'sessions');
  8. --查看并发连接数
  9. Select INST_ID, count(*) from gv$ session where status= 'ACTIVE' group by inst_id;
  10. --查看不同用户的连接数
  11. select username, count(username) from v$ session where username is not null group by username;

46、查当前的等待事件


   
  1. col wait_class for a20
  2. set lines 200 pages 200
  3. col event for a60
  4. select event, count(*),wait_class from v$session_wait group by event,wait_class order by 3;

47、查看归档是否有错误

select dest_name,error from v$archive_dest;

48、查看数据库运行时间


   
  1. select to_char(startup_time, 'DD-MON-YYYY HH24:MI:SS') 启动时间,
  2. TRUNC( sysdate-(startup_time))|| '天'||TRUNC( 24*(( sysdate-startup_time)-TRUNC( sysdate-startup_time)))
  3. || '小时'|| MOD(TRUNC( 1440*(( SYSDATE-startup_time)-
  4. TRUNC( sysdate-startup_time))), 60)
  5. || '分'|| MOD(TRUNC( 86400*(( SYSDATE-STARTUP_TIME)-
  6. TRUNC( SYSDATE-startup_time))), 60)
  7. || '秒' 运行时间
  8. from gv$ instance;

49、查询dg同步延迟


   
  1. select ceil(( sysdate-next_time)* 24* 60) "M"
  2. from v$archived_log
  3. where applied= 'YES'
  4. AND SEQUENCE #=
  5. ( SELECT MAX( SEQUENCE #) FROM V$ARCHIVED_LOG WHERE applied='YES');

50、查询数据库安装时间


   
  1. select a.name,to_char(a.created, 'yyyy.mm.dd'),b.instance_name
  2. from gv$ database a,gv$ instance b
  3. where a.inst_id=b.inst_id;

51、查看 sys 用户使用情况


   
  1. select b.username,h.machine,to_char(h.sample_time, 'yyyymmdd hh24:mi:ss') time, count(*)
  2. from dba_hist_active_sess_history h ,dba_users b
  3. where h.user_id=b.user_id and b.username in( 'SYSTEM', 'SYS') and h.MACHINE not in ( select host_name from gv$ instance)
  4. and h.sample_time> to_date( '20210208', 'yyyymmdd')
  5. group by b.username,h.machine,to_char(h.sample_time, 'yyyymmdd hh24:mi:ss');

52、查询 redo 每天切换次数


   
  1. select trunc(FIRST_TIME, 'dd'), count( 1)
  2. from v$log_history
  3. where trunc(FIRST_TIME, 'dd')> sysdate -10
  4. group by trunc(FIRST_TIME, 'dd')
  5. order by 1;

53、查看每天归档产生数据量 归档量


   
  1. --按天计算
  2. select trunc(FIRST_TIME, 'dd') Time, sum(BLOCKS*BLOCK_SIZE)/ 1024/ 1024/ 1024 Total_GB from v$archived_log
  3. group by trunc(FIRST_TIME, 'dd') order by 1;
  4. --按小时计算
  5. select trunc(FIRST_TIME, 'hh') Time, sum(BLOCKS*BLOCK_SIZE)/ 1024/ 1024/ 1024 Total_GB from v$archived_log
  6. group by trunc(FIRST_TIME, 'hh') order by 1;

54、redo 日志产生频率


   
  1. select a.recid,to_char(a.first_time, 'yyyy-mm-dd hh24:mi:ss') begin_time,
  2. b.recid,to_char(b.first_time, 'yyyy-mm-dd hh24:mi:ss') end_time,
  3. round((b.first_time-a.first_time)* 24* 60, 2) minutes
  4. from v$log_history a,v$log_history b
  5. where b.recid = a.recid+ 1 and to_char(a.first_time, 'yyyy-mm-dd hh24:mi:ss') >=to_char( sysdate -10, 'yyyy-mm-dd hh24:mi:ss') ;
  6. desc dba_hist_active_sess_history; ----可以查询执行过的sql的主机

55、AIX 查看僵尸进程

ps -ef | grep defunct

56、清理 LOCAL=NO 连接

ps -ef | grep LOCAL=NO | grep -v grep | awk '{print $2}' |xargs kill -9

57、AIX 系统查看错误

errpt | head -20

58、rman 查看归档备份


   
  1. rman target /
  2. list backup of archivelog all;

59、查看 rman 备份进度


   
  1. set line 200 pages 1000
  2. col MESSAGE for a60
  3. col TARGET for a20
  4. select sid, SERIAL #,TARGET,START_TIME,ELAPSED_SECONDS,TIME_REMAINING,MESSAGE,ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE"
  5. from v$session_longops
  6. where 1= 1 --and sid=2983 and SERIAL#=5
  7. and TIME_REMAINING> 0 ;

60、查询创建用户的日期


   
  1. select t.username, t.account_status, t.created, t.default_tablespace from DBA_USERS t
  2. where username= 'ABASE' order by t.created desc;

61、rman全库备份


   
  1. run {
  2. allocate channel c1 type disk ;
  3. allocate channel c2 type disk ;
  4. allocate channel c3 type disk ;
  5. allocate channel c4 type disk ;
  6. backup as compressed backupset database format '/backup/%d_%I_%s_%p.bak';
  7. backup as compressed backupset archivelog all format '/backup/%d_%I_%s_%p.arc';
  8. backup current controlfile for standby format '/backup/%d_%I_%s_%p.ctl';
  9. release channel c1;
  10. release channel c2;
  11. release channel c3;
  12. release channel c4;
  13. }

   
  1. --压缩全库备份
  2. backup database format= '/u01/app/backup/rman/eweaverstb_%s.bak' filesperset 4;
  3. run{
  4. backup as compressed backupset database format= '/u01/app/backup/ewverstb_%s.bak' plus archivelog delete input skip inaccessible;
  5. }

62、数据泵导入导出相关命令


   
  1. --expdp导入导出
  2. select * from dba_directories where directory_name ='DATA_PUMP_DIR';
  3. 如果目录过小或者不存在,则
  4. create directory expdp_dir as '/u01/app/backup/expdp_dir';
  5. grant read,write on directory expdp_dir to public;
  6. expdp \'/ as sysdba\' directory=expdp_dir dumpfile=full_bak.dmp full=y;
  7. impdp \'/ as sysdba\' directory=expdp_dir dumpfile=full_bak.dmp full=y;
  8. impdb \'/ as sysdba\' DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y;
  9. --使用 par 文件全库导出
  10. more full_expdp_query.par
  11. directory= exp_dir1
  12. logfile= full_new_exclude.log
  13. dumpfile= full_new_exclude_%U.dmp
  14. exclude= table:"in('LOG2017','LOG20210115')"
  15. query= GO.POLICYATTACHMENTS:"where createtime>=to_date('20200901','YYYYMMDD')"
  16. exclude= statistics
  17. full= y
  18. parallel= 8
  19. cluster= N
  20. nohup expdp \"/ as sysdba\" parfile= full_expdp_query.par & 
  21. --导入
  22. more full_impdp_query.par
  23. directory= imp_dir1
  24. logfile= impdp_full_query.log
  25. dumpfile= full_expdp_query_%U.dmp
  26. CLUSTER= N
  27. parallel= 8
  28. nohup impdp \"/ as sysdba\" parfile= full_impdp_query.par & 
  29. expdp \'/ as sysdba\' directory=expdp_dir dumpfile=tbs_bak.dmp tables=(XXX,XXX)
  30. expdp \'/ as sysdba\' directory= expdp_dir dumpfile=tbs_bak.dmp tables=\(PROD.SU_UALCOMPEMRESPONINFO,PROD.SU_BASICINFO,PROD.SU_SENDXML,PROD.SU_SENDXMLBATCH\) fromuser=xxx touser=xxx log=tab.log
  31. expdp \'/ as sysdba\' directory= TIF_DP  dumpfile=ATSSIX_20190808.DMP logfile=PICCATSSIX_20190809.log  fromuser=ATSSIX touser=ATS
  32. expdp \'/ as sysdba\' directory=expdp_dir dumpfile=bbruser.dmp logfile=bbruser.log fromuser=bbruser touser=bbinfo
  33. --只导出全库索引
  34. expdp \' / as sysdba \' directory=exp_dir dumpfile=index.dmp logfile=out_index.log cluster=n include=INDEX full=y
  35. Export: Release 11.2.0.3.0 - Production on Wed Feb 3 14:45:50 2021
  36. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
  37. ;;;
  38. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  39. With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
  40. Data Mining and Real Application Testing options
  41. FLASHBACK automatically enabled to preserve database integrity.
  42. Starting "SYS"."SYS_EXPORT_FULL_01": "/******** AS SYSDBA" directory=exp_dir dumpfile=index.dmp logfile=out_index.log cluster=n include=INDEX full=y
  43. Estimate in progress using BLOCKS method...
  44. Total estimation using BLOCKS method: 0 KB
  45. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/INDEX
  46. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX
  47. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
  48. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS
  49. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/BITMAP_INDEX/INDEX
  50. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/BITMAP_INDEX/INDEX_STATISTICS
  51. Master table "SYS"."SYS_EXPORT_FULL_01" successfully loaded/unloaded
  52. ******************************************************************************
  53. Dump file set for SYS.SYS_EXPORT_FULL_01 is:
  54. /oracle/soft/index.dmp
  55. Job "SYS"."SYS_EXPORT_FULL_01" successfully completed at 14:47:59
  56. SQLFILE参数
  57. 该参数可以用于impdp,主要作用是未真实在目标端执行导入的情况下,生成sql文件包含该dmp文件的所有ddl语句,使用语法为
  58. SQLFILE= [directory_object:]file_name
  59. 注意事项:
  60. 1.directory_object可以不和impdp的DIRECTORY参数不一致,如果是一样,directory_object可以省略
  61. 2.SQLFILE文件必须写入到磁盘之上,不能写入到ASM中
  62. 3.SQLFILE和QUERY参数冲突,不能同时使用
  63. --获取创建索引的 SQL
  64. impdp \' / as sysdba \' directory=exp_dir sqlfile=cre_index.sql dumpfile=index.dmp logfile=in_index.log cluster=n include=INDEX
  65. Import: Release 11.2.0.3.0 - Production on Wed Feb 3 15:06:30 2021
  66. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
  67. ;;;
  68. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  69. With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
  70. Data Mining and Real Application Testing options
  71. Master table "SYS"."SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
  72. Starting "SYS"."SYS_SQL_FILE_FULL_01":   "/******** AS SYSDBA" directory=exp_dir dumpfile=index.dmp logfile=index.log cluster=n sqlfile=cre_index.sql include=INDEX
  73. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/INDEX
  74. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX
  75. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
  76. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS
  77. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/BITMAP_INDEX/INDEX
  78. Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/BITMAP_INDEX/INDEX_STATISTICS
  79. Job "SYS"."SYS_SQL_FILE_FULL_01" successfully completed at 15:07:22
  80. --获取创建索引的 SQL 语句
  81. set pages 9999
  82. set line 9999
  83. set long 9999
  84. SELECT dbms_lob.substr(dbms_metadata.get_ddl('INDEX',INDEX_NAME,'SCOTT'))||';'
  85. from dba_indexes
  86. where owner='SCOTT';
  87. --导出序列
  88. expdp \' / as sysdba \' directory=exp_dir dumpfile=sequence.dmp logfile=out_sequence.log cluster=n include=sequence full=y
  89. --删除序列在导入
  90. set line 120 pages 9999
  91. spool drop_sequence.sql
  92. SELECT 'DROP SEQUENCE '||SEQUENCE_OWNER||'.'||SEQUENCE_NAME||';' FROM DBA_SEQUENCES WHERE SEQUENCE_OWNER='SCOTT';
  93. spool off;
  94. @drop_sequnece.sql
  95. impdp \' / as sysdba \' network_link=db_seq include=sequence
  96. --按条件导出
  97. expdp \'/ as sysdba\' directory=exp_dir1 logfile=full_query2021.log dumpfile=full_query_polic_%U.dmp TABLES=ECARGO.POLICYATTACHMENTS query=\"where createtime \>= to_date\(\'20200901\',\'YYYYMMDD\'\)\"
  98. impdp bbrinfo/8t4V~p5=Y DIRECTORY=expdp_dir dumpfile=bbruser.dmp REMAP_SCHEMA=bbruser:bbrinfo
  99. Import: Release 10.2.0.1.0 - 64bit Production on Friday, 09 August, 2019 14:43:03
  100. Copyright (C) 2003, 2005, Oracle.? All rights reserved.
  101. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
  102. With the Partitioning, OLAP and Data Mining options
  103. ORA-39001: invalid argument value
  104. ORA-39000: bad dump file specification
  105. ORA-39142: incompatible version number 3.1 in dump file "/home/oracle/PICCATSSIX_20190808.DMP"
  106. expdp \'/ as sysdba\' directory=exp_dir1 dumpfile=full_query2021_%U.dmp full=y logfile=full2021.log qurey= \"where policyattachments.createtime>= to_date('20200901','YYYYMMDD')\"
  107. impdp scott/tiger ?network_link=test1? TABLES=scott.a? directory=backup? REMAP_TABLE=a:a1 Query="'Where HIREDATE<= to_date(''31-05-1981'', ''dd-mm-yyyy'') and HIREDATE>to_date(''31-01-1981'', ''dd-mm-yyyy'') '"? logfile=test.log ;
  108. query= bi_dw.DW_MID_CONTRACT:"where data_date in(to_date('2013-11-13','yyyy-mm-dd'),to_date('2013-11-14','yyyy-mm-dd'),to_date('2013-8-13','yyyy-mm-dd'),to_date('2013-8-14','yyyy-mm-dd'))"
  109. expdp \'/ as sysdba\' directory=exp_dir1 logfile=full_query2021.log dumpfile=full_query_%U.dmp TABLES=ECARGO.POLICYATTACHMENT query=\"where createtime>= to_date('20200901','YYYYMMDD') \" parallel=8 cluster=N
  110. 源端数据库版本11.2.0.4.0,目标端数据库版本10.2.0.4.0,源端数据库版本高于目标端数据库版本,源端导出数据时加上目标端version:
  111. set lines 300
  112. col OWNER_NAME for a10
  113. col OPERATION for a15
  114. col JOB_MODE for a20
  115. col STATE for a15
  116. select * from dba_datapump_jobs;
  117. expdp wxlun/wxlun123 tables=wxlun.WXLUN_TAB01,wxlun.WXLUN_TAB02 directory=expdp dumpfile=wxlun1212.dmp logfile=wxlun1212.log version=10.2.0.4.0
  118. impdp scott/tiger directory=expdp dumpfile=wxlun1212.dmp logfile=wxlun1212.log remap_schema=wxlun:scott REMAP_TABLESPACE=wxlun:USERS
  119. --cp冷备数据文件 控制文件 参数文件 v$datafile,v$controlfile;

63、查看历史备份


   
  1. set line 200
  2. col START_TIME for a30
  3. col END_TIME for a30
  4. col status for a10
  5. select SESSION_KEY,
  6. INPUT_TYPE,
  7. STATUS,
  8. to_char(START_TIME, 'yyyy-mm-dd hh24:mi') START_TIME,
  9. to_char(END_TIME, 'yyyy-mm-dd hh24:mi') END_TIME,
  10. ELAPSED_SECONDS / 3600
  11. from v$rman_backup_job_details
  12. where to_char(START_TIME, 'yyyy-mm-dd hh24:mi') > to_char( sysdate -12, 'yyyy-mm-dd hh24:mi')
  13. order by SESSION_KEY;

64、查询数据库增量增长


   
  1. select sum(TABLESPACE_USEDSIZE)* 8/ 1024/ 1024, substr(rtime, 0, 10)
  2. from DBA_HIST_TBSPC_SPACE_USAGE
  3. where snap_id in ( select max(snap_id) from DBA_HIST_TBSPC_SPACE_USAGE group by substr(rtime, 0, 10) ) --and TABLESPACE_ID=7
  4. group by substr(rtime, 0, 10) order by 1 ;
  5. --清空SHARED_POOL缓冲
  6. ALTER SYSTEM FLUSH SHARED_POOL ;
  7. --删除已备份归档
  8. rman target /
  9. delete archivelog all backed up 1 times to device type 'sbt_tape';
  10. 关于密码错误验证延迟特性:
  11. 密码错误验证延迟,可以通过设置EVENT="28401 TRACE NAME CONTEXT FOREVER, LEVEL 1"
  12. alter system set events= '28401 trace name context forever, level 1'; ---不需要重启

65、数据库开启归档


   
  1. su - oracle
  2. sqlplus / as sysdba
  3. archive log list;
  4. 1、归档路径
  5. ①如果没有归档存放存储,需要操作系统挂载存储再继续操作
  6. ②如果归档存储存在,但并非所想存放的实际路径,可在相关存储下创建目录
  7. mkdir -p /app/oracle/arch
  8. 修改归档目录权限
  9. chown -R oracle:oinstall /app/oracle/arch
  10. ③如果归档存储存在,且路径正确,权限正确则可以直接使用
  11. 2、备份spfile文件
  12. create pfile from spfile;
  13. 3、修改归档路径到想存放的位置,如查询出的归档路径已经是正确的位置,则不需要修改。
  14. su - oracle
  15. sqlplus / as sysdba
  16. alter system set log_archive_dest_1= 'location=/app/oracle/arch' scope= spfile sid= '*';
  17. 4、重启数据库,开启/关闭归档模式(rac两个节点均关闭,使用一个节点修改,修改完成后启动另一个节点)
  18. shutdown immediate;
  19. startup mount;
  20. 5、归档模式修改:
  21. 开启归档模式:
  22. alter database archivelog;
  23. 关闭归档模式:
  24. alter database noarchivelog;
  25. alter database open;
  26. 如果为集群:需要停止两个节点,在一个节点操作完成后,拉起另一个节点,操作步骤如上,
  27. rac集群启动另一个节点:startup
  28. 6、查看数据库归档路径
  29. su - oracle
  30. sqlplus / as sysdba
  31. archive log list;
  32. 切换日志,查看归档目录下产生归档文件
  33. alter system switch logfile
  34. 7、关闭归档
  35. shutdown immediate;
  36. startup mount;
  37. --开启归档模式:
  38. --alter database archivelog;
  39. 关闭归档模式:
  40. alter database noarchivelog;

66、 RMAN 全备脚本部署


   
  1. ①RMAN全备脚本部署
  2. vi /home/oracle/full_backup.sh
  3. ORACLE_BASE=/app/oracle
  4. ORACLE_HOME=/app/product/11.2.0/db
  5. ORACLE_SID=JiekeXu1
  6. db_name=JiekeXu
  7. PATH=$PATH:$ORACLE_HOME/bin/
  8. v_date=`date +%Y%m%d`
  9. [ -d / backup/$db_name/$v_date ] || mkdir -p /app/ backup/$db_name/$v_date
  10. rman target /<<EOF > /app/ backup/$db_name/$v_date/full_$v_date.log
  11. run{
  12. allocate channel c1 device type disk;
  13. backup database format '/app/backup/%d/%T/full_%d_%T_%s_%p.bak';
  14. sql ' alter system archive log current ';
  15. sql ' alter  system  archive  log  current ';
  16. sql ' alter  system  archive  log  current ';
  17. backup archivelog all delete input format '/app/ backup/%d/%T/full_arch_%d_%T_%s_%p.bak ';
  18. backup current controlfile format '/app/ backup/%d/%T/full_controlfile_%U ';
  19. backup spfile format '/app/ backup/%d/%T/full_spfile_%d_%T_%s_%p.bak ';
  20. release channel c1;
  21. }
  22. EOF
  23. ②赋权
  24. chmod +x full_backup.sh

关于 SQL 命令还有很多,由于篇幅就先写这么多,66 条六六大顺,剩余的有机会在分享。上述 SQL 命令由于微信编辑器原因可能出现格式错误不能执行,这里将其保存至文本文件中方便复制粘贴执行,如有需要的小伙伴们在本公众号后台回复 【SQL大全二】 即可获取。

未完待续!!!


以下地址均可找到我:

————————————————————————————
公众号:JiekeXu之路
墨天轮:https://www.modb.pro/u/4347
CSDN :https://blog.csdn.net/JiekeXu
腾讯云:https://cloud.tencent.com/developer/user/5645107
————————————————————————————

Oracle 12c 及以上版本补丁更新说明及下载方法(收藏版)

一线运维 DBA 五年经验常用 SQL 大全(一)

Oracle 21C 新特性:数据泵相关新特性汇总

使用数据泵导出时遇到 ORA-27054 错误解决办法

案例|RAC 添加表空间误将数据文件放本地处理办法

11g RAC 在线存储迁移实现 OCR 磁盘组完美替换

震惊:Oracle 11gR2 RAC ADG 并没有高可用

如何通过 Shell 监控异常等待事件和活跃会话 

我的 OCM 之路|书写无悔青春追梦永不止步

Oracle 19c 之多租户 PDB 连接与访问(三)

Oracle 12C 最新补丁下载与安装操作指北

DBA 常用的软件工具有哪些(分享篇)?

深入了解 Oracle Flex ASM 及其优点

Oracle 11g 临时表空间管理

Oracle 每日一题系列合集


转载:https://blog.csdn.net/JiekeXu/article/details/113764968
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场