DB2更改文件路徑和名稱的方法 個人感覺DB2更改文件名的方法有點麻煩,雖然步驟也不是很多,可能是習慣於ORACLE的方法造成的。 www.2cto.com 在ORACLE中更改數據文件的路徑是比較簡單的事情,尤其在12C之後,如下一個簡單的命令就可以更改文件路徑: ALTER DATABASE MOVE DATAFILE 4 TO '/data/orcl/user01.dbf' 即便在12C之前移動文件也算相對簡單: 將相關的文件離線--ALTER DATABASE DATAFILE 4 OFFLINE 在操作系統級別更改文件位置或名稱 --mv /data1/orcl/user01.dbf /data/orcl/user01.dbf 更新控制文件指針 --alter database rename datafile 4 to '/data/orcl/user01.dbf' 將文件在線--ALTER DATABASE DATAFILE 4 ONLINE 在DB2中移動文件或者改名需要借助於備份,這有點蛋疼,對於從ORACLE轉到DB2的數據庫工程師來說,可能不太適應。 www.2cto.com 下面簡單看一下這個操作步驟: 下面是將表空間TEST的文件修改文件路徑並且命名。 [yansp@db2server ~]$ db2 connect to testdb Database Connection Information Database server = DB2/LINUX 9.7.0 SQL authorization ID = YANSP Local database alias = TESTDB [yansp@db2server ~]$ db2 list tablespace containers for 7 Tablespace Containers for Tablespace 7 Container ID = 0 Name = /dbauto/manual/test1.dbf Type = File Container ID = 1 Name = /dbauto/manual/test2.dbf Type = File www.2cto.com 表空間TEST有2個容器test1.dbf和test2.dbf,下面我們將其移動到上層目錄,並且修改文件名。 [yansp@db2server ~]$ db2 restore database testdb tablespace \(test\) from '/tmp' taken at 20130219003935 redirect SQL1277W A redirected restore operation is being performed. Table space configuration can now be viewed and table spaces that do not use automatic storage can have their containers reconfigured. DB20000I The RESTORE DATABASE command completed successfully. [yansp@db2server ~]$ db2 "set tablespace containers for 7 using (file '/dbauto/test01.dbf' 2000,file '/dbauto/test02.dbf' 2000)" DB20000I The SET TABLESPACE CONTAINERS command completed successfully. [yansp@db2server ~]$ db2 restore database testdb continue DB20000I The RESTORE DATABASE command completed successfully. [yansp@db2server ~]$ db2 rollforward database testdb to end of logs and stop Rollforward Status Input database alias = testdb Number of nodes have returned status = 1 Node number = 0 Rollforward status = not pending Next log file to be read = Log files processed = - Last committed transaction = 1970-01-01-00.00.00.000000 UTC DB20000I The ROLLFORWARD command completed successfully. [yansp@db2server ~]$ db2 list tablespace containers for 7 SQL1024N A database connection does not exist. SQLSTATE=08003 [yansp@db2server ~]$ db2 connect to testdb Database Connection Information Database server = DB2/LINUX 9.7.0 SQL authorization ID = YANSP Local database alias = TESTDB [yansp@db2server ~]$ db2 list tablespace containers for 7 Tablespace Containers for Tablespace 7 Container ID = 0 Name = /dbauto/test01.dbf Type = File Container ID = 1 Name = /dbauto/test02.dbf Type = File