Oracle数据库数据恢复、性能优化

找回密码
注册
搜索
热搜: 活动 交友 discuz
发新帖

3

积分

0

好友

0

主题
1#
发表于 2012-1-11 16:20:00 | 查看: 8840| 回复: 4
请问下大家谁有分析过TNS的查询请求包(TTICode=0x03,func=0x5E).我花了3天时间,把ojdbc.jar包反编译出来,再编译回去,分析TNS请求包,发现和sqlplus的请求包有很大的出入.不同的客户端对同一个数据库服务器发起同一个查询,查询包都不一样,而数据库都可以解析的出来,这到底怎么一回事呢
2#
发表于 2012-1-11 16:27:07
sqlplus 是基于OCI的,ojdbc.jar 里是 oracle jdbc driver的驱动
它们的封装是不同的,但本质上都会有sql*net 的请求信息, 稍后我会回复更多信息。

回复 只看该作者 道具 举报

3#
发表于 2012-1-12 19:56:34
jdbc Packet 包的描述

http://www.oracledatabase12g.com ... ss-description.html
  1. package oracle.net.ns;

  2. import java.io.*;
  3. import oracle.net.nl.RepConversion;

  4. // Referenced classes of package oracle.net.ns:
  5. //            NetException, NetInputStream, SQLnetDef, SessionAtts

  6. public class Packet
  7. implements SQLnetDef
  8. {

  9. public Packet(Packet packet)
  10. {
  11. this(packet.sAtts);
  12. length = packet.length;
  13. type = packet.type;
  14. flags = packet.flags;
  15. dataLen = packet.dataLen;
  16. dataOff = packet.dataOff;
  17. buffer = packet.buffer;
  18. }

  19. public Packet(SessionAtts sessionatts)
  20. {
  21. header = new byte[8];
  22. sAtts = sessionatts;
  23. sdu = sessionatts.getSDU();
  24. tdu = sessionatts.getTDU();
  25. }

  26. public Packet(SessionAtts sessionatts, int i)
  27. {
  28. this(sessionatts);
  29. createBuffer(i);
  30. }

  31. public Packet(SessionAtts sessionatts, int i, int j, int k)
  32. {
  33. this(sessionatts);
  34. createBuffer(i, j, k);
  35. }

  36. protected void createBuffer(int i)
  37. {
  38. buffer = new byte[i];
  39. buffer[0] = (byte)(i / 256);
  40. buffer[1] = (byte)(i % 256);
  41. }

  42. protected void createBuffer(int i, int j, int k)
  43. {
  44. buffer = new byte[i];
  45. buffer[0] = (byte)(i / 256);
  46. buffer[1] = (byte)(i % 256);
  47. buffer[5] = (byte)k;
  48. buffer[4] = (byte)j;
  49. }

  50. protected void dump(byte abyte0[], int i, int j)
  51. {
  52. int k = 0;
  53. System.out.println("Packet dump");
  54. System.out.println("buffer.length=" + abyte0.length);
  55. System.out.println("offset       =" + i);
  56. System.out.println("len          =" + j);
  57. for(int l = i; l < j; l +=  8 )
  58. {
  59. System.out.print("|");
  60. for(int i1 = 0; i1 < 8 && k < j - 1; i1++)
  61. {
  62. k = l + i1;
  63. RepConversion.printInHex(abyte0[k]);
  64. System.out.print(" ");
  65. }

  66. System.out.println("|");
  67. }

  68. System.out.println("finish dump");
  69. }

  70. protected void extractData()
  71. throws IOException, NetException
  72. {
  73. if(dataLen <= 0)
  74. data = new String();
  75. else
  76. if(length > dataOff)
  77. {
  78. data = new String(buffer, 0, dataOff, dataLen);
  79. } else
  80. {
  81. byte abyte0[] = new byte[dataLen];
  82. if(sAtts.nsInputStream.read(abyte0) < 0)
  83. throw new NetException(0);
  84. data = new String(abyte0, 0);
  85. }
  86. }

  87. protected String getData()
  88. {
  89. return data;
  90. }

  91. protected void receive()
  92. throws IOException, NetException
  93. {
  94. int i;
  95. for(i = 0; i < header.length;)
  96. try
  97. {
  98. if((i += sAtts.ntInputStream.read(header, i, header.length - i)) <= 0)
  99. throw new NetException(0);
  100. }
  101. catch(InterruptedIOException _ex)
  102. {
  103. throw new NetException(504);
  104. }

  105. length = header[0] & 0xff;
  106. length <<= 8;
  107. length |= header[1] & 0xff;
  108. type = header[4];
  109. flags = header[5];
  110. if(type > 19)
  111. throw new NetException(204);
  112. if(length > 32767 || length > sdu)
  113. throw new NetException(203);
  114. if(length < 8   )
  115. throw new NetException(207);
  116. buffer[5] = (byte)flags;
  117. buffer[4] = (byte)type;
  118. while(i < length)
  119. try
  120. {
  121. if((i += sAtts.ntInputStream.read(buffer, i, length - i)) <= 0)
  122. throw new NetException(0);
  123. }
  124. catch(InterruptedIOException _ex) { }
  125. }

  126. protected void send()
  127. throws IOException
  128. {
  129. synchronized(sAtts.ntOutputStream)
  130. {
  131. sAtts.ntOutputStream.write(buffer, 0, buffer.length);
  132. }
  133. }

  134. private int buffer2send;
  135. protected int sdu;
  136. protected int tdu;
  137. protected int length;
  138. public int type;
  139. protected int flags;
  140. protected int dataLen;
  141. protected int dataOff;
  142. protected String data;
  143. protected byte buffer[];
  144. protected byte header[];
  145. public SessionAtts sAtts;
  146. }
