在 Linux 環境管理 Oracle,必須以 oracle 作業系統使用者身分操作。本文整理資料庫實例與監聽器的啟停、狀態查詢標準指令,附實際輸出範例。
su - oracle
# 或
sudo -u oracle -i
sqlplus /nolog
CONNECT / AS SYSDBA
STARTUP
輸出關鍵階段:ORACLE instance started → Database mounted → Database opened。
sqlplus /nolog
CONNECT / AS SYSDBA
SHUTDOWN IMMEDIATE -- 正常關閉,等待交易完成
-- 或
SHUTDOWN ABORT -- 緊急關閉,啟動時需執行實例復原
建議:例行維護用 IMMEDIATE 或 TRANSACTIONAL;僅在系統掛死時用 ABORT。
lsnrctl start
lsnrctl stop
lsnrctl status
# 或進入互動模式
lsnrctl
LSNRCTL> status
LSNRCTL> exit
LSNRCTL for Linux: Version 19.0.0.0.0 - Production
Starting /u01/app/oracle/product/19.0.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/host/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host.example.com)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host.example.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 2024-01-15 10:30:00
Uptime 0 days 0 hr. 0 min. 5 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/host/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host.example.com)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
| 指令 | 用途 |
|---|---|
| start / stop | 啟動/停止監聽器 |
| status / services | 狀態 / 服務登記詳情 |
| reload | 重新讀取 listener.ora 不中斷連線 |
| change_password | 設定監聽器管理密碼 |
| save_config | 將執行時期修改寫回 listener.ora |
| trace / set trc_level | 啟用追蹤除錯 |
確認 $ORACLE_HOME、$ORACLE_SID、$PATH 包含 $ORACLE_HOME/bin,否則指令找不到或連線錯誤。