1 正常启停流程
切换oracle帐号
1 |
[root@host-10-10-10-205 ~]# su - oracle |
执行启动操作,并查看数据库状态
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 |
[oracle@host-10-10-10-205 ~]$ sqlplus /nolog SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 19 15:25:25 2017 Copyright (c) 1982, 2005, Oracle. All rights reserved. SQL> connect /as sysdba Connected to an idle instance. SQL> startup ORACLE instance started. Total System Global Area 2147483648 bytes Fixed Size 2022144 bytes Variable Size 436208896 bytes Database Buffers 1694498816 bytes Redo Buffers 14753792 bytes Database mounted. Database opened. # 查看数据库状态 SQL> select instance_name,status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ ggbak10 OPEN # 查看数据库名称 SQL> select name from v$database; NAME --------- GGBAK10 # 查看数据库表名称 SQL> desc v$database; Name Null? Type ----------------------------------------- -------- ---------------------------- DBID NUMBER NAME VARCHAR2(9) CREATED DATE RESETLOGS_CHANGE# NUMBER |
启动监听器
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 |
[oracle@host-10-10-10-205 ~]$ lsnrctl start LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 19-OCT-2017 15:50:35 Copyright (c) 1991, 2005, Oracle. All rights reserved. Starting /opt/oracle/product/10.2.0.1/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 10.2.0.1.0 - Production System parameter file is /opt/oracle/product/10.2.0.1/network/admin/listener.ora Log messages written to /opt/oracle/product/10.2.0.1/network/log/listener.log Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host-10-10-10-205)(PORT=1521))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production Start Date 19-OCT-2017 15:50:37 Uptime 0 days 0 hr. 0 min. 0 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /opt/oracle/product/10.2.0.1/network/admin/listener.ora Listener Log File /opt/oracle/product/10.2.0.1/network/log/listener.log Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host-10-10-10-205)(PORT=1521))) Services Summary... Service "PLSExtProc" has 1 instance(s). Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully |
查看监听状态
1 2 3 4 5 6 7 |
[oracle@host-10-10-10-205 ~]$ lsnrctl LSNRCTL> status …… Service "ggbak10" has 1 instance(s). Instance "ggbak10", status READY, has 1 handler(s) for this service... The command completed successfully LSNRCTL> exit |
关闭监听
1 2 3 4 5 |
[oracle@host-10-10-10-205 ~]$ lsnrctl stop LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 19-OCT-2017 16:43:26 Copyright (c) 1991, 2005, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) The command completed successfully |
关闭监听
1 |
[oracle@host-10-10-10-205 ~]$ lsnrctl stop |
关闭数据库服务
1 2 3 4 5 6 7 |
[oracle@host-10-10-10-205 ~]$ sqlplus /nolog SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 19 16:44:27 2017 Copyright (c) 1982, 2005, Oracle. All rights reserved. SQL> connect /as sysdba Connected. SQL> shutdown abort; ORACLE instance shut down. |
2 主机名或IP变更相关
如果数据库所在虚拟机或物理机的主机名发生变更后,无法通过ping通之前的主机名称,这时启动数据库会报错:
1 2 3 4 |
SQL> connect /as sysdba Connected to an idle instance. SQL> startup ORA-00600: internal error code, arguments: [keltnfy-ldmInit], [46], [1], [], [], [], [], [] |
无法ping通主机名
1 2 |
[oracle@host-10-10-10-127 ~]$ ping host-10-10-10-127 ping: unknown host host-10-10-10-127 |
解决方法:修改hosts文件,追加当前IP和主机名
1 2 3 4 |
[root@host-10-10-10-127 ~]# vim /etc/hosts 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 10.10.10.127 host-10-10-10-127 |
这时就可以启动数据库服务了。
但是启动监听还会报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[oracle@host-10-10-10-127 ~]$ lsnrctl start LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 19-OCT-2017 17:52:49 Copyright (c) 1991, 2005, Oracle. All rights reserved. Starting /opt/oracle/product/10.2.0.1/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 10.2.0.1.0 - Production System parameter file is /opt/oracle/product/10.2.0.1/network/admin/listener.ora Log messages written to /opt/oracle/product/10.2.0.1/network/log/listener.log Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host-10-10-10-4)(PORT=1521))) TNS-12545: Connect failed because target host or object does not exist TNS-12560: TNS:protocol adapter error TNS-00515: Connect failed because target host or object does not exist Listener failed to start. See the error message(s) above... |
解决方法:更新/opt/oracle/product/10.2.0.1/network/admin/listener.ora中的主机名:
1 |
[oracle@host-10-10-10-127 ~]$ vim /opt/oracle/product/10.2.0.1/network/admin/listener.ora |
保存后就可以启动监听了:
1 2 3 4 5 |
[oracle@host-10-10-10-127 ~]$ lsnrctl start [oracle@host-10-10-10-127 ~]$ telnet host-10-10-10-127 1521 Trying 10.10.10.127... Connected to host-10-10-10-127 (10.10.10.127). Escape character is '^]'.<img src="file:///C:/Users/Admin/AppData/Local/YNote/data/zjmeixinyanzhi@163.com/99317abbc956422f84a42c6eefe4964e/wz93j%5Dfja%7Ewx.png" alt="" data-media-type="image" data-attr-org-src-id="07E8A0B57CF44A53A025664E8807CD2B" /> |
3 归档模式开启
什么是Oracle归档模式?
Oracle数据库有联机重做日志,这个日志是记录对数据库所做的修改,比如插入,删除,更新数据等,对这些操作都会记录在联机重做日志里。一般数据库至少要有2个联机重做日志组。当一个联机重做日志组被写满的时候,就会发生日志切换,这时联机重做日志组2成为当前使用的日志,当联机重做日志组2写满的时候,又会发生日志切换,去写联机重做日志组1,就这样反复进行。
如果数据库处于非归档模式,联机日志在切换时就会丢弃. 而在归档模式下,当发生日志切换的时候,被切换的日志会进行归档。比如,当前在使用联机重做日志1,当1写满的时候,发生日志切换,开始写联机重做日志2,这时联机重做日志1的内容会被拷贝到另外一个指定的目录下。这个目录叫做归档目录,拷贝的文件叫归档重做日志。数据库使用归档方式运行时才可以进行灾难性恢复。
归档日志模式和非归档日志模式的区别
- 非归档模式只能做冷备份,并且恢复时只能做完全备份.最近一次完全备份到系统出错期间的数据不能恢复;
- 归档模式可以做热备份,并且可以做增量备份,可以做部分恢复。
Oracle数据库备份对归档模式有以下要求:
- 数据库必须开启归档模式;
- 支持Oracle数据库归档日志在闪回区环境下的备份恢复,但因闪回区空间有限,请确保闪回区空间足够大并实时监控闪回区空间利用率;
- 归档路径若设置为本地路径,注意归档路径所在文件系统要有足够的空间去承载用户的数据库应用;
查看归档日志状态:
1 2 3 4 5 6 7 8 9 10 11 |
[oracle@host-10-10-10-127 ~]$ sqlplus /nolog SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 19 18:10:00 2017 Copyright (c) 1982, 2005, Oracle. All rights reserved. SQL> connect /as sysdba Connected. SQL> archive log list Database log mode No Archive Mode Automatic archival Disabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 792 Current log sequence 794 |
发现归档模式处于关闭状态,以下为开启步骤:
开启归档模式,应特别注意,在开启数据库的归档模式是需要关闭数据库的,会有一定的停机时间,需要和用户提前沟通停机时间再进行处理,切勿自行中断用户业务。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance started. Total System Global Area 2147483648 bytes Fixed Size 2022144 bytes Variable Size 436208896 bytes Database Buffers 1694498816 bytes Redo Buffers 14753792 bytes Database mounted. SQL> alter database archivelog; Database altered. SQL> alter database open; Database altered. SQL> exit |
若需要将归档路径更改为本地路径,可按照以下方式修改归档日志路径:
注意:支持归档日志在闪回区下的备份恢复,因闪回区空间有限,请确保闪回区空间足够大并实时监控闪回区空间利用率。也可将归档路径设置为本地路径,注意Oracle数据库的安装用户必须对归档路径有读写权限,同时归档路径所在的文件系统,要有足够的空间。
创建归本地档路径
1 2 3 4 5 6 7 |
[root@host-10-10-10-127 ~]# mkdir -p /oracle/arch [root@host-10-10-10-127 ~]# chmod -R 777 /oracle/arch [root@host-10-10-10-127 ~]# chown -R oracle:oinstall /oracle/arch/ [root@host-10-10-10-127 ~]# df -h /oracle/arch/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 59G 50G 5.9G 90% / |
登录数据库,修改归档路径配置
1 2 3 4 5 6 7 8 9 10 11 |
SQL> connect /as sysdba Connected. SQL> alter system set log_archive_dest_1='location=/oracle/arch' scope =both; System altered. SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /oracle/arch Oldest online log sequence 792 Next log sequence to archive 794 Current log sequence 794 |
归档路径修改成功后,可通过以下方式归档日志,检查指定路径下是否有新的归档日志生成:
1 |
SQL> alter system switch logfile; |
4 参考文档
http://liujia.blog.51cto.com/243391/125581
http://guojuanjun.blog.51cto.com/277646/295454
http://blog.csdn.net/xinteng2012/article/details/39400235
https://baike.baidu.com/item/oracle%E5%BD%92%E6%A1%A3%E6%A8%A1%E5%BC%8F
code
more code
~~~~