Re: Connecting without specifying a database

Lists: pgsql-interfaces
From: Murray Cumming <murrayc(at)murrayc(dot)com>
To: pgsql-interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: Connecting without specifying a database
Date: 2005-02-10 11:50:23
Message-ID: 1108036223.3706.12.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Can PQconnectdb(), or something else, be used without specifying the
dbname in the connection string? I want to connect just so that I can
create a database that does not exist yet.

When I don't specify the dbname, PQconnectdb() tries to connect to a
database with the same name as the user, and then complains that it does
not exist. Is it really necessary for each user to have an empty
database like this?

--
Murray Cumming
murrayc(at)murrayc(dot)com
www.murrayc.com
www.openismus.com


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Murray Cumming <murrayc(at)murrayc(dot)com>
Cc: pgsql-interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: Connecting without specifying a database
Date: 2005-02-10 13:12:08
Message-ID: 200502100812.09410.xzilla@users.sourceforge.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

On Thursday 10 February 2005 06:50, Murray Cumming wrote:
> Can PQconnectdb(), or something else, be used without specifying the
> dbname in the connection string? I want to connect just so that I can
> create a database that does not exist yet.
>
> When I don't specify the dbname, PQconnectdb() tries to connect to a
> database with the same name as the user, and then complains that it does
> not exist. Is it really necessary for each user to have an empty
> database like this?

Most applications choose to connect to template1 in these scenarios.

--
Robert Treat
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL


From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Murray Cumming <murrayc(at)murrayc(dot)com>
Cc: pgsql-interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: Connecting without specifying a database
Date: 2005-02-10 14:38:29
Message-ID: 20050210143829.GA68483@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

On Thu, Feb 10, 2005 at 12:50:23PM +0100, Murray Cumming wrote:
>
> Can PQconnectdb(), or something else, be used without specifying the
> dbname in the connection string? I want to connect just so that I can
> create a database that does not exist yet.

See "Environment Variables" in the libpq chapter of the documentation:

http://www.postgresql.org/docs/8.0/static/libpq-envars.html

> When I don't specify the dbname, PQconnectdb() tries to connect to a
> database with the same name as the user, and then complains that it does
> not exist. Is it really necessary for each user to have an empty
> database like this?

No, but you have to connect to *some* database. As Robert Treat
mentioned, you could connect to template1 if you just need to issue
a CREATE DATABASE statement.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/