pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Murray Cumming <murrayc@murrayc.com>
Cc: pgsql-interfaces <pgsql-interfaces@postgresql.org>
Subject: Re: Connecting without specifying a database
Date: Thu, 10 Feb 2005 07:38:29 -0700
Message-ID: <20050210143829.GA68483@winnie.fuhr.org> (raw)
In-Reply-To: <1108036223.3706.12.camel@localhost.localdomain>
References: <1108036223.3706.12.camel@localhost.localdomain>

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/



view thread (3+ messages)

Message-ID: <20050210143829.GA68483@winnie.fuhr.org>
Permalink:  ../20050210143829.GA68483@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050210143829.GA68483@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: mike@fuhr.org, murrayc@murrayc.com
  Subject: Re: Connecting without specifying a database
  In-Reply-To: <20050210143829.GA68483@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox