problem calling psql multiple times from a script ? - Mailing list pgsql-general

From Paul Tilles
Subject problem calling psql multiple times from a script ?
Date
Msg-id 465D8F7A.8090903@noaa.gov
Whole thread Raw
Responses Re: problem calling psql multiple times from a script ?
List 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

pgsql-general by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: 8.3
Next
From: "Joshua D. Drake"
Date:
Subject: Re: 8.3