Problem with "create database ... with template "

From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Problem with "create database ... with template "
Date: 2007-05-09 18:03:43
Message-ID: Pine.LNX.4.64.0705092105280.12152@sn.sai.msu.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi there,

I'm investigating a problem my client experienced with
"create database xxx with template=yyy" - they often get error
"ERROR: source database "yyy" is being accessed by other users",

I modelled situation in clean environment with very simple perl script
( FreeBSD 6.2-STABLE, postgresql-8.2.3 from ports ) and was able to
reproduce the problem. There were no other connections ( I checked log ).
I tried shell script and got the same problem. Is this a known problem ?

perl testcreatedb.pl
Repeat #:1
Repeat #:2
Repeat #:3
Repeat #:4
Repeat #:5
Repeat #:6
Repeat #:7
Repeat #:8
Repeat #:9
Repeat #:10
Repeat #:11
Repeat #:12
Repeat #:13
Repeat #:14
Repeat #:15
Repeat #:16
DBD::Pg::db do failed: ERROR: source database "yyy" is being accessed by other users
DBD::Pg::db do failed: ERROR: source database "yyy" is being accessed by other users

----------- cut here -----------
#!/usr/bin/perl

use strict;
use DBI;

my $dbh;
my $rv = undef;

foreach my $i ( 1..100) {

$dbh = DBI->connect('dbi:Pg:database=yyy;host=msk2.socionet.ru;port=5432','db_user','',{ RaiseError => 1}) or
die "Can't connect to database !\n";

print STDERR "Repeat #:$i\n";

$rv = $dbh->do('drop database xxx');
$rv = $dbh->do('create database xxx with TEMPLATE=yyy');

print STDERR "error creating database: $rv\n" if ( $rv ne '0E0' );

$dbh->disconnect;
--------------- cut here -------------

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
Sternberg Astronomical Institute, Moscow University, Russia
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(495)939-16-83, +007(495)939-23-83

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-05-09 18:31:54 Re: Problem with "create database ... with template "
Previous Message Josh Berkus 2007-05-09 18:01:49 Re: Managing the community information stream