Êý¾Ý¿â»á»°¿ÕÏÐ
ÇжÏÁ¬½Ó֮ǰ£¬Oracle»á»°Ò»Ö±´¦ÓÚ¿ÕÏÐ״̬£¬ÔÚ·À»ðǽÖжÏÖ®ºó£¬¿Í»§¶ËÏòOracle·þÎñÆ÷Ìá½»SQLʱ£¬ÓÉÓÚTCPÁ¬½ÓÒѾÖжϣ¬Õâʱ¿Í»§¶ËÕì²âµ½Á¬½ÓÖжϣ¬ÄÇô¿Í»§¶Ë¾Í»á±¨ORA-03113/ORA-03114ÕâÀà´íÎó£¬È»ºó»á»°Öжϡ£µ«ÊÇÔÚOracle·þÎñÆ÷¶Ë£¬»á»°Ò»Ö±ÔÚ´¦Óڵȴý¿Í»§¶ËÏûÏ¢µÄ״̬¡£
¶ø¶ÔÓÚDruidÕâÖÖÓÐtestOnBorrow¡¢testWhileIdleµÄ¼ì²â»úÖÆ£¬ÇÒ¼ì²âʧ°Ü¿ÉÒÔÖØн¨Á¢Á¬½ÓµÄÁ¬½Ó³Ø£¬¿ÕÏеı»·À»ðǽÇжϵÄÁ¬½ÓÔÚºóÐø»á±»²»¶ÏÖؽ¨£¬¶øÔÚÊý¾Ý¿â·þÎñÆ÷¶Ë£¬ÔòÁ¬½ÓÔ½À´Ô½¶à£¬¼´»á»°ÊýÔ½À´Ô½¶à£¬ÉõÖÁ×îÖÕ³¬¹ýÁËÊý¾ÝΪ×î´óÁ¬½ÓÊý¡£
ÕâÊÇÒ»¸öÁÙʱ½â¾ö·½·¨£¬±ÈÈ罫·À»ðǽµÄÁ¬½Ó³¬Ê±Ê±¼äµ÷ÕûΪ8Сʱ£¬ÕâÑù¿ÉÒÔ¾¡Á¿±ÜÃâ¿ÕÏÐÁ¬½ÓµÄÇжϣ¬µ«ÎÞ·¨ÍêÈ«±ÜÃ⣬ÒòΪÎÞ·¨Ô¤¼ÆÁ¬½Ó»á±»¿ÕÏжà¾Ã£¬Èç¹ûÄãµÄϵͳ²»ÊÇ×ÜÓÐÈË·ÃÎʵĻ°£¬ÄÇôÁ¬½Ó³ÙÔç»áÒòΪ¿ÕÏжø±»Çжϣ¬µ¼ÖÂһЩ²»¿ÉÔ¤¼ÆµÄÎÊÌ⣬¶øµ÷´ó³¬Ê±Ê±¼äÖ»ÊÇ»º½â¶øÒÑ
2¡¢tcp keepalive¹¦ÄÜtcpµÄkeepalive£¬Æäʵ¾ÍÊÇÓÃÀ´±£³ÖtcpÁ¬½ÓµÄ£¬ÆäÔÀí¼òµ¥Ëµ¾ÍÊÇÈç¹ûÒ»¸öTCPÁ¬½ÓÔÚÖ¸¶¨µÄʱ¼äÄÚûÓÐÈκλ£¬»á·¢ËÍÒ»¸ö̽²â°üµ½Á¬½ÓµÄ¶Ô¶Ë£¬¼ì²âÁ¬½ÓµÄ¶Ô¶ËÊÇ·ñÈÔÈ»´æÔÚ£¬Èç¹û¶Ô¶ËÒ»¶¨Ê±¼äÄÚÈÔûÓжÔ̽²âµÄÏìÓ¦£¬»áÔٴη¢ËÍ̽²â°ü£¬·¢Ëͼ¸´Îºó£¬ÈÔȻûÓÐÏìÓ¦£¬¾ÍÈÏΪÁ¬½ÓÒѾʧЧ£¬¹Ø±Õ±¾µØÁ¬½Ó¡£
tcp keepalive²¢²»ÊÇĬÈÏ¿ªÆôµÄ£¬ÔÚ¿ª·¢³ÌÐòʱ¿ÉÒÔÉèÖÃtcp keepaliveΪtrue£¬ÕâÑùtcpÁ¬½ÓÔÚÒ»¶¨Ê±¼äÄÚûÓÐÈκÎÊý¾Ý±¨ÎÄ´«ÊäÔòÆô¶¯Ì½²â£¬Õâ¸öʱ¼äÒ»°ãÊDzÙ×÷ϵͳ¹æ¶¨£¬LinuxϵͳÖпÉÒÔͨ¹ýÉèÖÃnet.ipv4.tcp_keepalive_timeÀ´Ð޸ģ¬Ä¬ÈÏÊÇ7200Ã룬¼´2Сʱ¡£µ±È»ÔÚ±à³ÌʱҲ¿ÉÒÔÉèÖÃÕâ¸öʱ¼äÓÃÓÚµ±Ç°socket£¬µ«ÊÇJavaµÄSocket APIÖкÃÏñÖ»ÓÐÉèÖÃkeepalive=true£¬²¢Ã»·¨ÉèÖÃtcp_keepalive_time
µ±ÉèÖÃÁËtcp keepaliveÖ®ºó£¬Ö»Òªtcp̽²â°ü·¢Ë͵Äʱ¼äСÓÚ·À»ðǽµÄÁ¬½Ó³¬Ê±Ê±¼ä£¬·À»ðǽ¾Í»á¼ì²éµ½Á¬½ÓÖÐÈÔÈ»ÓÐÊý¾Ý´«Ê䣬¾Í²»»á¶Ï¿ªÕâ¸öÁ¬½Ó¡£
ʹÓÃJDBC´´½¨µÄÊý¾Ý¿âtcpÁ¬½ÓÊÇûÓÐÉèÖÃkeepaliveµÄ£¬Õâµã¿ÉÒÔͨ¹ýLinuxµÄnetstat»òssÃüÁîÔÚÊý¾Ý¿â¿Í»§¶Ë£¨¼´Ó¦Óöˣ©ÑéÖ¤
ʹÓÃÃüÁînetstat -ano »ò ss -ano£¬ÆäÖвÎÊýo¶¼ÊÇÏÔʾtimer¼ÆʱÆ÷£¬timer¼ÆʱÆ÷ÔÚÁ¬½Ó½¨Á¢×´Ì¬Ï¿ÉÒÔ¶ÔÁ¬½Ó±£»î¼Æʱ
netstatÃüÁî¶ÔûÓпªÆôkeepaliveµÄtcpÁ¬½ÓÏÔʾΪ£ºoff (0.00/0/0)
ssÃüÁî¶ÔûÓÐkeepaliveµÄtcpÁ¬½Ó£¬²»»áÏÔʾtimer¼ÆʱÆ÷
OracleÌṩÁËÀàËÆtcp keepaliveµÄ»úÖÆ£¬Ò²¾ÍÊÇDCD£¨Dead Conneciton Detection£©¡£ÔÚ$ORACLE_HOME/network/admin/sqlnet.oraÎļþÖÐÔö¼ÓÈçÏÂÒ»ÐУº
sqlnet.expire_time=NNN
ÕâÀïNNNΪ·ÖÖÓÊý£¬OracleÊý¾Ý¿â»áÔڻỰIDLEʱ¼ä³¬¹ýÕâ¸öÖ¸¶¨µÄʱ¼äʱ£¬¼ì²âÕâ¸ö»á»°µÄ¶Ô¶Ë£¨¼´¿Í»§¶Ë£©ÊÇ·ñ»¹ÓÐЧ¡£±ÜÃâ¿Í»§¶ËÓÉÓÚÒì³£Í˳ö£¬µ¼Ö»Ựһֱ´æÔÚ¡£
ͬÑùµÄÈç¹ûDCDµÄʱ¼ä±È·À»ðǽÇжϿÕÏÐÁ¬½ÓµÄʱ¼ä¶Ì£¬Á¬½ÓÒ²¿ÉÒÔÒ»Ö±±£³Ö
ÒÔÉϼ¸ÖÖ·½·¨ÒªÃ´ÊÇÀûÓÃtcpÁ¬½ÓkeepaliveÌØÐÔ£¬ÒªÃ´ÊDzÉÓÃÊý¾Ý¿â¶ËµÄ¿ÕÏÐÁ¬½Ó¼ì²â£¬ÎÒÃǵijÌÐòÖÐÒ²¿ÉÒÔÖ÷¶¯×öÕâÖÖÐÄÌø¼ì²â
DruidÊý¾Ý¿âÁ¬½Ó³Ø´Ó1.0.28¿ªÊ¼£¬Ìí¼ÓÁËdruid.keepAliveÊôÐÔ£¬Ä¬ÈϹرÕ
´ò¿ªdruid.keepAliveÖ®ºó£¬µ±Á¬½Ó³Ø¿ÕÏÐʱ£¬³ØÖеÄminIdleÊýÁ¿ÒÔÄÚµÄÁ¬½Ó£¬¿ÕÏÐʱ¼ä³¬¹ýminEvictableIdleTimeMillis£¬Ôò»áÖ´ÐÐkeepAlive²Ù×÷£¬¼´Ö´ÐÐdruid.validationQueryÖ¸¶¨µÄ²éѯSQL£¬Ò»°ãΪselect * from dual£¬Ö»ÒªminEvictableIdleTimeMillisÉèÖõÄСÓÚ·À»ðǽÇжÏÁ¬½Óʱ¼ä£¬¾Í¿ÉÒÔ±£Ö¤µ±Á¬½Ó¿ÕÏÐʱ×Ô¶¯×ö±£»î¼ì²â£¬²»»á±»·À»ðǽÇжÏ
²Î¿¼£º
OracleÓë·À»ðǽ
·À»ðǽ¡¢DCDÓëTCP Keep alive
¡¡