Problem
When trying to restore a database from backup, you might get an SQL1005N “The database alias “dabase_name” already exists in either the local database directory or system database directory.”
Solution
$ export DB2NODE=0
$ db2 terminate
DB20000I The TERMINATE command completed successfully.
$ db2 restore database <dabase_name> from <source_directory> to <destination>
SQL1005N The database alias "dabase_name" already exists in either the local
database directory or system database directory. SQLSTATE=00000
$ db2 update dbm cfg using DFTDBPATH <destination>
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
$ db2 create database sample at dbpartitionnum
DB20000I The CREATE DATABASE AT NODE command completed successfully.
$ db2 restore database <dabase_name> from <source_directory> to <destination>
SQL2539W Warning! Restoring to an existing database that is the same as the backup image database. The database files will be deleted.
Do you want to continue ? (y/n) y
DB20000I The RESTORE DATABASE command completed successfully.
Note that on DB2 9.7 the command
$ db2 terminate
allows you to refresh the catalog directory cache.
