Ubuntu 下 lsnrctl 使用案例精选
一 环境准备与常用命令
export ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1export PATH=$PATH:$ORACLE_HOME/binlsnrctl start|stop|restart [listener_name]lsnrctl status [listener_name]lsnrctl reload [listener_name]lsnrctl services [service_name]、lsnrctl connectionslsnrctl logfile [listener_name]、tail -f $ORACLE_HOME/network/log/listener.loglsnrctl setloglevel listener_name debug、lsnrctl setenv variable valuelsnrctl processes、lsnrctl env。二 案例一 启动与验证监听器
sudo su - oraclesource ~/.bash_profile(或相应 profile)lsnrctl start(如命名监听器:lsnrctl start LISTENER)lsnrctl status,确认监听地址、端口与服务映射tail -f $ORACLE_HOME/network/log/listener.log三 案例二 多监听器管理与热更新
lsnrctl start LISTENER1、lsnrctl start LISTENER2lsnrctl status LISTENER1、lsnrctl status LISTENER2lsnrctl reload LISTENER1(不中断现有连接)lsnrctl stop LISTENER2,如需彻底移除,先停止,再删除 listener.ora 中对应条目,最后 lsnrctl start 使变更生效四 案例三 连接诊断与日志排错
lsnrctl status(关注监听地址与端口,如 1521)lsnrctl services(确认数据库服务是否已注册)tail -f $ORACLE_HOME/network/log/listener.loglsnrctl setloglevel LISTENER debug(排障后建议恢复)sqlplus sys/password@//host:1521/service as sysdba五 案例四 生产变更与回滚演练
lsnrctl status > status_before.txtlsnrctl services > services_before.txtlsnrctl stop LISTENERlsnrctl start LISTENERlsnrctl status 与 lsnrctl services 校验sqlplus sys/password@//host:1522/service as sysdbalsnrctl restart LISTENER