relocate and rename datafile 方法、示例

本文介绍了Oracle数据库中两种重命名数据文件的方法:alter database rename file 和 alter tablespace renamedatafile。提供了详细的步骤和示例,包括离线表空间、复制文件及更改数据库控制文件记录等操作。
 对于rename datafile方法有两种,可以分为
        alter database  rename file ... to ...
        alter tablespace ... rename datafile ... to ...
        关于这两种方法,官网链接如下
http://docs.oracle.com/cd/E11882_01/server.112/e25494/tspaces.htm#ADMIN12490

 一 . alter database rename file  ... to ...方法、示例

这种方法适用于所有的数据文件,包含system数据文件
需要注意的是,
        rename到目标位置的数据文件,必须手动拷贝到目标位置,alter database  rename file ... to ...命令不会去创建文件。
步骤如下
    To rename datafiles of several tablespaces in one operation or to rename 
datafiles of the SYSTEM tablespace, you must have the ALTER DATABASE system
privilege. 
1.Ensure that the database is mounted but closed. 

2.Copy the datafiles to be renamed to their new locations and new names, using operating system commands. 

3.Make sure the new copies of the datafiles have different fully specified filenames from the datafiles currently in use. 

4.Use the SQL statement ALTER DATABASE to rename the file pointers in the database's control file. 

5.Open the database.

6.Back up the database. After making any structural changes to a database, always perform an immediate and complete backup
        
示例如下
变更前检查数据文件所在路径

  1. > select file_name,tablespace_name from dba_data_files;

  2. FILE_NAME TABLESPACE_NAME
  3. -------------------------------------------------------------------------------- ------------------------------
  4. /s01/oracle/app/oracle/oradata/test/system01.dbf SYSTEM
  5. /s01/oracle/app/oracle/oradata/test/sysaux01.dbf SYSAUX
  6. /s01/oracle/app/oracle/oradata/test/undotbs01.dbf UNDOTBS1
  7. /s01/oracle/app/oracle/oradata/test/users01.dbf USERS
  8. /s01/oracle/app/oracle/oradata/test/users02.dbf USERS
1. 确认当前数据库处于closed但mount状态

  1. > shutdown immediate
  2. Database closed.
  3. Database dismounted.
  4. ORACLE instance shut down.
  5. > startup mount;
  6. ORACLE instance started.

  7. Total System Global Area 839282688 bytes
  8. Fixed Size 2257880 bytes
  9. Variable Size 784337960 bytes
  10. Database Buffers 50331648 bytes
  11. Redo Buffers 2355200 bytes
  12. Database mounted.
2. 手动将数据文件拷贝到新的位置,示例中将    
    /
s01/oracle/app/oracle/oradata/test/users02.dbf 和/s01/oracle/app/oracle/oradata/test/temp01.dbf 
    rename 到 
/home/oracle/user.dbf和/home/oracle/temp.dbf
3. 确认已经将数据文件拷贝到目标位置

  1. [oracle@uumile ~]$ cd /s01/oracle/app/oracle/oradata/test/
  2. [oracle@uumile test]$ cp users02.dbf /home/oracle/user.dbf
  3. [oracle@uumile test]$ cp temp01.dbf /home/oracle/temp.dbf
  4. [oracle@uumile ~]$ cd /home/oracle
  5. [oracle@uumile ~]$ ls -*.dbf
  6. -rw-r----- 1 oracle oinstall 20979712 Feb 26 13:40 temp.dbf
  7. -rw-r----- 1 oracle oinstall 10493952 Feb 26 13:39 user.dbf
4. 使用alter database rename file ... to ...命令修改控制文件中的数据文件路径指向。

  1. > alter database rename file \'/s01/oracle/app/oracle/oradata/test/temp01.dbf\',
  2.   2          '/s01/oracle/app/oracle/oradata/test/users02.dbf\'
  3.   3      to    '/home/oracle/temp.dbf\',
  4.   4             '/home/oracle/user.dbf\';

  5. Database altered.
