Re: Q on requirement to connect to a specific DB - Mailing list pgsql-novice

From Tom Lane
Subject Re: Q on requirement to connect to a specific DB
Date
Msg-id 17844.1147656688@sss.pgh.pa.us
Whole thread Raw
In response to Q on requirement to connect to a specific DB  (<kynn@panix.com>)
List pgsql-novice
<kynn@panix.com> writes:
> As far as I know I must connect to *some*
> database, whose role is irrelevant, just so that I can execute "CREATE
> DATABASE ..."  from that connection.

Correct.

> I find this puzzling from a design perspective.  Why involve some
> irrelevant DB in the process of creating a new one?

Because the backend can't operate without a set of system catalogs
to interrogate.  We could maybe have a dummy database that had no
other purpose than to be connected to for specific commands ...
oh wait, that's pretty much what we do have.

> If so, what is the "canonical" database to connect to?  (Is this the
> purpose of "template1"?)

Pre-8.1, that was the usual convention, but as of 8.1 we manufacture
an additional "standard" database named "postgres", and that's the
recommended connection target if you have no better alternative.
The reason for the change is that "template1" has the additional
function of being the default database-to-clone for CREATE DATABASE,
and there was too much conflict between those two uses.

            regards, tom lane

pgsql-novice by date:

Previous
From: Sean Davis
Date:
Subject: Re: Q on requirement to connect to a specific DB
Next
From: "Robert Landsmeer"
Date:
Subject: Re: Wondering if anyone could help me