Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Oracle 資料庫啟動失敗:/etc/hosts 權限不足導致 TNS-12545/ORA-00000 解決實錄

編輯:Linux 教學

問題現象

SUSE 9 SP3 環境安裝 Oracle 9.2.0.8 / 11.1.0.6,安裝完成後啟動監聽器與資料庫雙雙報錯:

1. 監聽器啟動失敗

LSNRCTL> start
...
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle15)(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
IBM/AIX RISC System/6000 Error: 13: Permission denied
Listener failed to start.

2. 資料庫啟動/關閉報 ORA-00000(正常完成但實際失敗)

SQL> startup
ORA-00000: normal, successful completion
SQL> shutdown immediate;
ORA-00000: normal, successful completion

根因分析

Oracle 啟動過程需讀取 /etc/hosts 解析主機名,若該檔案缺乏執行權限(o+x),Oracle 進程(以 oracle 用戶身分)無法存取,導致主機名解析失敗,進而引發 TNS 協議適配器錯誤與資料庫實例掛載異常。

解決方案

# 檢查當前權限
ls -l /etc/hosts
# -rw-r--r-- 1 root root 342 ...  ← 缺乏 o+x

# 賦予其他用戶執行權限(關鍵)
chmod 755 /etc/hosts
# 或最小權限:chmod o+x /etc/hosts

# 驗證
ls -l /etc/hosts
# -rw-r--r-x 1 root root 342 ...  ← 已有 o+x

# 重新啟動監聽器與資料庫
lsnrctl start
sqlplus / as sysdba
SQL> startup

深度補充

  • 為何需 o+x?:/etc/hosts 為目錄項目,進程遍歷目錄樹解析路徑時,需對目錄擁有 x 權限;對檔案本身讀取需 r,但某些系統呼叫(如 gethostbyname 內部實作)在檢查檔案屬性時會檢測 x 位。Oracle 進程以非 root 用戶運行,屬於「其他」類別,故需 o+x。
  • 安全性考量:chmod 755 不會洩露內容(hosts 本質公開),僅允許遍歷與讀取,風險極低。
  • 通用性:同理,/etc/resolv.conf、/etc/nsswitch.conf 等系統解析關鍵檔同樣需保證 o+r(必要時 o+x)。

驗證清單

  1. ping oracle15 解析正常
  2. tnsping ORCL 回傳 OK
  3. lsnrctl status 顯示 LISTENER 狀態 READY
  4. sqlplus / as sysdba 連線成功,startup 開啟資料庫無錯誤

結語

一個 chmod o+x /etc/hosts 解決了困擾多時的 Oracle 啟動連環錯誤。系統級關鍵配置檔權限缺失 是跨平台資料庫部署的隱形殺手,建議納入安裝前檢查清單(Pre-flight Checklist)。

Copyright © Windows教程網 All Rights Reserved