diff '--exclude=.svn' -ur org/postgresql/core/v3/ConnectionFactoryImpl.java ../x/org/postgresql/core/v3/ConnectionFactoryImpl.java
--- org/postgresql/core/v3/ConnectionFactoryImpl.java	2012-08-21 18:47:09.930742600 -0400
+++ ../x/org/postgresql/core/v3/ConnectionFactoryImpl.java	2012-08-13 11:34:25.267000000 -0400
@@ -118,6 +118,45 @@
             // Enable TCP keep-alive probe if required.
             newStream.getSocket().setKeepAlive(requireTCPKeepAlive);
 
+            // Try to set SO_SNDBUF and SO_RECVBUF socket options, if requested.
+            // If receive_buffer_size and send_buffer_size are set to a value greater
+            // than 0, adjust. -1 means use the system default, 0 is ignored since not
+            // supported.
+
+            // Set SO_RECVBUF read buffer size
+            String receiveBufferSizeProperty = info.getProperty("receive_buffer_size", "-1");
+            try {
+                int receiveBufferSize = Integer.parseInt(receiveBufferSizeProperty);
+                if (receiveBufferSize > -1) {
+                    // value of 0 not a valid buffer size value
+                    if (receiveBufferSize > 0) {
+                        newStream.getSocket().setReceiveBufferSize(receiveBufferSize);
+                    } else {
+                        logger.info("Ignore invalid value for receive_buffer_size: " + receiveBufferSize);
+                    }
+                }
+            } catch (NumberFormatException nfe) {
+                logger.info("Couldn't parse receive_buffer_size value: " + receiveBufferSizeProperty);
+            }
+
+            // Set SO_SNDBUF write buffer size 
+            String sendBufferSizeProperty = info.getProperty("send_buffer_size", "-1");
+            try {
+                int sendBufferSize = Integer.parseInt(sendBufferSizeProperty);
+                if (sendBufferSize > -1) {
+                    if (sendBufferSize > 0) {
+                        newStream.getSocket().setSendBufferSize(sendBufferSize);
+                    } else {
+                        logger.info("Ignore invalid value for send_buffer_size: " + sendBufferSize);
+                    }
+                }
+            } catch (NumberFormatException nfe) {
+                logger.info("Couldn't parse send_buffer_size value: " + sendBufferSizeProperty);
+            }
+
+            logger.info("Receive Buffer Size is " + newStream.getSocket().getReceiveBufferSize());
+            logger.info("Send Buffer Size is " + newStream.getSocket().getSendBufferSize());
+
             // Construct and send a startup packet.
             String[][] params = {
                                     { "user", user },
diff '--exclude=.svn' -ur org/postgresql/ds/common/BaseDataSource.java ../x/org/postgresql/ds/common/BaseDataSource.java
--- org/postgresql/ds/common/BaseDataSource.java	2012-08-21 18:47:12.982742600 -0400
+++ ../x/org/postgresql/ds/common/BaseDataSource.java	2012-08-13 11:34:28.971000000 -0400
@@ -54,6 +54,8 @@
     private String binaryTransferDisable = "";
     private int loginTimeout = 0; // in seconds
     private int socketTimeout = 0; // in seconds
+    private int receive_buffer_size = -1; // off (-1), not in use
+    private int send_buffer_size = -1; // off (-1), not in use
     private boolean ssl = false;
     private String sslfactory;
     private boolean tcpKeepAlive = false;
@@ -293,6 +295,22 @@
     }
 
     /**
+     * Sets the write buffer size of TCP/IP socket.
+     */
+    public void setReceiveBufferSize(int nbytes)
+    {
+        this.receive_buffer_size = nbytes;
+    }
+
+    /**
+     * Sets the send buffer size of TCP/IP socket.
+     */
+    public void setSendBufferSize(int nbytes)
+    {
+        this.send_buffer_size = nbytes;
+    }
+
+    /**
      * Gets the default threshold for enabling server-side prepare.
      *
      * @see #setPrepareThreshold(int)
@@ -478,6 +496,12 @@
                 sb.append("&sslfactory=").append(sslfactory);
             }
         }
+        if (receive_buffer_size != -1) {
+            sb.append("&receive_buffer_size=").append(receive_buffer_size);
+        }
+        if (send_buffer_size != -1) {
+            sb.append("&send_buffer_size=").append(send_buffer_size);
+        }
         sb.append("&tcpkeepalive=").append(tcpKeepAlive);
         if (compatible != null) {
             sb.append("&compatible="+compatible);
@@ -530,6 +554,8 @@
         ref.add(new StringRefAddr("ssl", Boolean.toString(ssl)));
         ref.add(new StringRefAddr("sslfactory", sslfactory));
 
+        ref.add(new StringRefAddr("receive_buffer_size", Integer.toString(receive_buffer_size)));
+        ref.add(new StringRefAddr("send_buffer_size", Integer.toString(send_buffer_size)));
         ref.add(new StringRefAddr("tcpKeepAlive", Boolean.toString(tcpKeepAlive)));
         if (compatible != null)
         {
@@ -556,6 +582,8 @@
         out.writeInt(socketTimeout);
         out.writeBoolean(ssl);
         out.writeObject(sslfactory);
+        out.writeInt(receive_buffer_size);
+        out.writeInt(send_buffer_size);
         out.writeBoolean(tcpKeepAlive);
         out.writeObject(compatible);
         out.writeInt(logLevel);
@@ -579,6 +607,8 @@
         socketTimeout = in.readInt();
         ssl = in.readBoolean();
         sslfactory = (String)in.readObject();
+        receive_buffer_size = in.readInt();
+        send_buffer_size = in.readInt();
         tcpKeepAlive = in.readBoolean();
         compatible = (String)in.readObject();
         logLevel = in.readInt();
