Unix Technical Forum

Q on requirement to connect to a specific DB

This is a discussion on Q on requirement to connect to a specific DB within the pgsql Novice forums, part of the PostgreSQL category; --> As far as I understand, one always has to connect to a specific database even when what one wants ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:52 PM
kynn@panix.com
 
Posts: n/a
Default Q on requirement to connect to a specific DB




As far as I understand, one always has to connect to a specific
database even when what one wants to do does not have anything to do
with any existing database. For example, suppose I just want to
create a new database. 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.

I find this puzzling from a design perspective. Why involve some
irrelevant DB in the process of creating a new one? Am I
understanding the whole situation correctly? If so, what is the
"canonical" database to connect to? (Is this the purpose of
"template1"?)

Thanks!

kj


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:52 PM
Sean Davis
 
Posts: n/a
Default Re: Q on requirement to connect to a specific DB

kynn@panix.com wrote:
> As far as I understand, one always has to connect to a specific
> database even when what one wants to do does not have anything to do
> with any existing database. For example, suppose I just want to
> create a new database. 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.


You can also use the createdb program.

Sean

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 10:52 PM
Tom Lane
 
Posts: n/a
Default Re: Q on requirement to connect to a specific DB

<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

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:33 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com