Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fcqol-0004MF-LG for pgsql-odbc@arkaria.postgresql.org; Tue, 10 Jul 2018 11:28:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fcqoj-0001PS-Hy for pgsql-odbc@arkaria.postgresql.org; Tue, 10 Jul 2018 11:28:25 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fcqoj-0001PL-4Y for pgsql-odbc@lists.postgresql.org; Tue, 10 Jul 2018 11:28:25 +0000 Received: from mail03.asahi-net.or.jp ([202.224.55.15]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fcqoa-0001py-HQ for pgsql-odbc@postgresql.org; Tue, 10 Jul 2018 11:28:23 +0000 Received: from [192.168.1.5] (p171004-ipngn200303fukui.fukui.ocn.ne.jp [180.5.50.4]) (Authenticated sender: GQ9H-INUE) by mail03.asahi-net.or.jp (Postfix) with ESMTPA id CA548E7C16; Tue, 10 Jul 2018 20:28:11 +0900 (JST) Subject: Re: ODBC cliens is hanging if network connection is broken To: AYahorau@ibagroup.eu Cc: MikalaiKeida@ibagroup.eu, pgsql-odbc@postgresql.org References: <51a5824d-25ae-dfd2-3576-ed71d29d6d3a@dream.email.ne.jp> From: "Inoue, Hiroshi" Message-ID: Date: Tue, 10 Jul 2018 20:28:20 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------B0FB809D647EA6F5E2D4A67C" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------B0FB809D647EA6F5E2D4A67C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi, On 2018/07/10 19:40, AYahorau@ibagroup.eu wrote: > Hello, > > I added pqopt option into the odbc.ini  file as you suggested: > [sles12-1] > Description = PostgreSQL connection to rtpdb > Driver = PostgreSQL > Database = rtpdb > *pqopt = **keepalives=1 keepalives_interval=5 keepalives_count=1* Oops I mistook keepalive_idle for keepalive_interval. Please try *pqopt = **keepalives=1 **|keepalives_idle=5| keepalives_count=1 ***keepalives_interval=1 *regards, Hiroshi Inoue * > Servername = sles12-1 > Username = > Password = > Port = 5432 > Protocol = 7.4+ > ReadOnly = No > RowVersioning = No > ShowSystemTables = No > ConnSettings = > > But unfortunately if did not take a desired effect. These conditions > lead to client hanging again. > I checked an opened socket on client side with the command > *netstat -a -n -o > *and found out that it contains system defaut parameters: > *tcp        0      0 192.168.1.12:40961      192.168.1.11:5432       > ESTABLISHED keepalive (7216.12/0/0)* > > After I had changed system keepalive parameters by manual modification > the files > *echo 1 > /proc/sys/net/ipv4/tcp_keepalive_time* > *echo 1 > /proc/sys/net/ipv4/tcp_keepalive_intvl > echo 1 > /proc/sys/net/ipv4/tcp_keepalive_probes* > > I saw that it affected on keepalive parameters and the ODBC client > behaviour and SQLExecute failed when keepalive timeout expired: > *tcp        0      0 192.168.1.12:40972      192.168.1.11:5432       > ESTABLISHED keepalive (3.18/0/0) > > *Nevertheless this is not a good way of configuration because it > affects on whole the system. * > > *Did I do anything wrong with pqopt option? * > * > Best regards, > Andrei Yahorau > > > > From: "Inoue, Hiroshi" > To: AYahorau@ibagroup.eu, > Cc: pgsql-odbc@postgresql.org, MikalaiKeida@ibagroup.eu > Date: 10/07/2018 08:50 > Subject: Re: ODBC cliens is hanging if network connection is broken > ------------------------------------------------------------------------ > > > > > On 2018/07/09 23:06, _AYahorau@ibagroup.eu_ > wrote: > Hello! > > Thank You for quick response. > I set *SQL_ATTR_QUERY_TIMEOUT*to 5 seconds as follows: > > SQLRETURN rc = SQLSetStmtAttr(hstmt, SQL_ATTR_QUERY_TIMEOUT, > (SQLPOINTER) 5, SQL_IS_UINTEGER); > after SQLAllocHandle for hstmt and before SQLExecDirect call. > > To take some time in SQLExecDirect I call the command "*SELECT > pg_sleep(10)*". > If an ODBC aplication does not loose network connection with the > remote server  this command is terminated in 5 seconds after its > invocation. > I get the following error *57014 *(*Cancelling statement due to > statement timeout*). > > In case if network connection is lost(network interface is down) my > ODBC application is indefinitely hanging. > Here is a gstack output of this process:* > gstack 13359* > #0  0x00007fdd045703b0 in __poll_nocancel () from /lib64/libc.so.6 > #1  0x00007fdd037c8626 in ?? () from /usr/lib64/libpq.so.5 > #2  0x00007fdd037c86b0 in ?? () from /usr/lib64/libpq.so.5 > #3  0x00007fdd037c6889 in PQgetResult () from /usr/lib64/libpq.so.5 > #4  0x00007fdd039fbe55 in CC_send_query_append > (self=self@entry=0x10ccc60, query=query@entry=0x7fff2364d470 "SET > statement_timeout = 5000", qi=qi@entry=0x0, flag=flag@entry=0, > stmt=stmt@entry=0x0, appendq=appendq@entry=0x0) at connection.c:1921 > #5  0x00007fdd03a2e3ed in SC_execute (self=self@entry=0x10df840) at > statement.c:1912 > #6  0x00007fdd03a0c596 in Exec_with_parameters_resolved > (stmt=stmt@entry=0x10df840, exec_end=exec_end@entry=0x7fff2364d60c) at > execute.c:450 > #7  0x00007fdd03a0d4b6 in PGAPI_Execute (hstmt=hstmt@entry=0x10df840, > flag=flag@entry=1) at execute.c:1045 > #8  0x00007fdd03a0daac in PGAPI_ExecDirect > (hstmt=hstmt@entry=0x10df840, szSqlStr=szSqlStr@entry=0x4014ed "SELECT > pg_sleep(10)", cbSqlStr=cbSqlStr@entry=-3, flag=flag@entry=1) at > execute.c:191 > #9  0x00007fdd03a3511b in SQLExecDirect (StatementHandle=0x10df840, > StatementText=0x4014ed "SELECT pg_sleep(10)", TextLength=-3) at > odbcapi.c:322 > #10 0x00007fdd04851432 in SQLExecDirect () from /usr/lib64/libodbc.so.2 > #11 0x0000000000400fcf in main (argc=1, argv=0x7fff2364d928) at > odbcExample.c:163 > > Do you have any idea what can be wrong? > > Thank you in advance, > Andrei Yahorau > > > > From: "Inoue, Hiroshi" __ > > To: _AYahorau@ibagroup.eu_ , > Cc: _pgsql-odbc@postgresql.org_ , > _MikalaiKeida@ibagroup.eu_ > Date: 08/07/2018 13:33 > Subject: Re: ODBC cliens is hanging if network connection is broken > > ------------------------------------------------------------------------ > > > > Hi, > > On 2018/07/07 21:37, _AYahorau@ibagroup.eu_ > wrote: > Hello PostgreSQL Community! > > I downloaded and installed the latest version of PostgreSQL from > _https://www.postgresql.org/ftp/source/v10.4/_on my SLES 12 system. > Here is my configuration of unixODBC: > > odbcinst,ini > [PostgreSQL] > Description=PostgreSQL ODBC driver > Driver=/usr/local/lib/psqlodbcw.so > FileUsage=1 > > odbc.ini > [sles12-1] > Description = PostgreSQL connection to rtpdb > Driver = PostgreSQL > Database = rtpdb > Servername = sles12-1 > Username = > Password = > Port = 5432 > Protocol = 7.4+ > ReadOnly = No > RowVersioning = No > ShowSystemTables = No > ConnSettings = > > As a Driver in odbcinst.ini I specified the path to *psqlodbcw.so > *which was downloaded from > _https://git.postgresql.org/gitweb/?p=psqlodbc.git_and built as follows: > ./configure > make > make install > > Could you please provide a comment concerning the following situation? > > I  created a simple ODBC program which calls "*SELECT > pg_is_in_recovery()*" on the remote PostgreSQL server using ODBC API. > It works good with this ODBC configuration. But as soon as I turn off > network interface after *SQLConnect *call and before *SQLExecDirect*, > it leads to *SQLExecDirect *hanging. > > I tried to use *statement_timeout* and > *idle_in_transaction_session_timeout* postgresql configuration > parameters but they were not suitable for network issue case. These > parameters define server-side behaviour but a client considers that > the connection is ok and it is hanging. > > > > As far as I know *SQL_ATTR_CONNECTION_TIMEOUT *ODBC attribute could > handle this situation. Another ODBC driver for another database in > case of similar situation returns *HYT01 *ODBC error (Connection > timeout expired) . But I guess *SQL_ATTR_CONNECTION_TIMEOUT * is not > supported by psqlodbc.  Am I right? > > How about calling SQLSetStmtAttr() with the attribute parameter > SQL_ATTR_QUERY_TIMEOUT? > > > > PostgreSQL JDBC driver provides *socketTimeout*property which helps a > client to be informed about network problems and to avoid an infinite > hanging. > In my tests it returned *08006 *sqlstate (*connection_failure*). > > So I have a question. Is there any psqlodbc or native PostgreSQL > mechanism or configuration parameter which helps a client to be > informed about network problem? > Is there any mechanism which helps to avoid this infinite hanging for > SQL query in this case? > > Could you try options about TCP keepalive using pqopt in odbc.ini > > pqopt = keepalives=1 keepalives_interval=5 keepalives_count=1 > > ? > > regards, > Hiroshi Inoue > > > > Thank You in advance, > Andrei Yahorau --------------B0FB809D647EA6F5E2D4A67C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Hi,

On 2018/07/10 19:40, AYahorau@ibagroup.eu wrote:
Hello,

I added pqopt option into the odbc.ini  file as you suggested:
[sles12-1]
Description = PostgreSQL connection to rtpdb

Driver = PostgreSQL

Database = rtpdb

pqopt = keepalives=1 keepalives_interval=5 keepalives_count=1

Oops I mistook keepalive_idle for keepalive_interval.
Please try

pqopt = keepalives=1 keepalives_idle=5 keepalives_count=1 keepalives_interval=1

regards,
Hiroshi Inoue

Servername = sles12-1
Username =

Password =

Port = 5432

Protocol = 7.4+

ReadOnly = No

RowVersioning = No

ShowSystemTables = No

ConnSettings =


But unfortunately if did not take a desired effect. These conditions lead to client hanging again.
I checked an opened socket on client side with the command
netstat -a -n -o
and found out that it contains system defaut parameters:
tcp        0      0 192.168.1.12:40961      192.168.1.11:5432       ESTABLISHED keepalive (7216.12/0/0)

After I had changed system keepalive parameters by manual modification the files
echo 1 > /proc/sys/net/ipv4/tcp_keepalive_time
echo 1 > /proc/sys/net/ipv4/tcp_keepalive_intvl
echo 1 > /proc/sys/net/ipv4/tcp_keepalive_probes


I saw that it affected on keepalive parameters and the ODBC client behaviour and SQLExecute failed when keepalive timeout expired:

tcp        0      0 192.168.1.12:40972      192.168.1.11:5432       ESTABLISHED keepalive (3.18/0/0)

Nevertheless this is not a good way of configuration because it affects on whole the system.

Did I do anything wrong with pqopt option?

Best regards,
Andrei Yahorau



From:        "Inoue, Hiroshi" <h-inoue@dream.email.ne.jp>
To:        AYahorau@ibagroup.eu,
Cc:        pgsql-odbc@postgresql.org, MikalaiKeida@ibagroup.eu
Date:        10/07/2018 08:50
Subject:        Re: ODBC cliens is hanging if network connection is broken





On 2018/07/09 23:06, AYahorau@ibagroup.eu wrote:
Hello!

Thank You for quick response.
I set
SQL_ATTR_QUERY_TIMEOUT to 5 seconds as follows:

SQLRETURN rc = SQLSetStmtAttr(hstmt, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER) 5, SQL_IS_UINTEGER);