复制代码

回复 只看该作者 道具 举报

4#
发表于 2012-1-12 20:00:50
  1. SQL*NET PACKET STRUCTURE: NS PACKET HEADER

  2. Problem Description:
  3. ====================

  4. This entry contains information about the SQL*Net packet structure and the NS
  5. packet headers (protocol independent layer).

  6. These packet types appear in the SQL*Net trace. The help explain how the
  7. client and server are synchronized and what they are doing.

  8. Search words:
  9. packets tracing file trc tns sqlnet

  10. Solution Description:
  11. =====================

  12. ================
  13. NS PACKET HEADER
  14. ================
  15. 0 1 2 3
  16. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  17. —————————————————————–
  18. | NSPHDLEN | NSPHDPSM |
  19. |—————————————————————|
  20. | NSPHDTYP | reserved | NSPHDHSM |
  21. —————————————————————–
  22. NSPHDLEN: Packet length – number of bytes in the entire packet.
  23. NSPHDPSM: Packet checksum – the 16-bit ones complement of the 16-bit
  24. ones complement sum of the entire packet.
  25. NSPHDTYP: Packet type
  26. Code Decimal HEX Description
  27. ———– ——- ——- ——————————
  28. NSPTCN 01 1 connect
  29. NSPTAC 02 2 accept
  30. NSPTAK 03 3 acknowledge
  31. NSPTRF 04 4 refuse
  32. NSPTRD 05 5 redirect
  33. NSPTDA 06 6 data
  34. NSPTNL 07 7 “null” – empty data, no flags
  35. NSPTAB 09 9 abort
  36. NSPTRS 11 B re-send
  37. NSPTMK 12 C marker
  38. NSPTAT 13 D attention
  39. NSPTCNL 14 E control information
  40. NSPTHI 19 12 highest legal packet type

  41. NSPHDHSM: Header checksum – the 16-bit ones complement of the 16-bit
  42. ones complement sum of the packet header.
  43. NSPSIZHD: size of packet header

  44. =================
  45. NS CONNECT PACKET
  46. =================
  47. 0 1 2 3
  48. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  49. —————————————————————–
  50. | NSPHDLEN | NSPHDPSM |
  51. |——————————————————- ——-|
  52. | NSPTCN (1) | reserved | NSPHDHSM |
  53. |—————————————————————|
  54. | NSPCNVSN | NSPCNLOV |
  55. |—————————————————————|
  56. | NSPCNOPT | NSPCNSDU |
  57. |—————————————————————|
  58. | NSPCNTDU | NSPCNNTC |
  59. |—————————————————————|
  60. | NSPCNTNA | NSPCNONE |
  61. |—————————————————————|
  62. | NSPCNLEN | NSPCNOFF |
  63. |—————————————————————|
  64. | NSPCNMXC |
  65. |—————————————————————|
  66. | NSPCNFL0 | NSPCNFL1 |//////////////////////////////|
  67. |—————————————————————|
  68. | (expansion) |
  69. |—————————————————————|
  70. | NSPCNDAT, NSPCNV3DAT, NSPCNV2DAT (data) |
  71. —————————————————————–

  72. NSPCNVSN Packet version number.
  73. NSPCNLOV Lowest version number that sender can be compatible with.
  74. NSPCNOPT Global service options supported (see NSGBLXXXX in nsi.h).
  75. NSPCNSDU My SDU (session data unit) size.
  76. NSPCNTDU Maximum TDU (transport data unit) size for NT driver.
  77. NSPCNNTC NT protocol characteristics (see NTCXXX in ti.h).
  78. NSPCNTNA Line turnaround value (=> max consecutive packet sends
  79. allowed before a packet recv must occur).
  80. NSPCNONE The value ’1′ in my hardware byte order
  81. NSPCNLEN Length of connect data (not necessarily in this packet).
  82. NSPCNOFF Offset to start of connect data.
  83. NSPCNMXC Maximum connect data that can be received.
  84. NSPCNFL0 Connect flags (from nsinfflg).
  85. NSPCNFL1 Connect flags (from nsinfflg).

  86. **** The following are added for Oracle Trace functionality (expansion)
  87. NSPCNCF1 cross facility item 1
  88. NSPCNCF2 cross facility item 2
  89. NSPCNCID unique connection id
  90. **** End of update for Oracle trace

  91. NSPCNDAT start of connect data (V3.6 packet)
  92. NSPCNV3DAT start of connect data (V3 packet)
  93. NSPCNV2DAT start of connect data, V2 packet

  94. ================
  95. NS ACCEPT PACKET
  96. ================
  97. 0 1 2 3
  98. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  99. —————————————————————–
  100. | NSPHDLEN | NSPHDPSM |
  101. |—————————————————————|
  102. | NSPTAC (2) | reserved | NSPHDHSM |
  103. |—————————————————————|
  104. | NSPACVSN | NSPACOPT |
  105. |—————————————————————|
  106. | NSPACSDU | NSPACTDU |
  107. |—————————————————————|
  108. | NSPACONE | NSPACLEN |
  109. |—————————————————————|
  110. | NSPACOFF | NSPACFL0 | NSPACFL1 |
  111. |—————————————————————|
  112. | (expansion) |
  113. |—————————————————————|
  114. | NSPACDAT, NSPACV2DAT (data) |
  115. —————————————————————–

  116. NSPACVSN Version that this connection is to run at.
  117. NSPACOPT Global service options in place for this connection.
  118. NSPACSDU SDU (session data unit) size for this connection.
  119. NSPACTDU Maximum TDU (transport data unit) for this connection.
  120. NSPACONE The value ’1′ in my hardware byte order
  121. NSPACLEN Length of connect data (not necessarily in this packet).
  122. NSPACOFF Offset to start of connect data.
  123. NSPACFL0 Connect flags (from nsctxinf).
  124. NSPACFL1 Connect flags (from nsctxinf).
  125. NSPACDAT Start of connect data (V3/V3.6 packet)
  126. NSPACV2DAT Start of connect data, V2 packet

  127. ================
  128. NS RESEND PACKET
  129. ================
  130. 0 1 2 3
  131. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  132. —————————————————————–
  133. | NSPHDLEN | NSPHDPSM |
  134. |—————————————————————|
  135. | NSPTRS (11) | reserved | NSPHDHSM |
  136. —————————————————————–

  137. ================
  138. NS REFUSE PACKET
  139. ================
  140. 0 1 2 3
  141. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  142. —————————————————————–
  143. | NSPHDLEN | NSPHDPSM |
  144. |—————————————————————|
  145. | NSPTRF (4) | reserved | NSPHDHSM |
  146. |—————————————————————|
  147. | NSPRFURS | NSPRFSRS | NSPRFLEN |
  148. |—————————————————————|
  149. | NSPRFDAT (data) |
  150. —————————————————————–

  151. NSPRFURS User (application) reason for refusal.
  152. NSPRFSRS System (NS) reason for refusal.
  153. NSPRFLEN Length of refuse data (not necessarily in this packet).
  154. NSPRFDAT Start of connect data

  155. ==================
  156. NS REDIRECT PACKET
  157. ==================
  158. 0 1 2 3
  159. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  160. —————————————————————–
  161. | NSPHDLEN | NSPHDPSM |
  162. |—————————————————————|
  163. | NSPTRD (5) | reserved | NSPHDHSM |
  164. |—————————————————————|
  165. | NSPRDLEN | NSPRDDAT (data) |
  166. |——————————— |
  167. | |
  168. —————————————————————–

  169. NSPRDLEN Length of redirect data (not necessarily in this packet).
  170. NSPRDDAT Start of connect data

  171. ==============
  172. NS DATA PACKET
  173. ==============
  174. 0 1 2 3
  175. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  176. —————————————————————–
  177. | NSPHDLEN | NSPHDPSM |
  178. |———————————————————————-|
  179. | NSPTDA (6) | reserved | NSPHDHSM |
  180. |———————————————————————-|
  181. | NSPDAFLG | NSPDADAT (data) |
  182. |———————————————————————-|

  183. NSPDAFLG flags:
  184. Code Value Description
  185. ———– ———– ——————————
  186. NSPDAFZER 0
  187. NSPDAFTKN 1 the hdx (send) token
  188. NSPDAFRCF 2 request confirmation
  189. NSPDAFCFM 4 confirmation
  190. NSPDAFRSV 8 RESERVED (for hdx flag)
  191. NSPDAFMOR 20 more data to come
  192. NSPDAFEOF 40 “end of file”
  193. NSPDAFIMM 80 do immediate confirmation
  194. NSPDAFRTS 100 request-to-send
  195. NSPDAFRNT 200 request NT trailer
  196. NSPDADAT start of data

  197. ================
  198. NS MARKER PACKET
  199. ================
  200. 0 1 2 3
  201. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  202. —————————————————————–
  203. | NSPHDLEN | NSPHDPSM |
  204. |—————————————————————|
  205. | NSPTMK (12) | reserved | NSPHDHSM |
  206. |—————————————————————|
  207. | NSPMKTYP | NSPMKODT | NSPMKDAT |
  208. —————————————————————-

  209. NSPMKTYP marker type
  210. Code Value Description
  211. ———– ———– ——————————
  212. NSPMKTD0 0 data marker – 0 data bytes
  213. NSPMKTD1 1 data marker – 1 data byte
  214. NSPMKTAT 2 attention marker => ATTENTION packet
  215. NSPMKODT old (pre-V3.05) data byte
  216. NSPMKDAT data byte – For V3.05 we want NSPMKDAT to be the same
  217. as
  218. NSPDADAT – this fixes a bug to do with reading a
  219. marker via
  220. the NSBRECV interface where the MARKER packet
  221. co-resides in
  222. the same SDU buffer as a another packet (“leftover”
  223. condition).

  224. ===================
  225. NS ATTENTION PACKET
  226. ===================
  227. (there isn’t one, it’s a special case of a MARKER packet, see above)

  228. ===============
  229. NS ABORT PACKET
  230. ===============

  231. 0 1 2 3
  232. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  233. —————————————————————–
  234. | NSPHDLEN | NSPHDPSM |
  235. |—————————————————————|
  236. | NSPTAB (9) | reserved | NSPHDHSM |
  237. |—————————————————————|
  238. | NSPABURS | NSPABSRS | NSPABDAT (data) |
  239. |——————————— |
  240. | |
  241. —————————————————————–

  242. NSPABURS User (application) reason for abort.
  243. NSPABSRS System (NS) reason for abort.
  244. NSPABDAT Start of abort data

  245. =================
  246. NS CONTROL PACKET
  247. =================
  248. 0 1 2 3
  249. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  250. —————————————————————–
  251. | NSPHDLEN | NSPHDPSM |
  252. |—————————————————————|
  253. | NSPTCNL (14) | reserved | NSPHDHSM |
  254. |—————————————————————|
  255. | NSPTCNLCMD | data |
  256. |——————————— |
  257. | |
  258. —————————————————————–

  259. * The control command passed. Initially the only command would be for
  260. Oracle trace.

  261. NSPCTLCMD valid commands are:

  262. Code Value Description
  263. ———– ———– ————————–
  264. NSPCTL_OT 1 Oracle trace command
复制代码

回复 只看该作者 道具 举报

5#
发表于 2012-1-12 20:07:28
你可以参考这三个note:

How to Perform the Equivalent of SQL*Net Client Tracing with Oracle JDBC Thin Driver [ID 793415.1]
How to Trace the Network Packets Exchanged Between JDBC and the RDBMS in Release 11.2 [ID 1050942.1]
How To Generate Sqlnet trace with Sql*Developer ? [ID 1390063.1]

回复 只看该作者 道具 举报

您需要登录后才可以回帖 登录 | 注册

QQ|手机版|Archiver|Oracle数据库数据恢复、性能优化

GMT+8, 2024-12-24 01:44 , Processed in 0.049716 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部
TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569