Oracle运维(数据库、监听、重启)
创始人
2024-06-02 19:31:22
0

一、概述

二、数据库重启

# su到oracle用户下
[root@localhost ~]# su - oracle#重启数据库
[oracle@localhost ~]$ sqlplus /nolog
SQL> conn /as sysdba
# 关闭数据库
SQL> shutdown immediate
# 数据库启动
SQL> startup
SQL> exit

shutdown有四个参数,四个参数的含义如下:

  1. Normal 需要等待所有的用户断开连接

  2. Immediate 等待用户完成当前的语句

  3. Transactional 等待用户完成当前的事务

  4. Abort 不做任何等待,直接关闭数据库

  • normal需要在所有连接用户断开后才执行关闭数据库任务,所以有的时候看起来好象命令没有运行一样!在执行这个命令后不允许新的连接

  • immediate在用户执行完正在执行的语句后就断开用户连接,并不允许新用户连接。

  • transactional 在拥护执行完当前事物后断开连接,并不允许新的用户连接数据库。

  • abort 执行强行断开连接并直接关闭数据库。

前三种方式不回丢失用户数据。第四种在不的已的情况下,不建议采用!

经常遇到的问题:

  • 权限问题,解决方法,切换到oracle用户

  • 没有关闭监听器 ,解决方法:关闭监听器

  • 有oracle实例没有关闭,解决办法:关闭oracle实例

  • 环境变量设置不全,解决办法:修改环境变量

三、监听

1、常用命令

前提:登录用户有dba权限,能够进行查看

# 查看监听状态
[oracle@scorl root]$ lsnrctl status
# 启用监听
[oracle@localhost ~]$ lsnrctl start
# 停掉lsnrctl
[oracle@localhost ~]$ lsnrctl stop# 退出oracle用户
[oracle@localhost ~]$ exit
logout
[root@localhost ~]#

2、案例

# 查看监听状态
[oracle@scorl root]$ lsnrctl statusLSNRCTL for Linux: Version 11.2.0.3.0 - Production on 18-JUL-2019 14:45:23Copyright (c) 1991, 2011, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
TNS-12541: TNS:no listenerTNS-12560: TNS:protocol adapter errorTNS-00511: No listenerLinux Error: 2: No such file or directory
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=scorl.dyedu.cn)(PORT=1521)))
TNS-12541: TNS:no listenerTNS-12560: TNS:protocol adapter errorTNS-00511: No listenerLinux Error: 111: Connection refused# 启动监听
[oracle@scorl root]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.3.0 - Production on 18-JUL-2019 14:45:32Copyright (c) 1991, 2011, Oracle.  All rights reserved.Starting /Database/oraapp/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.3.0 - Production
System parameter file is /Database/oraapp/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /Database/oraapp/oracle/diag/tnslsnr/scorl/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=scorl.dyedu.cn)(PORT=1521)))Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                18-JUL-2019 14:45:32
Uptime                    0 days 0 hr. 0 min. 17 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /Database/oraapp/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /Database/oraapp/oracle/diag/tnslsnr/scorl/listener/alert/log.xml
Listening Endpoints Summary...(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=scorl.dyedu.cn)(PORT=1521)))
Services Summary...
Service "scorl.dyedu.cn" has 1 instance(s).Instance "scorl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully# 停掉lsnrctl[oracle@localhost ~]$ lsnrctl stopLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 22-JAN-2018 08:00:14Copyright (c) 1991, 2009, Oracle. All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))The command completed successfully

这个命令会列出Oracle Net Listener的进程

 [oracle@localhost ~]$ netstat -antp | grep tnslsnr(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)tcp 0 0 192.168.241.155:1521 0.0.0.0:* LISTEN 6407/tnslsnr [oracle@localhost ~]$

四、使用plsql连接

用plsql连接到数据库,tnsnames.ora增加配置

TEST_DB155 =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.241.155)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = ORCL)))

五、更换IP

有一次Linux的ip变了以后,出现了这个

[root@localhost ~]# su - oracle[oracle@localhost ~]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 01-SEP-2018 03:38:08Copyright (c) 1991, 2009, Oracle. All rights reserved.Starting /u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionSystem parameter file is /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.oraLog messages written to /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xmlListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.241.155)(PORT=1521)))TNS-12545: Connect failed because target host or object does not existTNS-12560: TNS:protocol adapter errorTNS-00515: Connect failed because target host or object does not existLinux Error: 99: Cannot assign requested addressListener failed to start. See the error message(s) above...

进去改了下ip就好了

[oracle@localhost ~]$ vim /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora

相关内容

热门资讯

中证A500ETF摩根(560... 8月22日,截止午间收盘,中证A500ETF摩根(560530)涨1.19%,报1.106元,成交额...
A500ETF易方达(1593... 8月22日,截止午间收盘,A500ETF易方达(159361)涨1.28%,报1.104元,成交额1...
何小鹏斥资约2.5亿港元增持小... 每经记者|孙磊    每经编辑|裴健如 8月21日晚间,小鹏汽车发布公告称,公司联...
中证500ETF基金(1593... 8月22日,截止午间收盘,中证500ETF基金(159337)涨0.94%,报1.509元,成交额2...
中证A500ETF华安(159... 8月22日,截止午间收盘,中证A500ETF华安(159359)涨1.15%,报1.139元,成交额...
科创AIETF(588790)... 8月22日,截止午间收盘,科创AIETF(588790)涨4.83%,报0.760元,成交额6.98...
创业板50ETF嘉实(1593... 8月22日,截止午间收盘,创业板50ETF嘉实(159373)涨2.61%,报1.296元,成交额1...
港股异动丨航空股大幅走低 中国... 港股航空股大幅下跌,其中,中国国航跌近7%表现最弱,中国东方航空跌近5%,中国南方航空跌超3%,美兰...
电网设备ETF(159326)... 8月22日,截止午间收盘,电网设备ETF(159326)跌0.25%,报1.198元,成交额409....
红利ETF国企(530880)... 8月22日,截止午间收盘,红利ETF国企(530880)跌0.67%,报1.034元,成交额29.0...