[20171106]配置客戶端連接註意.txt--//在配置客戶端連接時一般建議使用Net Manager工具,windows下調用執行Net Manager.--//linux下執行 netmgr,這樣能一定程度避免copy & paste的 錯誤.--//我這裡想說的是在連接類型選擇上一定要註意 ...
[20171106]配置客戶端連接註意.txt
--//在配置客戶端連接時一般建議使用Net Manager工具,windows下調用執行Net Manager.
--//linux下執行 netmgr,這樣能一定程度避免copy & paste的 錯誤.
--//我這裡想說的是在連接類型選擇上一定要註意,一般存在4中選擇:
資料庫預設設置
專用伺服器
共用伺服器
池中伺服器.
--//最好明確設置那種模式,而不是選擇"資料庫預設設置"模式,這樣會導致以後配置啟用"共用伺服器"出現問題.
--//最近我們生產系統就遭遇這樣的問題,還是通過例子說明:
1.環境:
SYS@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
--//我在我的client配置如下:
R:\>cat tnsnames.ora
# tnsnames.ora Network Configuration File: r:\tnsnames.ora
# Generated by Oracle configuration tools.
BOOK =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = book)
)
)
BOOK1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = book)
)
)
BOOK2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = SHARED)
(SERVICE_NAME = book)
)
)
--//註第一種情況連接串BOOK就是"資料庫預設設置".沒有明確參數SERVER的值.許多開發包括我們下發的程式都是這樣設置的.
2.我開啟共用服務模式:
SYS@book> show parameter dispatchers
NAME TYPE VALUE
---------------- -------- -------------------------------------
dispatchers string (PROTOCOL=TCP) (SERVICE=book,bookXDB)
max_dispatchers integer
SYS@book> show parameter shared_server
NAME TYPE VALUE
---------------------- ------- -----
max_shared_servers integer 1
shared_server_sessions integer
shared_servers integer 1
--//我打開2個會話:
R:\>sqlplus scott/book@book
R:\>sqlplus scott/book@book
--//打開另外會話以sys用戶執行如下(session 3):
--//session 3:
SELECT s.sid
,s.serial#
,p.spid
,p.pid
,p.serial# p_serial#
,s.SERVER
,s.status
,s.username
, 'alter system kill session '''
|| s.sid
|| ','
|| s.serial#
|| ''''
|| ' immediate;'
c50
FROM v$session s, v$process p
WHERE s.paddr = p.addr and s.username='SCOTT';
SID SERIAL# SPID PID P_SERIAL# SERVER STATUS USERNAME C50
----- ------- ------ ------- ---------- --------- -------- ---------- --------------------------------------------------
262 241 5750 19 1 NONE INACTIVE SCOTT alter system kill session '262,241' immediate;
263 77 5750 19 1 NONE INACTIVE SCOTT alter system kill session '263,77' immediate;
--//你可以發現現在2個會話沒有執行任何語句,status='INACTIVE',server='NONE'.如果你在其中會話執行語句.
--//session 1:
select count(*) from emp,emp,emp,emp,emp,emp,emp,emp;
--//session 3:
SID SERIAL# SPID PID P_SERIAL# SERVER STATUS USERNAME C50
----- ------- ------ ------- ---------- --------- -------- ---------- --------------------------------------------------
263 77 5750 19 1 NONE INACTIVE SCOTT alter system kill session '263,77' immediate;
262 241 5752 20 1 SHARED ACTIVE SCOTT alter system kill session '262,241' immediate;
--//你可以發現其中1個會話status從'INACTIVE'->'ACTIVE',server從'NONE'=>SHARED.
--//在sessiono 1沒有執行結束時,在session 2執行:
SCOTT@book> select sysdate from dual ;
--//session 2會掛起,這個是因為我沒有設置dispatchers參數D000進程太少.
--//如果這時在執行如下:
R:\>sqlplus scott/book@book
SQL*Plus: Release 12.1.0.1.0 Production on Mon Nov 6 12:00:05 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-28547: connection to server failed, probable Oracle Net admin error
3.重覆測試看看awr報表:
--session 3:
exec dbms_workload_repository.create_snapshot();
--session 1:
select count(*) from emp,emp,emp,emp,emp,emp,emp,emp;
--session 2:
select sysdate from dual ;
--//等待結束.
--session 3:
exec dbms_workload_repository.create_snapshot();
--//查看awr報表.實際上根本看不出問題.
SYS@book> @ &r/wait
P1RAW P2RAW P3RAW P1 P2 P3 SID SERIAL# SEQ# EVENT STATE WAIT_TIME_MICRO SECONDS_IN_WAIT
---------------- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------------------------------------- ------------------- --------------- ---------------
000000004D545300 0000000000000001 00 1297371904 1 0 262 241 77 SQL*Net message to client WAITED SHORT TIME 5 31
--//這個也是共用伺服器模式的弊端.執行的語句必須很快完成,不然會影響別的會話執行sql語句.blog.itpub.net/267265/viewspace-2124172/
4.如果增加參數max_shared_servers,max_dispatchers數量:
SYS@book> alter system set max_shared_servers=6 scope=memory;
System altered.
SYS@book> alter system set max_dispatchers=10 scope=memory ;
System altered.
SYS@book> alter system set dispatchers='(PROTOCOL=TCP) (SERVICE=book,bookXDB)(dispatchers=6)' scope=memory;
System altered.
SYS@book> alter system register ;
System altered.
$ ps -lef | egrep "d00[0-9]_book|UI[D]"
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
0 S oracle 53333 1 0 80 0 - 61860 poll_s 14:45 ? 00:00:00 ora_d000_book
0 S oracle 53471 1 0 80 0 - 61827 poll_s 14:56 ? 00:00:00 ora_d001_book
0 S oracle 53473 1 0 80 0 - 61827 poll_s 14:56 ? 00:00:00 ora_d002_book
0 S oracle 53475 1 0 80 0 - 61827 poll_s 14:56 ? 00:00:00 ora_d003_book
0 S oracle 53477 1 0 80 0 - 61827 poll_s 14:56 ? 00:00:00 ora_d004_book
0 S oracle 53479 1 0 80 0 - 61827 poll_s 14:56 ? 00:00:00 ora_d005_book
--//依次打開3個會話:
R:\>sqlplus scott/book@book
R:\>sqlplus scott/book@book
R:\>sqlplus scott/book@book
--//session 4:
SELECT s.sid
,s.serial#
,p.spid
,p.pid
,p.serial# p_serial#
,s.SERVER
,s.status
,s.username
,s.program
,p.program
, 'alter system kill session '''
|| s.sid
|| ','
|| s.serial#
|| ''''
|| ' immediate;'
c50
FROM v$session s, v$process p
WHERE s.paddr = p.addr and s.username='SCOTT';
SID SERIAL# SPID PID P_SERIAL# SERVER STATUS USERNAME PROGRAM PROGRAM C50
---------- ---------- ------ ------- ---------- --------- -------- -------- ------------ -------------------------- --------------------------------------------------
262 33 53471 29 4 NONE INACTIVE SCOTT sqlplus.exe oracle@xxxxxdg4 (D001) alter system kill session '262,33' immediate;
261 11 53473 30 2 NONE INACTIVE SCOTT sqlplus.exe oracle@xxxxxdg4 (D002) alter system kill session '261,11' immediate;
263 9 53479 33 1 NONE INACTIVE SCOTT sqlplus.exe oracle@xxxxxdg4 (D005) alter system kill session '263,9' immediate;
--//分別運行不同dispatchers上.這樣就不會存在阻塞.
--//session 1:
SCOTT@book> select count(*) from emp,emp,emp,emp,emp,emp,emp,emp;
...
--//session 2:
SCOTT@book> select sysdate from dual ;
SYSDATE
-------------------
2017-11-06 15:11:00
--//session 3:
SCOTT@book> select sysdate from dual ;
SYSDATE
-------------------
2017-11-06 15:11:03
--//如果要增加S00N進程數量,修改參數:
SYS@book> alter system set shared_servers=4 scope=memory ;
System altered.
$ ps -lef | egrep "s00[0-9]_book|UI[D]"
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
0 S oracle 53335 1 3 80 0 - 60697 poll_s 14:45 ? 00:00:55 ora_s000_book
0 S oracle 53617 1 0 80 0 - 60565 poll_s 15:13 ? 00:00:00 ora_s001_book
0 S oracle 53619 1 0 80 0 - 60565 poll_s 15:13 ? 00:00:00 ora_s002_book
0 S oracle 53621 1 0 80 0 - 60565 poll_s 15:13 ? 00:00:00 ora_s003_book
5.總結:
1.講了這麼多,回到前面遇到的問題,可以發現如果client配置時使用資料庫預設設置,在共用伺服器存在的情況下,會優先使用.這樣
如果應用配置存在問題,特別是2層應用模式,全部使用共用伺服器模式連接資料庫,這樣如果某個sql執行很慢,就有可能阻塞業務的
正常運行,即使你配置足夠的dispatchers.實際上如果你使用ezconnect連接也是共用模式.
參考鏈接: http://blog.itpub.net/267265/viewspace-2130292/=>[20161212]ezconnect與共用服務模式.txt
2.從上面的情況,說明在配置client時,需要選擇正確的連接類型,而不是選擇"資料庫預設設置",以免造成不必要麻煩.
3.如果這樣只能建立新的服務名,指派服務名使用共用伺服器模式.
SYS@book> show parameter service
NAME TYPE VALUE
------------- ------ ---------------
service_names string BOOK, BOOKSHARE
SYS@book> alter system set dispatchers='(PROTOCOL=TCP) (SERVICE=bookshare,bookXDB)(dispatchers=6)' scope=memory;
System altered.
--//修改連接串如下:
BOOKS =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = SHARED)
(SERVICE_NAME = bookshare)
)
)
R:\>sqlplus scott/book@books
SCOTT@books> @ spid
SID SERIAL# SPID PID P_SERIAL# C50
---------- ---------- ------ ------- ---------- --------------------------------------------------
171 7 53621 37 1 alter system kill session '171,7' immediate;
--//session 4:
SELECT s.sid
,s.serial#
,p.spid
,p.pid
,p.serial# p_serial#
,s.SERVER
,s.status
,s.username
,s.program
,s.SERVICE_NAME
,p.program
, 'alter system kill session '''
|| s.sid
|| ','
|| s.serial#
|| ''''
|| ' immediate;'
c50
FROM v$session s, v$process p
WHERE s.paddr = p.addr and s.username='SCOTT';
SID SERIAL# SPID PID P_SERIAL# SERVER STATUS USERNAME PROGRAM SERVICE_NAME PROGRAM C50
--- ---------- ------ ------- ---------- --------- -------- -------- ----------- ------------ ---------------------- --------------------------------------------------
171 7 53727 32 6 NONE INACTIVE SCOTT sqlplus.exe BOOKSHARE oracle@xxxxxdg4 (D004) alter system kill session '171,7' immediate;
--//退出重新登錄:
R:\>sqlplus scott/book@book
SCOTT@book> @ spid
SID SERIAL# SPID PID P_SERIAL# C50
---------- ---------- ------ ------- ---------- --------------------------------------------------
184 19 53781 38 8 alter system kill session '184,19' immediate;
--//session 4:
SYS@book> /
SID SERIAL# SPID PID P_SERIAL# SERVER STATUS USERNAME PROGRAM SERVICE_NAME PROGRAM C50
--- ---------- ------ ------- ---------- --------- -------- -------- ----------- ------------ --------------- --------------------------------------------------
184 19 53781 38 8 DEDICATED INACTIVE SCOTT sqlplus.exe book oracle@gxqyydg4 alter system kill session '184,19' immediate;
--//這樣連接模式就是專用伺服器模式.