使用set newname切换文件到其他的位置

本文描述:使用set newname切换文件到其他的位置
试验步骤:
(1)查看当前文件位置
C:\Users\Administrator>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期五 6月 16 16:09:00 2017

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> col name for a50;
SQL> select file#, name from v$datafile;

     FILE# NAME
---------- --------------------------------------------------
         1 F:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSTEM01.DBF
         2 F:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBF
         3 F:\APP\ADMINISTRATOR\ORADATA\ORCL\UNDOTBS01.DBF
         4 F:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF
         5 F:\ORADATA\TT01.DBF

SQL>
(2)rman 使用set newname进行位置移动
RMAN>  run{
2> sql 'alter tablespace tt offline immediate';
3> set newname for datafile 'f:\oradata\tt01.dbf' to 'g:\rmanbp\tt01.dbf';
4> restore tablespace tt;
5> switch datafile all;
6> recover tablespace tt;
7> sql 'alter tablespace tt online';
8> }

sql statement: alter tablespace tt offline immediate

executing command: SET NEWNAME

Starting restore at 16-6月 -17
using channel ORA_DISK_1

channel ORA_DISK_1: restoring datafile 00005
input datafile copy RECID=3 STAMP=946829237 file name=F:\APP\ADMINISTRATOR\FLASH_RECOVERY_AREA\ORCL\DATAFILE\O1_MF_TT_DN70OL9K_.DBF
destination for restore of datafile 00005: g:\rmanbp\tt01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00005
output file name=G:\RMANBP\TT01.DBF RECID=4 STAMP=946832210
Finished restore at 16-6月 -17

datafile 5 switched to datafile copy
input datafile copy RECID=5 STAMP=946832211 file name=G:\RMANBP\TT01.DBF

Starting recover at 16-6月 -17
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 16-6月 -17

sql statement: alter tablespace tt online

RMAN>
(3)查看移动结果
SQL> select file#, name from v$datafile;

     FILE# NAME
---------- --------------------------------------------------
         1 F:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSTEM01.DBF
         2 F:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBF
         3 F:\APP\ADMINISTRATOR\ORADATA\ORCL\UNDOTBS01.DBF
         4 F:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF
         5 G:\RMANBP\TT01.DBF

SQL>
(4)再次执行set newname 切换回原来的位置
RMAN>  run{
2> sql 'alter tablespace tt offline immediate';
3> set newname for datafile 'g:\rmanbp\tt01.dbf' to 'f:\oradata\tt01.dbf';
4> restore tablespace tt;
5> switch datafile all;
6> recover tablespace tt;
7> sql 'alter tablespace tt online';
8> }

sql statement: alter tablespace tt offline immediate

executing command: SET NEWNAME

Starting restore at 16-6月 -17
using channel ORA_DISK_1

datafile 5 is already restored to file f:\oradata\tt01.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 16-6月 -17

datafile 5 switched to datafile copy
input datafile copy RECID=7 STAMP=946832456 file name=f:\oradata\tt01.dbf

Starting recover at 16-6月 -17
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 16-6月 -17

sql statement: alter tablespace tt online

RMAN>
(5)查看移动结果
SQL> select file#, name from v$datafile;

     FILE# NAME
---------- --------------------------------------------------
         1 F:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSTEM01.DBF
         2 F:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBF
         3 F:\APP\ADMINISTRATOR\ORADATA\ORCL\UNDOTBS01.DBF
         4 F:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF
         5 F:\ORADATA\TT01.DBF

SQL>

实验完毕。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在SpringBoot中实现双数据源,需要使用到多个数据源的配置,以及动态切换数据源的代码。 在配置多个数据源时,需要在application.properties或application.yml文件中分别配置不同的数据源信息,包括数据源的驱动、url、用户名、密码等信息。例如: ``` spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver spring.datasource.primary.url=jdbc:mysql://localhost:3306/db1 spring.datasource.primary.username=root spring.datasource.primary.password=root spring.datasource.secondary.driver-class-name=oracle.jdbc.driver.OracleDriver spring.datasource.secondary.url=jdbc:oracle:thin:@localhost:1521:db2 spring.datasource.secondary.username=oracle spring.datasource.secondary.password=oracle ``` 在代码中,需要定义两个数据源的bean,并且使用@Primary注解标记其中一个数据源为主数据源。例如: ``` @Configuration public class DataSourceConfig { @Bean(name = "primaryDataSource") @Primary @ConfigurationProperties(prefix = "spring.datasource.primary") public DataSource primaryDataSource() { return DataSourceBuilder.create().build(); } @Bean(name = "secondaryDataSource") @ConfigurationProperties(prefix = "spring.datasource.secondary") public DataSource secondaryDataSource() { return DataSourceBuilder.create().build(); } } ``` 在使用数据源的时候,需要使用@Qualifier注解指定要使用的数据源。例如: ``` @Service public class UserService { @Autowired @Qualifier("primaryDataSource") private DataSource primaryDataSource; @Autowired @Qualifier("secondaryDataSource") private DataSource secondaryDataSource; public void addUser(User user) { // 使用主数据源插入用户信息 // ... } public User getUser(Long id) { // 使用从数据源查询用户信息 // ... } } ``` 在动态切换数据源时,可以使用ThreadLocal来保存当前线程使用的数据源。例如: ``` public class DynamicDataSourceContextHolder { private static final ThreadLocal<String> contextHolder = new ThreadLocal<>(); public static void setDataSource(String dataSource) { contextHolder.set(dataSource); } public static String getDataSource() { return contextHolder.get(); } public static void clearDataSource() { contextHolder.remove(); } } ``` 在使用数据源之前,需要先调用DynamicDataSourceContextHolder.setDataSource(dataSource)方法来设置当前线程使用的数据源。例如: ``` @Service public class UserService { @Autowired @Qualifier("primaryDataSource") private DataSource primaryDataSource; @Autowired @Qualifier("secondaryDataSource") private DataSource secondaryDataSource; public void addUser(User user) { DynamicDataSourceContextHolder.setDataSource("primaryDataSource"); // 使用主数据源插入用户信息 // ... } public User getUser(Long id) { DynamicDataSourceContextHolder.setDataSource("secondaryDataSource"); // 使用从数据源查询用户信息 // ... } } ``` 注意:在使用完数据源之后,需要调用DynamicDataSourceContextHolder.clearDataSource()方法清除当前线程使用的数据源,以免影响下一次使用数据源。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sky@sea

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值