在程序的運行中,有時候數據庫會斷開連接,然后報下面錯誤:
ORA-12519: TNS:no appropriate service handler found 可用的服務處理程序沒有找到。
1. 簡單解釋下什么是service handler,以及service handler是什么時候被調用的?
在客戶端和數據庫oracle進行通信時,oracle需要進行完成一個過程"服務注冊 (service registration)" . 服務注冊是將數據庫提供的服務名稱,實例名,可用服務處理程序,端口號等告知listener 的過程。 當客戶端的請求到達listener時,listenser將會選擇一個合適的service handlers為之服務。可用的服務處理程序(service handlers)用於調度和派生子程序。
下面是參考的一篇文章http://blog.chinaunix.net/uid-20802110-id-4153116.html
2. 排查和解決
//查看所配置的processes最大連接數量
SQL> show parameter process;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
aq_tm_processes integer 1
cell_offload_processing boolean TRUE
db_writer_processes integer 2
gcs_server_processes integer 0
global_txn_processes integer 1
job_queue_processes integer 1000
log_archive_max_processes integer 4
processes integer 550 (配置最大連接進程550)
processor_group_name string
或
SQL> select value from v$parameter where name ='processes';
VALUE
--------------------------------------------------------------------------------
550
//查看所配置sessions最大連接數量
SQL> show parameter session;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
java_max_sessionspace_size integer 0
java_soft_sessionspace_limit integer 0
license_max_sessions integer 0
license_sessions_warning integer 0
session_cached_cursors integer 50
session_max_open_files integer 10
sessions integer 848 (配置最大連接sessions 550)
shared_server_sessions integer
//查看實際process的連接數量 (包括oracle自身本地連接進程數和非本地的連接進程數)
SQL> select count(*) from v$process;
COUNT(*)
----------
45
//查看非本地連接數量
oracle@sha-oracle-04:~/export/dmpfiles/temp> ps -ef|grep LOCAL=NO|wc -l
15
oracle連接常見的有帶LOCAL=NO參數或帶LOCAL=YES的進程。
LOCAL=NO:非本地連接,即網絡連接。它是通過Listener 連接到服務器的。客戶端的應用通過客戶端的監聽向服務器的監聽發送請求,服務器的監聽接收后,在與數據庫連接,執行相關操作,在把結果返回給客戶端。這是通過監聽的流程。 所以在客戶端需要配置監聽,即配置tnsnames.ora。
LOCAL=YES:本地連接。 本地連接不走監聽,所以在服務監聽沒有啟動的情況下,通過本地的sqlplus 還是可以連上數據庫的。
//查看處於活動狀態的進程列表(用戶名和進程名)
SQL> select spid,username,program from v$process;
SPID USERNAME
------------------------ ---------------
PROGRAM
------------------------------------------------
PSEUDO
5747 oracle
oracle@sha-oracle-04 (PMON)
5752 oracle
oracle@sha-oracle-04 (PSP0
46 rows selected.
//更改最大進程數量
SQL> alter system set processes = 550 scope = spfile;
System altered.
修改system表的processes字段為550,
Oracle 里面有個叫做spfile的東西,就是動態參數文件,里面設置了Oracle 的各種參數。所謂的動態,就是說你可以在不關閉數據庫的情況下,更改數據庫參數,記錄在spfile里面。更改參數的時候,有4種scope選項。scope就是范圍
++ scope=spfile 僅僅更改spfile里面的記載,不更改內存,也就是不立即生效,而是等下次數據庫啟動生效。有一些參數只允許用這種方法更改
++ scope=memory 僅僅更改內存,不改spfile。也就是下次啟動就失效了
++ scope=both 內存和spfile都更改
++ 不指定scope參數,等同於scope=both.
//關閉數據庫instance
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
//啟動數據庫instance
SQL> startup
ORACLE instance started.
