Re: Create Database using JDBC - Mailing list pgsql-jdbc

From Markus Schaber
Subject Re: Create Database using JDBC
Date
Msg-id 43A41044.2010802@logix-tt.com
Whole thread Raw
In response to Create Database using JDBC  ("Nidhi Srivastava" <nsrivastava@quark.com>)
Responses Re: Create Database using JDBC  ("Jim C. Nasby" <jnasby@pervasive.com>)
List pgsql-jdbc
Hi, Nidhi,

Nidhi Srivastava schrieb:

> I wish to create a database if one doesn’t exist using JDBC. I tried
> connecting to template1 database and then issuing the “CREATE DATABASE
> test” command but I get the following error :
>
> ERROR:  CREATE DATABASE: source database "template1"
>
> is being accessed by other users
>
> How do I resolve this? I’m using PostGreSQL8.0

This is a PostgreSQL limitation, in that you cannot use a database as
template if anyone else except the one who issued the create database
has a connection to it.

You can either use "template0" as template (if you did not apply any
modifications to template1), or create your own templateblah database
which you use as template.

Btw, the Debian PostgreSQL packagers seem to add an empty database
called "postgresql" to each cluster, and then all tools (e. G. pgadmin)
are told to use this database to connect against, so the template
database is kept reserved for real templating issues. Maybe this could
be adopted upstream.

HTH,
Markus

pgsql-jdbc by date:

Previous
From: Simon Moses
Date:
Subject: Re: setting & using connection pool in beans for tomcat.
Next
From: Markus Schaber
Date:
Subject: Re: Create Database using JDBC