1. 程式人生 > >自動啟動數據庫

自動啟動數據庫

數據庫 實例 監聽 自動重啟

自動重啟,需要grid的支持

自動管理資源

[oracle@edsir1p8-+ASM ~]$ crs_stat -t
Name           Type           Target    State     Host        
------------------------------------------------------------
ora.DATA.dg    ora....up.type ONLINE    ONLINE    edsir1p8    
ora.asm        ora.asm.type   ONLINE    ONLINE    edsir1p8    
ora.cssd       ora.cssd.type  ONLINE    ONLINE    edsir1p8    
ora.diskmon    ora....on.type ONLINE    ONLINE    edsir1p8


通常2種方式自動啟動數據庫

1.

[oracle@edsir1p8-+ASM ~]$ tail -3 /etc/oratab
PROD4:/u01/app/oracle/product/11.2.0/db_1:N
EMREP:/u01/app/oracle/product/11.2.0/db_1:N
+ASM:/u01/app/oracle/product/11.2.0/grid:N
---這種方式通常不好用


2.crs_stat

這是個資源表,讓數據庫和監聽註冊到這個表裏

[oracle@edsir1p8-+ASM ~]$ srvctl add  database -d PROD4  -o /u01/app/oracle/product/11.2.0/db_1
[oracle@edsir1p8-+ASM ~]$ srvctl config database   --查看哪些數據庫已經註冊


關監聽,註冊

[oracle@edsir1p8-+ASM ~]$ srvctl add  listener -l  listener -p 1521 -o /u01/app/or
acle/product/11.2.0/db_1PRCN-2061 : Failed to add listener ora.LISTENER.lsnr
PRCN-2065 : Port(s) 1521 are not available on the nodes given
PRCN-2035 : Port 1521 is not available on node(s) or virtual host(s): edsir1p8.us.
oracle.com


--關監聽

[oracle@edsir1p8-+ASM ~]$ lsnrctl stop
[oracle@edsir1p8-+ASM ~]$ srvctl add  listener -l  listener -p 1521 -o /u01/app/oracle/pr
oduct/11.2.0/db_1
[oracle@edsir1p8-+ASM ~]$ srvctl config listener   --查看監聽是否註冊成功
[oracle@edsir1p8-+ASM ~]$ crs_stat -t
Name           Type           Target    State     Host       
------------------------------------------------------------
ora.DATA.dg    ora....up.type ONLINE    ONLINE    edsir1p8   
ora....ER.lsnr ora....er.type OFFLINE   OFFLINE              
ora.asm        ora.asm.type   ONLINE    ONLINE    edsir1p8   
ora.cssd       ora.cssd.type  ONLINE    ONLINE    edsir1p8   
ora.diskmon    ora....on.type ONLINE    ONLINE    edsir1p8   
ora.prod4.db   ora....se.type OFFLINE   OFFLINE

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

--重啟服務器,看效果

oracle@edsir1p8- ~]$ ps -ef | grep smon
oracle    5387  5106  0 09:25 pts/2    00:00:00 grep smon     --沒有實例啟動
[oracle@edsir1p8- ~]$ lsnrctl status
-bash: lsnrctl: command not found       --沒有任何的Oracle環境變量
[oracle@edsir1p8- ~]$ . oraenv
ORACLE_SID = [oracle] ? +ASM
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid is /u01/app/oracle
[oracle@edsir1p8-+ASM ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 22-JUN-2017 09:25:58
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused     --監聽沒有啟動
[oracle@edsir1p8-+ASM ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 22 09:28:48 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to an idle instance.


SQL> quit
Disconnected
[oracle@edsir1p8-+ASM ~]$ srvctl start database -d PROD4
PRCD-1027 : Failed to retrieve database PROD4
PRCR-1070 : Failed to check if resource ora.prod4.db is registered
Cannot communicate with crsd
[oracle@edsir1p8-+ASM ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 22 09:30:20 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup
ORA-01078: failure in processing system parameters
ORA-29701: unable to connect to Cluster Synchronization Service
SQL> quit
Disconnected
[oracle@edsir1p8-+ASM ~]$ crsctl start has
CRS-4123: Oracle High Availability Services has been started.
[oracle@edsir1p8-+ASM ~]$ crs_stat -t
Name           Type           Target    State     Host        
------------------------------------------------------------
ora.DATA.dg    ora....up.type ONLINE    OFFLINE               
ora....ER.lsnr ora....er.type ONLINE    ONLINE    edsir1p8    
ora.asm        ora.asm.type   ONLINE    OFFLINE               
ora.cssd       ora.cssd.type  ONLINE    OFFLINE               
ora.diskmon    ora....on.type ONLINE    ONLINE    edsir1p8    
ora.prod4.db   ora....se.type OFFLINE   OFFLINE
[oracle@edsir1p8-+ASM ~]$ crsctl enable has
CRS-4622: Oracle High Availability Services autostart is enabled.
--必須開機自啟動,只有他開機自啟動,註冊到裏面的資源才能開機自啟動

重啟服務器,看效果

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


--集群管理的方式將數據庫開

[oracle@edsir1p8-+ASM ~]$ srvctl start database -d PROD4

--執行相反操作
srvctl remove database -d PROD4    ---移除數據庫
srvctl remove listener -l listener     ---如果註冊錯誤可以使用該命令刪除

本文出自 “yangwang” 博客,請務必保留此出處http://yangwang.blog.51cto.com/10855137/1943802

自動啟動數據庫