dbTalk Databases Forums  

[BUGS] pg_service.conf ignores dbname parameter

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] pg_service.conf ignores dbname parameter in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Fuhr
 
Posts: n/a

Default [BUGS] pg_service.conf ignores dbname parameter - 12-16-2003 , 08:34 AM






================================================== ==========================
POSTGRESQL BUG REPORT TEMPLATE
================================================== ==========================

Your name : Michael Fuhr
Your email address : mfuhr (AT) fuhr (DOT) org


System Configuration
---------------------
Architecture (example: Intel Pentium) : several

Operating System (example: Linux 2.0.26 ELF) : several

PostgreSQL version (example: PostgreSQL-7.4): PostgreSQL-7.4

Compiler used (example: gcc 2.95.2) : several


Please enter a FULL description of your problem:
------------------------------------------------

When a client connects to the database server using a service name,
the dbname parameter in pg_service.conf is ignored. In the absence
of an explicitly-named database in the connection string, the service
name is used as the database name regardless of that service's
dbname setting.


Please describe a way to repeat the problem. Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------

1. Create/edit pg_service.conf in whatever directory it's supposed
to be in on your system (location varies). Add the following (change
the database and user names as appropriate for your system):

[foobar]
dbname=template1
user=postgres

2. Connect to the database server using the "foobar" service. The
following example should work on most Unix-like systems (you may
or may not be prompted for a password, depending on your configuration):

% env PGSERVICE=foobar psql
Password: ********
psql: FATAL: database "foobar" does not exist


If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------

The problem appears to be in the parseServiceInfo() function in
src/interfaces/libpq/fe-connect.c. Here's an excerpt from that
function:

/*
* If not already set, set the database name to the
* name of the service
*/
for (i = 0; options[i].keyword; i++)
{
if (strcmp(options[i].keyword, "dbname") == 0)
{
if (options[i].val == NULL)
options[i].val = strdup(service);
break;
}
}

/*
* Set the parameter --- but don't override any
* previous explicit setting.
*/
found_keyword = 0;
for (i = 0; options[i].keyword; i++)
{
if (strcmp(options[i].keyword, key) == 0)
{
if (options[i].val == NULL)
options[i].val = strdup(val);
found_keyword = 1;
break;
}
}

Since the database name is already set to be either the service
name or an explicitly named database from the connection string,
the "Set the parameter" section of code skips the dbname parameter.
I haven't yet examined the rest of the code closely enough to come
up with the correct patch, but it seems that the "set the database
name to the name of the service" code should be deferred until
after all of the service's parameters have been read.

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] pg_service.conf ignores dbname parameter - 12-17-2003 , 11:46 AM






Michael Fuhr <mfuhr (AT) fuhr (DOT) org> writes:
Quote:
When a client connects to the database server using a service name,
the dbname parameter in pg_service.conf is ignored. In the absence
of an explicitly-named database in the connection string, the service
name is used as the database name regardless of that service's
dbname setting.
[snip]
I haven't yet examined the rest of the code closely enough to come
up with the correct patch, but it seems that the "set the database
name to the name of the service" code should be deferred until
after all of the service's parameters have been read.
Hm. I'm of the opinion that the real problem here is the code's
assumption that it is reasonable to force dbname = servicename when
the service file doesn't say any such thing. For all other parameters,
omitting the parameter from pg_service.conf causes the standard default
to be adopted. Why should dbname work differently? It saves only a
minimal amount of typing to do it this way, and it might prevent some
useful setups (namely, a service that specifies connection params but
allows the usual default of dbname = username to apply).

Since pg_service was completely undocumented before 7.4, I think it is
safe to say that its usage in the field is nil except for the original
author, and therefore "backwards compatibility" is not really a relevant
argument just yet. We ought to concentrate on "principle of least
astonishment" instead.

Accordingly, I'd rather just delete the offending code instead of move
it. (BTW, I notice Bruce has fooled with this code before, so it's
already in the "known source of problems" category.)

Comments anyone?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.