记一次使用Oracle数据库业务系统的迁移过程(IMP/EXP)

概要

公司有一套业务系统需要在实体服务器上迁移至虚拟化上面,本次是对迁移过程进行记录。

环境

原环境:2008 R2 + ORACLE 11GR2 + TOMCAT6 + JDK8

新环境:CENTOS7 + ORACLE 11GR2 + TOMCAT6 + JDK8

老业务系统数据库备份

1. 查看数据库版本(新环境数据库需要与老环境数据库版本一致)

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0      Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

2. 查看字符集(非常重要,需要将新的ORACLE服务器环境与老环境字符集保持一致,否则会出现乱码等错误)

SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK

3. 查看用户表空间(将在新环境里面创建相同的表空间)

select default_tablespace from dba_users where username='USER';

4. 查看表空间下有哪些用户(将在新环境里面创建相同的用户名)

select distinct s.owner from dba_segments s where s.tablespace_name ='USER_DATA';

5. 备份原数据库(此处使用exp工具进行导出)

exp USER/PASSWORD@orcl  file=d:\backup.dmp log=d:\backup.log

新系统环境配置

1. 安装JDK

rpm -ivh jdk-8u241-linux-x64.rpm

2. 安装ORACLE(注意安装时的字符集设置)

详见:oracle 11gR2 for Linux 静默安装

3. 安装TOMCAT

略。

4. 创建临时表空间

create temporary tablespace USER_TEMP tempfile '/Project/DB/USER_TEMP.DBF' size 200m autoextend on next 100m maxsize 20480m extent management local;

5. 创建表空间

create  tablespace USER DATAFILE '/Project/DB/USER.DBF' size 200m autoextend on next 100m maxsize 20480m extent management local;

6. 创建用户并指定表空间

 create user USER identified by PASSWORD default tablespace USER temporary tablespace USER_TEMP;

7. 用户授权

grant connect,resource,dba to USER;

8. 数据库还原

imp USER/PASSWORD file='/Project/BACKUP.dmp' full=y ignore=y

9. 迁移项目

复制项目文件至TOMCAT项目目录

扩展

1. 字符集忘记设置,安装完毕后修改字符集

connect system/ORCL as sysdba
shutdown immediate
startup mount
alter system enable restricted session ;
alter system set JOB_QUEUE_PROCESSES=0;
alter system set AQ_TM_PROCESSES=0;
alter database open ;
alter database character set internal_use ZHS16GBK ;
shutdown immediate
startup

2. 删除用户表空间

drop tablespace USER including contents and datafiles;

3. 空表不导出问题

11G中新特性,当表无数据时,不分配segment,以节省空间。而使用exp命令时,无Segment的表不会被导出。

使用以下命令,组成为空表分配segment的SQL语句,并执行。

select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0

查询到的结果如下:

alter table QRTZ_CRON_TRIGGERS allocate extent;
alter table QRTZ_JOB_LISTENERS allocate extent;
alter table QRTZ_PAUSED_TRIGGER_GRPS allocate extent;
alter table QRTZ_TRIGGER_LISTENERS allocate extent;
alter table UNIT_COMMON_DEPARTMENT allocate extent;
alter table UNIT_COMMON_USER allocate extent;
alter table UNIT_DEPARTMENT_USER allocate extent;
alter table MT_NOTICE allocate extent;
alter table MT_TENANT_GZ_USER allocate extent;
alter table MSG_SHORT_MESSAGE allocate extent;
alter table MSG_MAS_CONFIG allocate extent;
alter table CD_READ_MARKER allocate extent;
alter table EXCHANGE_LOG allocate extent;
alter table QRTZ_BLOB_TRIGGERS allocate extent;
alter table QRTZ_CALENDARS allocate extent;
alter table MT_NOTICE_CONTENT_INFO allocate extent;
alter table WF_GZ_DATA_SYNC allocate extent;
alter table WF_GZ_DATA_SYNC_HIS allocate extent;

然后将执行结果复制到另一个SQL窗口,并执行,分配segment.然后可以执行imp

借鉴资料

https://www.cnblogs.com/silentjesse/p/5484341.html

THE END