12.1.0.2之前,用startup trigger:
1 2 3 4 5 6 7 8 |
--在CDB中建立startup trigger CREATE TRIGGER open_all_pdbs AFTER STARTUP ON DATABASE BEGIN EXECUTE IMMEDIATE 'alter pluggable database all open'; END open_all_pdbs; / |
12.1.0.2之后,用PDB save state
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
下面的命令可以放pdb保持其关机前的状态,语法如下: ALTER PLUGGABLE DATABASE [all]|[PDB_NAME] SAVE STATE; 取消设置的话,语法如下: ALTER PLUGGABLE DATABASE [all]|[PDB_NAME] DISCARD STATE; 如: alter pluggable database pdbrac1 save state; alter pluggable database all discard state; 注意,savle state只是抓取当前的状态进行save,如果当前状态是mount,然后save state了。然后在open all pdb,再重启cdb,重启后只是会恢复到open all pdb之前的状态,即save state时的状态。 SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> SQL> startup ORACLE instance started. Total System Global Area 1560281088 bytes Fixed Size 2924784 bytes Variable Size 1056968464 bytes Database Buffers 486539264 bytes Redo Buffers 13848576 bytes Database mounted. Database opened. SQL> --最初时,2个pdb启动后状态都是mounted的。 SQL> select NAME,OPEN_MODE from v$pdbs; NAME OPEN_MODE ------------------------------ ---------- PDB$SEED READ ONLY PDBRAC1 MOUNTED PDBRAC2 MOUNTED SQL> alter pluggable database PDBRAC1 open; Pluggable database altered. SQL> alter pluggable database pdbrac1 save state; Pluggable database altered. SQL> SQL> SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> SQL> SQL> SQL> startup ORACLE instance started. Total System Global Area 1560281088 bytes Fixed Size 2924784 bytes Variable Size 1056968464 bytes Database Buffers 486539264 bytes Redo Buffers 13848576 bytes Database mounted. Database opened. SQL> SQL> SQL> --save state之后,PDBRAC1就是随cdb一起启动了。 SQL> select NAME,OPEN_MODE from v$pdbs; NAME OPEN_MODE ------------------------------ ---------- PDB$SEED READ ONLY PDBRAC1 READ WRITE PDBRAC2 MOUNTED SQL> SQL> --如果是先save state,在open all,那么记录的状态只是在open all 之前的。 SQL> alter pluggable database all save state; Pluggable database altered. SQL> alter pluggable database all open; Pluggable database altered. SQL> SQL> SQL> SQL> SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> SQL> SQL> SQL> startup ORACLE instance started. Total System Global Area 1560281088 bytes Fixed Size 2924784 bytes Variable Size 1056968464 bytes Database Buffers 486539264 bytes Redo Buffers 13848576 bytes Database mounted. Database opened. SQL> SQL> --因此重启cdb之后,也只是恢复save state时候的状态,即open all之前的,只有PDBRAC1打开的状态。 SQL> select NAME,OPEN_MODE from v$pdbs; NAME OPEN_MODE ------------------------------ ---------- PDB$SEED READ ONLY PDBRAC1 READ WRITE PDBRAC2 MOUNTED SQL> |