Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mI4U9-0005DQ-VA for pgsql-general@arkaria.postgresql.org; Mon, 23 Aug 2021 07:35:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mI4U8-00066o-LU for pgsql-general@arkaria.postgresql.org; Mon, 23 Aug 2021 07:35:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mI4U7-00061n-NP for pgsql-general@lists.postgresql.org; Mon, 23 Aug 2021 07:35:08 +0000 Received: from mail1.hku.hk ([2001:ce0:2201:101:0:ffff:0:11]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mI4U1-0002tC-9J for pgsql-general@lists.postgresql.org; Mon, 23 Aug 2021 07:35:05 +0000 Received: from hku-nsp1.hku.hk (hku-nsp1.hku.hk [147.8.145.51]) by mail1.hku.hk (8.14.7/8.14.7) with ESMTP id 17N7Yqv1003068 for ; Mon, 23 Aug 2021 15:34:54 +0800 DKIM-Filter: OpenDKIM Filter v2.11.0 mail1.hku.hk 17N7Yqv1003068 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hku.hk; s=default; t=1629704094; bh=qJlA3f0FSwHUemy22h3StcWXKsyQ1cgcDVGMFURCYOM=; h=To:From:Subject:Date:From; b=JNcn5fQG5vKvC8BDbTitaDhebFehHjKcgixZerZkkOvNUkRH7DZMsjmSWoWCeS4YR H+vlwz8k/iyxc886ifF3/rNs+UPv43wqGop8GddfWkr20SSS7d7wudBOhWKfAG07/e xKAwGPDFBoTT19P0n+NStOXx0mUTzIqygxhITr3E= IronPort-SDR: kgzJcXmZmDSfbcN3h/W7OopmPjoQ/XPAFNpAH/9KgEh7p56kVhi3mK9oz/8zHaoPDDK+FvMB2H cE5J1UN7B9zDxp8cjNyvYouNmQtCVIPvHkT207+s75WruTqUWgcU9iJDDEodUuk1xcJvJKw+zB vFJO5LWCTxXktg3kJtogvq+IjgPlLJ9UCwfVeIUBhlxVPcY2Ehm0dIqgE+tZqOzKHaSf0/cSdS YufskxirYY4UF+zrU4e3mnqdI46jBRPNcCp/K8chJQZs0qhWRcy/sYWDnFOyy/8D5O2iwN1vZv lIKvKlvWZj+/zWzcDNh42X+s Received: from unknown (HELO [10.64.236.181]) ([10.64.236.181]) by smtproam1.hku.hk with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 23 Aug 2021 15:34:52 +0800 To: pgsql-general@lists.postgresql.org From: Kelvin Lau Subject: Connecton timeout issues and JDBC Message-ID: <20d676e7-a2d4-da48-891e-0a1dd4e9048d@hku.hk> Date: Mon, 23 Aug 2021 15:34:53 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------8B2902A1D889B039E20E2E02" Content-Language: en-US X-MailScanner-Information: Services provided by HKU Information Technology Services X-MailScanner-ID: 17N7Yqv1003068 X-MailScanner: 0 X-MailScanner-From: kelvin12@hku.hk X-Spam-Status: No List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------8B2902A1D889B039E20E2E02 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hello psql community, I have been using Python to deal with CRUD of the database. I have discovered that there are some issues when dealing with long queries (either SELECT or COPY, since it is somewhat big data). The connection is dropped by the 2~3 hours mark and I have no idea what is wrong. There is no knowledge on how my workstation is connected to the server. But I managed to work around the issue by putting a few parameters in psycopg2: conn = psycopg2.connect(host=“someserver.hk”, port=12345, dbname=“ohdsi”, user=“admin”, password=“admin1”, options="-c search_path="+schema, # it seems the below lines are needed to keep the connection alive. connect_timeout=10, keepalives=1, keepalives_idle=5, keepalives_interval=2, keepalives_count=5) It looks like that few keepalives* parameter kept the connection alive so the long queries can run day and night. The problem now is that, I am forced to use R and JDBC to deal with a bunch of codes, because there are a lot of analyses written in R. The issue that a long query would be dropped around the 2~3 hours mark showed up again in R/JDBC. How can I work around that? I have tried putting /tcpKeepAlive=true /in the link but it seems to have mixed results. Do I also have to put /tcp_keepalives_interval/ or /tcp_keepalives_count/? What are some recommend values in these parameters? Are there any other possible solutions?/ Thanks/ --------------8B2902A1D889B039E20E2E02 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hello psql community,

I have been using Python to deal with CRUD of the database. I have discovered that there are some issues when dealing with long queries (either SELECT or COPY, since it is somewhat big data). The connection is dropped by the 2~3 hours mark and I have no idea what is wrong. There is no knowledge on how my workstation is connected to the server.

But I managed to work around the issue by putting a few parameters in psycopg2:

conn = psycopg2.connect(host=“someserver.hk”,
port=12345,
dbname=“ohdsi”,
user=“admin”,
password=“admin1”,
options="-c search_path="+schema,
# it seems the below lines are needed to keep the connection alive.
connect_timeout=10,
keepalives=1,
keepalives_idle=5,
keepalives_interval=2,
keepalives_count=5)

It looks like that few keepalives* parameter kept the connection alive so the long queries can run day and night.

The problem now is that, I am forced to use R and JDBC to deal with a bunch of codes, because there are a lot of analyses written in R. The issue that a long query would be dropped around the 2~3 hours mark showed up again in R/JDBC. How can I work around that?

I have tried putting tcpKeepAlive=true in the link but it seems to have mixed results. Do I also have to put tcp_keepalives_interval or tcp_keepalives_count? What are some recommend values in these parameters?

Are there any other possible solutions?

Thanks


--------------8B2902A1D889B039E20E2E02--