5. open database 

  1. > alter database open;

  2. Database altered.

  3. > select file_name,tablespace_name from dba_data_files;

  4. FILE_NAME TABLESPACE_NAME
  5. -------------------------------------------------------------------------------- ------------------------------
  6. /s01/oracle/app/oracle/oradata/test/system01.dbf SYSTEM
  7. /s01/oracle/app/oracle/oradata/test/sysaux01.dbf SYSAUX
  8. /s01/oracle/app/oracle/oradata/test/undotbs01.dbf UNDOTBS1
  9. /s01/oracle/app/oracle/oradata/test/users01.dbf USERS
  10. /home/oracle/user.dbf USERS

  11. > select file_name,tablespace_name from dba_temp_files;

  12. FILE_NAME TABLESPACE_NAME
  13. -------------------------------------------------------------------------------- ------------------------------
  14. /home/oracle/temp.dbf TEMP
6. 备份全库。


二 . alter tablespace XXX rename datafile ... to ...方法、示例

这种方法适用于非system数据文件的rename,
这种方法同样需要手动拷贝数据文件到目标位置,alter tablespace XXX rename datafile ... to ... 命令不会去自动创建文件。
步骤如下

1.Take the non-SYSTEM tablespace that contains the datafiles offline. The database must be open
   
2.Copy the datafiles to the new location or new names using operating system 
commands. 
   
3.Make sure that the new, fully specified filenames are different from the old 
filenames. 
   
4.Use the SQL statement ALTER TABLESPACE with the RENAME DATAFILE option to 
change the filenames within the database. 

5.Bring the tablespace online

6. Back up the database. After making any structural changes to a database, always perform an immediate and complete backup


示例
rename前数据文件路径检查

  1. > select file_name,tablespace_name from dba_data_files;

  2. FILE_NAME TABLESPACE_NAME
  3. -------------------------------------------------------------------------------- ------------------------------
  4. /s01/oracle/app/oracle/oradata/test/system01.dbf SYSTEM
  5. /s01/oracle/app/oracle/oradata/test/sysaux01.dbf SYSAUX
  6. /s01/oracle/app/oracle/oradata/test/undotbs01.dbf UNDOTBS1
  7. /s01/oracle/app/oracle/oradata/test/users01.dbf USERS
  8. /home/oracle/user.dbf USERS
1. 需要rename的数据文件所在的tablespace offline

  1. > alter tablespace users offline normal;

  2. Tablespace altered.
2. 手动拷贝数据文件到目标位置

  1. [oracle@uumile ~]$ pwd
  2. /home/oracle
  3. [oracle@uumile ~]$ cp user.dbf /s01/oracle/app/oracle/oradata/test/users02.dbf
3. 确认数据文件已经拷贝成功

  1. [oracle@uumile ~]$ cd /s01/oracle/app/oracle/oradata/test/
  2. [oracle@uumile test]$ ls users02.dbf 
  3. users02.dbf
4. 使用alter tablespace 命令rename datafile 到目标位置

  1. > alter tablespace users rename datafile  '/home/oracle/user.dbf' to 
  2.   2 '/s01/oracle/app/oracle/oradata/test/users02.dbf';

  3. Tablespace altered.
5. 将目标表空间online,并检查数据文件路径

  1. > alter tablespace users online;

  2. Tablespace altered.

  3. > select file_name,tablespace_name from dba_data_files;

  4. FILE_NAME TABLESPACE_NAME
  5. -------------------------------------------------------------------------------- ------------------------------
  6. /s01/oracle/app/oracle/oradata/test/system01.dbf SYSTEM
  7. /s01/oracle/app/oracle/oradata/test/sysaux01.dbf SYSAUX
  8. /s01/oracle/app/oracle/oradata/test/undotbs01.dbf UNDOTBS1
  9. /s01/oracle/app/oracle/oradata/test/users01.dbf USERS
  10. /s01/oracle/app/oracle/oradata/test/users02.dbf USERS
6. 备份全库。



这里需要注意的是,temporary tablespace 是不能offline的,但是temporary tablespace的tempfile可以offline。
官网链接如下
http://docs.oracle.com/cd/E11882_01/server.112/e25494/tspaces.htm#ADMIN11369

