[bug fix] connection service file doesn't take effect with ECPG apps - Mailing list pgsql-hackers

From MauMau
Subject [bug fix] connection service file doesn't take effect with ECPG apps
Date
Msg-id 6ABE137B9CF04026B6902A192A0FFE22@maumau
Whole thread Raw
Responses Re: [bug fix] connection service file doesn't take effect with ECPG apps
List 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

pgsql-hackers by date:

Previous
From: "MauMau"
Date:
Subject: Re: [bug fix] pg_ctl always uses the same event source
Next
From: Simon Riggs
Date:
Subject: Re: Optimize kernel readahead using buffer access strategy