after SQLAllocHandle for hstmt and before SQLExecDirect call.

To take some time in SQLExecDirect I call the command "SELECT pg_sleep(10)".
If an ODBC aplication does not loose network connection with the remote server  this command is terminated in 5 seconds after its invocation.

I get the following error 57014 (Cancelling statement due to statement timeout).

In case if network connection is lost(network interface is down) my ODBC application is indefinitely hanging.
Here is a gstack output of this process:
gstack 13359

#0  0x00007fdd045703b0 in __poll_nocancel () from /lib64/libc.so.6

#1  0x00007fdd037c8626 in ?? () from /usr/lib64/libpq.so.5

#2  0x00007fdd037c86b0 in ?? () from /usr/lib64/libpq.so.5

#3  0x00007fdd037c6889 in PQgetResult () from /usr/lib64/libpq.so.5

#4  0x00007fdd039fbe55 in CC_send_query_append (self=self@entry=0x10ccc60, query=query@entry=0x7fff2364d470 "SET statement_timeout = 5000", qi=qi@entry=0x0, flag=flag@entry=0, stmt=stmt@entry=0x0, appendq=appendq@entry=0x0) at connection.c:1921

#5  0x00007fdd03a2e3ed in SC_execute (self=self@entry=0x10df840) at statement.c:1912

