From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Michael Fuhr <mfuhr(at)fuhr(dot)org> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: pg_service.conf ignores dbname parameter |
Date: | 2003-12-19 21:50:31 |
Message-ID: | 200312192150.hBJLoVq07836@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-hackers |
I have applied the attached patch to remove the default
dbname=serive-name code, changed the comment at the top of the file, and
changed a few ints to booleans.
---------------------------------------------------------------------------
Michael Fuhr wrote:
> ============================================================================
> 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
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/plain | 4.1 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2003-12-19 21:52:27 | Re: [BUGS] pg_service.conf ignores dbname parameter |
Previous Message | Lamar Owen | 2003-12-19 21:38:03 | Re: Jdbc connection pooling and PG 7.4 consistently fails |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2003-12-19 21:52:27 | Re: [BUGS] pg_service.conf ignores dbname parameter |
Previous Message | Joshua D. Drake | 2003-12-19 21:36:41 | Re: PostgreSQL speakers needed for OSCON 2004 |