/*! * @file main.c * * @brief Main program body * * @version V1.0.1 * * @date 2021-07-01 */ #include "Board.h" #include "stdio.h" #include "common.h" #include "spi.h" #include "apm32f0xx_pwm_timer.h" #include "adc.h" #include "adc_mcp3421.h" #include "powermanager/powermanager.h" #include "motor/motor.h" #include "detector/detection.h" #include "detector/injectoropt.h" #include "detector/pressure.h" #include "pinmulticonf.h" #include "eeprom_at24c01c.h" #include "powermanager/lowpower.h" #include "parameter.h" #include "protocol/protocol.h" #include "uart_debug.h" #include "i2c.h" #include "DataLinkLayer.h" #include "config/syscfgfile1.h" #include "config/syscfgfile2.h" #include "apm32f0xx_tmr.h" #include "motor.h" #include "apm32f0xx.h" #include "eeprom_at24c01c.h" #include "debug.h" #include "rtc.h" //#define M0_DEBUG 1 #define DEBUG_UART 1 #ifdef M0_DEBUG SYSMOD SysMod = SYS_INIT_MOD; #else SYSMOD SysMod = SYS_SLEEP_MOD; //default mod SLEEPMOD; #endif /********************************************************************/ uint8 INFUSION; uint8 INJECTORPUMP; extern uint8 AbnormalFlag; SYSCFG_DESCRIPTOR SysCfgDescriptor; //extern void LowPowerPinConf ( void ); //extern int giSndHeartBeatResendErrorCount; //extern int giRevHeartBeatCount; //extern volatile uint8 gMCURunCountFlag; // MCU run flag //extern volatile uint8 gMCUSleepCountFlag; // MCU unsleep flag extern PRESS_INFOR gPressInfor; extern char injecEmptyAlarmFlag; char isPressCoffeErr = 0; //压力系数出错标志 /*void SleepModBasicInit ( void ) { #ifdef DEBUG_UART //UartDebugInit(); //应该是用不到 #endif // MPowerPinConf ( TRUE ); // BeepPinInit ( TRUE ); // BatteryPinConf ( TRUE ); SystickInit(); }*/ static int32 RunModBasicInit ( void ) { uint32_t adError = 0; RTCInit(); initShutdownVar(); //AdcCalibrate(); AdcInit(); //hwg240202: 初始化后,直接启动ADC转换; //BatteryDeteInit(); #ifdef M0_DEBUG delay_ms ( 1000 ); //motor and other power enable MainUnitPowerOn ( TRUE ); delay_ms ( 500 ); #endif MotorInit(); WifiOn ( TRUE ); DetectModulInit(); SerialProtocolFunInit();//控制板和按键板串口通信 while ( !AdCs1237Init() ) //压力传感器初始化,循环初始化保证能够初始化成功 { adError++; if ( adError > 10000 ) { //trigger device fault 11 alarm PackMessage ( &CommToM4.m_AppCtrl.m_TxMsgBuffCtrl, SND_UPSTREAM_SENSOR_ALARM, EProtocolType_Notice, 0, NULL ); //AD fail Alarm break; } } Eeprom24c01cInit ( I2C1 ); //eeprom存储器 if ( File1SyscfgSelftest() != SYSCFG_ERR_NONE ) { isPressCoffeErr = 1; PackMessage ( &CommToM4.m_AppCtrl.m_TxMsgBuffCtrl, SND_EEPROM_ERR_ALARM, EProtocolType_Data, 0, NULL ); } else { isPressCoffeErr = 0; } InjectDiaDeteInit(); //hwg240202: AD转换在battery检测初始化里启动。 PressureModulInit(); //pressure init return 0; } void systickTimerEnable ( void ) { TimerOn_ms ( PressDeteTimer, TIME_125MS ); TimerOn_ms ( NormalDeteTimer, TIME_1S ); TimerOn_ms ( PowerBatteryTimer, TIME_1S ); //battery dete TIMER6 TimerOn_ms ( HeartBeatTimer, TIME_1S ); //M0 HEART_BEAT TIMER5 TimerOn_ms ( HeartTestTimer, TIME_5min ); //M4 HEART_BEAT TIMER8 TIME_5min TimerOn_ms ( DataProcessTimer, 30 ); //串口收发定时器 TimerOn_ms ( RTCUpdataTimer, 200 ); } void systickTimerDisable(void) { TimerOff_ms ( PressDeteTimer ); TimerOff_ms ( NormalDeteTimer ); TimerOff_ms ( PowerBatteryTimer ); //battery dete TIMER6 TimerOff_ms ( HeartBeatTimer ); //M0 HEART_BEAT TIMER5 TimerOff_ms ( HeartTestTimer ); //M4 HEART_BEAT TIMER8 TIME_5min TimerOff_ms ( DataProcessTimer ); //串口收发定时器 TimerOff_ms ( RTCUpdataTimer ); } #define ApplicationAddress ((uint32_t)0x08002000) void IAP_Set ( void ) { uint32_t i = 0; /* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/ /* 复制ApplicationAddress开始的向量表,映射到SRAM中0x20000000 */ for ( i = 0; i < 48; i++ ) { * ( ( uint32_t * ) ( 0x20000000 + ( i << 2 ) ) ) = * ( __IO uint32_t * ) ( ApplicationAddress + ( i << 2 ) ); } /* 使能系统时钟*/ RCM_EnableAPB2PeriphClock ( RCM_APB2_PERIPH_SYSCFG ); /* Remap SRAM at 0x00000000 */ SYSCFG->CFG1_B.MMSEL = ( uint8_t )0x03; } /*! * @brief Main program * * @param None * * @retval None * * @note */ int main ( void ) //hwg240201: 参考输液泵的修改记录 { #if DEBUG_ENTER_DEBUG_MODE #else IAP_Set(); #endif SysIntPriorityConf(); //hwg240201 INFUSION = 0; INJECTORPUMP = 1; //hwg240201: 硬件已固定为GND下拉; SysMod = SYS_SLEEP_MOD; SystickInit(); EnableGpioClock(); pinConf2PullDownVdd(); //hwg250219:这里配合关掉VDD,延时后再进入低功耗模式,烧录完成时,这里会起作用。 wakeUpPinBasicConf(); //开机键 ledCtrlPinConf(); redLedBlink_ms(2,500); delay_ms( 1000 ); while ( 1 ) { while( SysMod == SYS_SLEEP_MOD ) { #if DEBUG_AUTO_RUN batteryInfoInit(); SysMod = SYS_INIT_MOD; #else ledCtrlPinConf (); greenLedBlink_ms(2,200); //hwg:240116/ 绿灯闪烁一下; sleepModeUnusedPinConf(); //hwg:240115/ 睡眠模式非必要引脚配置; runLowPowerMod(); //hwg:240115/ LowPowerMod() rename,进入低功耗(停止)模式,PC10外部中断唤醒后退出; SystemInit(); //hwg:240116/ 退出停止模式后,需要重新配置系统时钟,reconfigure system clock wakeUpPinBasicConf(); //hwg:240116/ 开机键配置为上拉输入模式; if ( powerOnPinEffectiveCheck() ) //hwg:240116/ 开机键去抖20ms,有效判定,1退出低功耗模式,0延时500ms后,重新进入低功耗模式; { WatchdogFlagsClean(); ledCtrlPinConf (); greenLedBlink_ms(1,100); //hwg:240116/ 绿灯闪烁1下; batteryInfoInit(); //hwg:240117/ 对电池参数进行初始化。 SysMod = SYS_INIT_MOD; //hwg:240117/ 模式切换。 break; } else { delay_ms ( 50 ); } #endif } initModePinConf(); MainUnitPowerOn( TRUE ); startUpBeepLedPrompt(); RunModBasicInit(); systickTimerEnable(); while ( SysMod != SYS_SLEEP_MOD ) { // 后续改进... UpstreamSensorCoeffCheck(); SerialProtocolRcvCheck(); DetectionManage(); WatchdogFlagsClean(); if ( SysMod == SYS_SLEEP_MOD ) { //hwg:240115这里需不需要关闭一些中断; systickTimerDisable(); //hwg:240116/ 在这里停掉定时器。 stopAnalogPeripheral(); //hwg:240116/ 进入停止模式前要关闭模拟外设,ADC/DAC; while( POWERBTN_PRESSED ) { WatchdogFlagsClean(); } } #if DEBUG_PARA_MONITOR DebugStartCount ( &debugParaMonitor.mainRun ); #endif } } } 指出上述代码中可能导致设备在工作过程中,发生报警,电机等已停止工作。但是跑马灯和显示界面显示还在运行中,跟控制板状不同步的地方
最新发布
06-24
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值