#6  0x00007fdd03a0c596 in Exec_with_parameters_resolved (stmt=stmt@entry=0x10df840, exec_end=exec_end@entry=0x7fff2364d60c) at execute.c:450

#7  0x00007fdd03a0d4b6 in PGAPI_Execute (hstmt=hstmt@entry=0x10df840, flag=flag@entry=1) at execute.c:1045

#8  0x00007fdd03a0daac in PGAPI_ExecDirect (hstmt=hstmt@entry=0x10df840, szSqlStr=szSqlStr@entry=0x4014ed "SELECT pg_sleep(10)", cbSqlStr=cbSqlStr@entry=-3, flag=flag@entry=1) at execute.c:191

#9  0x00007fdd03a3511b in SQLExecDirect (StatementHandle=0x10df840, StatementText=0x4014ed "SELECT pg_sleep(10)", TextLength=-3) at odbcapi.c:322

#10 0x00007fdd04851432 in SQLExecDirect () from /usr/lib64/libodbc.so.2

#11 0x0000000000400fcf in main (argc=1, argv=0x7fff2364d928) at odbcExample.c:163


Do you have any idea what can be wrong?


Thank you in advance,
Andrei Yahorau




From:        
"Inoue, Hiroshi" <h-inoue@dream.email.ne.jp>
To:        
AYahorau@ibagroup.eu,
Cc:        
pgsql-odbc@postgresql.org, MikalaiKeida@ibagroup.eu
Date:        
08/07/2018 13:33
Subject:        
Re: ODBC cliens is hanging if network connection is broken





