[bug fix] connection service file doesn't take effect with ECPG apps

From: "MauMau" <maumau307(at)gmail(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: [bug fix] connection service file doesn't take effect with ECPG apps
Date: 2013-12-17 12:26:49
Message-ID: 6ABE137B9CF04026B6902A192A0FFE22@maumau
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

I've found a small bug of ECPG and attached a patch. I tested the fix with
9.4. I'd like the fix to be back-ported.

[Problem]
The ECPG app runs the statement:

EXEC SQL CONNECT TO 'tcp:postgresql://?service=my_service';

I want this app to connect to any database based on the connection service
file.
For example, I wrote the following connection service file pg_service.conf,
placed it in the current directory, set PGSERVICEFILE environment variable
to point to it:

[my_service]
dbname = mydb
host = myhost
port = 5555

myhost is a different host than the one where the app runs.

Unfortunately, the app could not connect to the intended database. It tried
to connect to the (non-existent) database server on the local machine and
failed.

[Cause]
ECPGconnect() parses the URI and produces an empty host name. It passes an
empty string as the value for "host" connection parameter to
PQconnectdbParams().

Given an empty host name, PQconnectdbParams() ignores the host parameter in
pg_service.conf. When host is "", PQconnectdbParams() try to connect via
local UNIX domain socket.

[Fix]
It doesn't make sense for ECPGconnect() to pass an empty host name to
PQconnectdbParams(), so prevent it from passing host parameter for the
service setting to take effect. port is the same.

Regards
MauMau

Attachment Content-Type Size
ecpg_service.patch application/octet-stream 804 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2013-12-17 12:29:34 Re: Optimize kernel readahead using buffer access strategy
Previous Message MauMau 2013-12-17 12:03:38 Re: [bug fix] pg_ctl always uses the same event source