Thread: Problem creating a database in a script; '"template1" is being accessed'

Problem creating a database in a script; '"template1" is being accessed'

From
Madison Kelly
Date:
Hi all,

   I've got a script that creates a database for my program in it's
installer script. The problem I am having is that when the installer calls:

/usr/bin/createdb tle-bu -U tle-bu

   I often get the error:

createdb: database creation failed: ERROR:  source database "template1"
is being accessed by other users

   Which is not the case. If I issue the same command from the command
line it works fine. I thought it might be a race condition (because the
step before that is to add the DB user) so I added a 1 second sleep but
it didn't help.

   Is there anything you guys might suggest?

Thanks!

Madison

PS - Here is the Perl code snippet for reference:

my $cd = new FileHandle;
-U $db_user 2>&1 |]\n"; }
if ( $cd->open("$createdb_path $db_name -U $db_user 2>&1 |") )
{
    while (<$cd>)
    {
        chomp;
        print " |- DEBUG: Create Database: [$_]\n";
    }
}
$cd->close;

Re: Problem creating a database in a script; '"template1" is being accessed'

From
Dennis Jenkins
Date:

--- Madison Kelly <linux@alteeve.com> wrote:

> Hi all,
>
> createdb: database creation failed: ERROR:  source
> database "template1"
> is being accessed by other users


I get that error every time that anyone is connected
to the database using pgAdmin.  We have to get
everyone to disconnect before we can create a
database.

Everyone out of the pool!  Adult swim!


Dennis Jenkins

Re: Problem creating a database in a script; '"template1"

From
Madison Kelly
Date:
Dennis Jenkins wrote:
>
> --- Madison Kelly <linux@alteeve.com> wrote:
>
>
>>Hi all,
>>
>>createdb: database creation failed: ERROR:  source
>>database "template1"
>>is being accessed by other users
>
>
>
> I get that error every time that anyone is connected
> to the database using pgAdmin.  We have to get
> everyone to disconnect before we can create a
> database.
>
> Everyone out of the pool!  Adult swim!
>
>
> Dennis Jenkins


Haha,

   I found a tip from google goups that suggested adding '-T template0'
which seems to have just solved my problem. Maybe it would help you, too?

Madison