Hi,

On 2018/07/07 21:37,
AYahorau@ibagroup.eu wrote:
Hello PostgreSQL Community!

I downloaded and installed the latest version of PostgreSQL from
https://www.postgresql.org/ftp/source/v10.4/ on my SLES 12 system.
Here is my configuration of unixODBC:


odbcinst,ini

[PostgreSQL]

Description=PostgreSQL ODBC driver

Driver=/usr/local/lib/psqlodbcw.so

FileUsage=1


odbc.ini

[sles12-1]

Description = PostgreSQL connection to rtpdb

Driver = PostgreSQL

Database = rtpdb

Servername = sles12-1

Username =

Password =

Port = 5432

Protocol = 7.4+

ReadOnly = No

RowVersioning = No

ShowSystemTables = No

ConnSettings =


As a Driver in odbcinst.ini I specified the path to psqlodbcw.so which was downloaded from
https://git.postgresql.org/gitweb/?p=psqlodbc.git and built as follows:
./configure
make
make install


Could you please provide a comment concerning the following situation?


I  created a simple ODBC program which calls "SELECT pg_is_in_recovery()" on the remote PostgreSQL server using ODBC API. It works good with this ODBC configuration. But as soon as I turn off network interface after SQLConnect  call and before SQLExecDirect, it leads to SQLExecDirect hanging.

I tried to use statement_timeout
 and idle_in_transaction_session_timeout  postgresql configuration parameters but they were not suitable for network issue case. These parameters define server-side behaviour but a client considers that the connection is ok and it is hanging.



As far as I know SQL_ATTR_CONNECTION_TIMEOUT ODBC attribute could handle this situation. Another ODBC driver for another database in case of similar situation returns HYT01  ODBC error (
Connection timeout expired) . But I guess  SQL_ATTR_CONNECTION_TIMEOUT  is not supported by psqlodbc.  Am I right?

How about calling SQLSetStmtAttr() with the attribute parameter SQL_ATTR_QUERY_TIMEOUT?




PostgreSQL JDBC driver provides
socketTimeout property which helps a client to be informed about network problems and to avoid an infinite hanging.
In my tests it returned 08006 sqlstate (connection_failure
).

So I have a question. Is there any psqlodbc or native PostgreSQL mechanism or configuration parameter which helps a client to be informed about network problem?
Is there any mechanism which helps to avoid this infinite hanging for SQL query in this case?


Could you try options about TCP keepalive using pqopt in odbc.ini

pqopt =
keepalives=1 keepalives_interval=5 keepalives_count=1

?

regards,
Hiroshi Inoue



Thank You in advance,

Andrei Yahorau

--------------B0FB809D647EA6F5E2D4A67C--