databasedb2database-backupsdb2-luwdatabase-restore

Preserve restrictive flag when restoring Db2 database


Is there any way to preserve the Db2 restrictive mode setting during a database restore?

Problem: The restrictive flag is overwritten when restoring a backup of a non-restrictive Db2 database into an existing, restrictive Db2 database.

[1] IBM Db2 - Restoring to an existing database

https://www.ibm.com/docs/en/db2/11.5?topic=data-existing-database

[2] IBM Db2 - A practical guide to restrictive databases

https://community.ibm.com/community/user/datamanagement/viewdocument/a-practical-guide-to-restrictive-da

Regarding [2]:

To create a restrictive database, you need to specify the RESTRICTIVE keyword with the CREATE DATABASE command. Here is an example:

db2 CREATE DATABASE testdb RESTRICTIVE;

After the restrict_access parameter is set when the database is created, it cannot be modified. This sets the restrict_access database configuration parameter to YES.

In the practical guide [2] there is no comment regarding backup/restore indeed in the KC [1](Last udpdate 24.1.2024) it would suggest under the point

"When restoring to an existing database, the restore utility performs the following actions: (...)"

that the restrict_access configuration parameter stays/must stay in place as set during database creation.

Tested Version: Db2 LUW 11.5 on rhel 8


Solution

  • The expectation in the question is incorrect, a "restore ... into" will only inherit the name/alias of the database that is about to be overwritten (if it exists). That is to say, restore database... into... will NOT preserve any attributes or settings of the old database being overwritten apart from name/alias.

    If the source-database (i.e the database whose backup image is being restored) is itself unrestricted, then any restored backup-image of that source-database will itself also be unrestricted. Similarly, if the original source database was restricted, then any restored backup-image of that restricted database will itself be restricted.

    That is how the Db2-LUW product (at v11.5) currently works. There exists (currently) no generally available IBM supplied script to "convert" an unrestricted-database into a restrictive-database (or vice-versa), although that might change in future. The catalog contents (as regards authorizations and permissions) are quite different.