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

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to