problem calling psql multiple times from a script ?

From: Paul Tilles <Paul(dot)Tilles(at)noaa(dot)gov>
To: pgsql-general(at)postgresql(dot)org
Subject: problem calling psql multiple times from a script ?
Date: 2007-05-30 14:51:38
Message-ID: 465D8F7A.8090903@noaa.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am executing a script which contains multiple executions of psql.
The last execution of psql renames the database. It looks something
like the following

psql -f create_tables.sql db_name1

psql -f modify_tables.sql db_name1

psql -f add_indexes.sql db_name1

psql template1 <<XX_rename
ALTER DATABASE db_name1 RENAME TO db_name2;
XX_rename

I notice sometimes that the "ALTER DATABASE ... RENAME ..." statement
fails with an error that a user has the database (db_name1) open.

I am wondering if one of the previous executions of psql is doing some
"back room" work in the database while allowing the script to continue.
I am wondering if this "back room" work prevents the database from being
renamed. Which system table could I check to see if the database is open?

I have seen this type of "back room" behavior with our Informix
databases. Multiple calls to dbaccess followed by a database rename
caused the rename to fail in some cases. I had to add a loop with a
"sleep" followed by a check if the database was open.

We are using postgres Version 7.4.8.

TIA.

Paul Tilles

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2007-05-30 15:04:19 Re: 8.3
Previous Message Gino.Barille 2007-05-30 14:32:41 On-line / off-line trace of SQL statements presented to the Postgres SQL engine