SQL> 提示:open 的时候不需要附加read only 子句,oracle 会根据控制文件判断是否是物理standby,从而自动启动到read only 模式,直接startup 也是同理。
1.2,如果想从open 状态再切换回redo 应用状态,并不需要shutdown,直接启用redo 应用即可,例如: SQL> select status from v$instance;
STATUS ------------ OPEN
SQL> alter database recover managed standby database disconnect from session; SQL> alter database recover managed standby database disconnect from session;
4,STANDBY_FILE_MANAGEMENT设置为MANUAL,增加及删除表空间和数据文件 因为一直是auto模式,这里为了做实验,需要将其设置为manual,设置命令是:alter system set standby_file_management=‘MANUAL‘ scope=both; 在primary和standby上都做如下操作 SQL> alter system set standby_file_management=‘MANUAL‘ scope=both;
System altered.
SQL>
4.1,增加新的表空间 create tablespace mytmp datafile ‘/home/oradata/powerdes/mytmp01.dbf‘ size 20m autoextend on next 10m; SQL> create tablespace mytmp datafile ‘/home/oradata/powerdes/mytmp01.dbf‘ size 20m autoextend on next 10m;
Tablespace created.
SQL> SQL>
检查刚创建的表空间 select name from v$datafile where name like ‘%mytmp%‘; SQL> select name from v$datafile where name like ‘%mytmp%‘;
NAME -------------------------------------------------------------------------------- /home/oradata/powerdes/mytmp01.dbf
SQL>
切换日志:alter system switch logfile; SQL> alter system switch logfile;
System altered.
SQL>
检查standby库表空间,已经存在了: select name from v$tablespace where name like ‘%MYTMP%‘; SQL> select name from v$tablespace where name like ‘%MYTMP%‘;
NAME ------------------------------ MYTMP
SQL>
检查standby库数据文件,不存在: SQL> select name from v$datafile where name like ‘%mytmp%‘;
再去检查standby是否redo应用启动了,也是启用了,如下所示: SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE -------------------- ---------------- READ ONLY PHYSICAL STANDBY
SQL>
都正常啊,那就再去检查下最新创建的那个数据文件 primary库上:select * from(select to_char(CREATION_TIME,‘yyyy-mm-dd hh24:mi:ss‘),name from v$datafile order by CREATION_TIME desc)a where rownum<3; SQL> select * from(select to_char(CREATION_TIME,‘yyyy-mm-dd hh24:mi:ss‘),name from v$datafile order by CREATION_TIME desc)a where rownum<3;
TO_CHAR(CREATION_TI ------------------- NAME -------------------------------------------------------------------------------- 2015-02-12 16:00:26 /home/oradata/powerdes/mytmp01.dbf
发现在同一时刻2015-02-12 16:00:26primary和standby都创建了一个数据文件,primary就是我们创建知道的mytmp表空间所属的数据文件,那么standby库呢?有一个UNNAMED00011未知的数据文件,这段时间没有人操作standby库,这意味着这个UNNAMED00011就是从primary及时同步过来的表空间,只是因为不是auto所以给起了个临时的名字而已。手工修改其与primary数据库保持一致,如下(注意执行命令之后手工复制数据文件到standby): 在standby库上执行:alter database create datafile ‘/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00011‘ as ‘/home/oradata/powerdes/mytmp01.dbf‘; SQL> alter database create datafile ‘/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00011‘ as ‘/home/oradata/powerdes/mytmp01.dbf‘;
Database altered.
SQL>
再去检查standby库上检查,mytmp数据文件已经存在了,如下所示: SQL> select name from v$datafile where name like ‘%mytmp%‘;
NAME -------------------------------------------------------------------------------- /home/oradata/powerdes/mytmp01.dbf
SQL>
4.3,删除表空间测试 在primary上操作:drop tablespace mytmp including contents and datafiles; SQL> drop tablespace mytmp including contents and datafiles;
Tablespace dropped.
SQL>
检查mytmp没有记录,已经删除了 SQL> select name from v$datafile where name like ‘%mytmp%‘;
no rows selected
SQL>
再去standby库上检查 SQL> select name from v$datafile where name like ‘%mytmp%‘;
NAME -------------------------------------------------------------------------------- /home/oradata/powerdes/mytmp01.dbf
SQL>
看到standby库上mytmp还在,所以需要我们人工手动处理 alter database recover managed standby database disconnect from session; SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL>
再去检查,执行,就看不到mytmp的记录了。 SQL> select name from v$datafile where name like ‘%mytmp%‘;
通过命令修改数据字典中的数据文件路径,并online 表空间 alter tablespace plcrm rename datafile ‘/home/oradata/powerdes/plcrm01.dbf‘ to ‘/home/oradata/powerdes/plcrm01_rename.dbf‘; SQL> alter tablespace plcrm rename datafile ‘/home/oradata/powerdes/plcrm01.dbf‘ to ‘/home/oradata/powerdes/plcrm01_rename.dbf‘;
Tablespace altered.
SQL> alter tablespace plcrm online;
Tablespace altered.
SQL>
检查新的数据文件名:select name from v$datafile where name like ‘%rename%‘; SQL> select name from v$datafile where name like ‘%rename%‘;
NAME -------------------------------------------------------------------------------- /home/oradata/powerdes/plcrm01_rename.dbf
然后重启oracle实例: SQL> startup mount ORACLE instance started.
Total System Global Area 3373858816 bytes Fixed Size 2218032 bytes Variable Size 1845495760 bytes Database Buffers 1509949440 bytes Redo Buffers 16195584 bytes Database mounted. SQL>
数据文件重新命名: SQL> alter database rename file ‘/home/oradata/powerdes/plcrm01.dbf‘ to ‘/home/oradata/powerdes/plcrm01_rename.dbf‘;
Database altered.
SQL>
重新启动redo应用: alter database recover managed standby database disconnect from session; SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL>
再去primary切换日志: SQL> alter system switch logfile;
System altered.
SQL>
最后去standby上验证 检查新的数据文件名:select name from v$datafile where name like ‘%rename%‘; SQL> select name from v$datafile where name like ‘%rename%‘;
NAME -------------------------------------------------------------------------------- /home/oradata/powerdes/plcrm01_rename.dbf