原来的数据库服务器运行在HP DL388G7服务器上面,内存32G,由于业务增长,内存吃紧,加上时不时出现服务器硬件故障,由于是单实例单服务器,存在单点发现,于是打算采取一些措施改善一下:
1)升级服务器内存
2)并搭建服务器操作系统级别的双机
3)迁移数据库数据到新服务器
前面已经写过升级服务器内存相关的文章,题目为“数据库服务器升级内存需要考虑的问题”,链接如下:http://blog.csdn.net/laven54/article/details/8738698
前面已经写过数据迁移相关的文章,题目为“SUSE Linux HA双机搭建”,链接如下: http://blog.csdn.net/laven54/article/details/8878048
——————————————————————————————————————————————————————————
EXP/IMP对于小数据量的数据库,是一个不错的迁移工具。 迁移数据过程如下,分两大步,导出和导入。
more / exp20130118/exp.sh
date
expdp user/passwd DIRECTORY=DATA_PUMP_DIR2 DUMPFILE=exp_2013-1-19.dmp LOGFILE=exp_2013-1-19.log SCHEMAS=bv
date
exp目标目录放在本地还是存储,放哪个目录?是否创建directory?
SQL> select * from dba_directories;
OWNER DIRECTORY_NAME DIRECTORY_PATH
SYS DATA_PUMP_DIR /oracle/product/10.2/db/rdbms/log/
SYS DATA_PUMP_DIR1 /exp
SYS ORACLE_OCM_CONFIG_DIR /oracle/product/10.2/db/ccr/state
create directory data_pump_dir2 as ' /exp20130118';
目录创建以后,就可以把读写权限授予特定用户,具体语法如下:
GRANT READ[,WRITE] ON DIRECTORY directory TO username;
例如:
grant read, write on directory data_pump_dir2 to sys;
找一个业务不繁忙的时间,执行导出脚本即可。
说明:
1)我google网上大多数文章都说,如果用exp/imp方式迁移数据,在新服务器上,只需要创建一个用户用于导入就可以,但是我第一次导入时只创建一个用户,就会报一大堆错,最后还是创建所有用户,知道的同学告诉我一声,谢谢。
2)我这里偷点懒,直接用toad拷贝创建用户的语句,连加密的密码也有了,方便。
到Toad里边拷贝创建表空间和用户的脚本,直接粘贴进行初始化准备工作。表空间主要是看看和用户相关的都有哪些表空间,可以用sql语句查询;用户就得一个一个看。
1、1创建一个参数文件
CREATE PROFILE LIMIT_SESSION LIMIT
SESSIONS_PER_USER 30
CPU_PER_SESSION DEFAULT
CPU_PER_CALL DEFAULT
CONNECT_TIME DEFAULT
IDLE_TIME DEFAULT
LOGICAL_READS_PER_SESSION DEFAULT
LOGICAL_READS_PER_CALL DEFAULT
COMPOSITE_LIMIT DEFAULT
PRIVATE_SGA DEFAULT
FAILED_LOGIN_ATTEMPTS DEFAULT
PASSWORD_LIFE_TIME DEFAULT
PASSWORD_REUSE_TIME DEFAULT
PASSWORD_REUSE_MAX DEFAULT
PASSWORD_LOCK_TIME DEFAULT
PASSWORD_GRACE_TIME DEFAULT
PASSWORD_VERIFY_FUNCTION DEFAULT;
————————————————————————————————————————————————
1、2创建表空间
拷贝过来的代码示例:
CREATE TABLESPACE INDX DATAFILE
'/oracle/oradata/ebai/indx01.dbf' SIZE 10000M AUTOEXTEND OFF,
'/oracle/oradata/ebai/indx02.dbf' SIZE 10000M AUTOEXTEND OFF,
'/oracle/oradata/ebai/indx03.dbf' SIZE 10000M AUTOEXTEND OFF,
'/oracle/oradata/ebai/indx04.dbf' SIZE 10000M AUTOEXTEND OFF,
'/oracle/oradata/ebai/indx05.dbf' SIZE 10000M AUTOEXTEND OFF,
'/oracle/oradata/ebai/indx06.dbf' SIZE 10000M AUTOEXTEND OFF,
'/oracle/oradata/ebai/indx07.dbf' SIZE 5000M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED
LOGGING
ONLINE
PERMANENT
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;
其他表空间创建语句在此省略。
1、3创建用户
拷贝过来的代码示例:
CREATE USER XXXXX
IDENTIFIED BY VALUES '602CXD123XXXC410'
DEFAULT TABLESPACE SYSTEM
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
-- 1 Role for XXXXXX
GRANT CONNECT TO XXXXX WITH ADMIN OPTION;
ALTER USER XXXX DEFAULT ROLE ALL;
-- 1 Object Privilege for XXXXX
GRANT SELECT ON XX.XXXX_VIEW TO XXXXXX;
... ...此处省略数万字
create directory impdp_datapump_dir as '/exp20130118' ;
grant read,write on directory impdp_datapump_dir to system;
vi impdp.sh
date
impdp system/XXXX DIRECTORY=impdp_datapump_dir DUMPFILE=exp_2013-1-19.dmp ignore=y commit=y LOGFILE=imp_2013-1-31.log
date
导入过程根据数据量不同会有差异,耐心等待。
testdb: /exp20130118> more imp_2013-02-04.log |grep err
ORA-39083: Object type ALTER_PROCEDURE failed to create with error:
ORA-04052: error occurred when looking up remote object xxxxxxx
ORA-00604: error occurred at recursive SQL level 3
ORA-39083: Object type ALTER_PROCEDURE failed to create with error:
ORA-04052: error occurred when looking up remote object xxxxxx
ORA-00604: error occurred at recursive SQL level 3
ORA-39083: Object type ALTER_PROCEDURE failed to create with error:
ORA-04052: error occurred when looking up remote object xxxxxx
ORA-00604: error occurred at recursive SQL level 3
ORA-39083: Object type JOB failed to create with error:
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 35 error(s) at 16:11:53
之前很多用户赋权的时候都会报错,大部分都是XXX对象不存在,所以考虑数据库导入成功之后再次进行赋权。
另外值得注意的是,生产数据库上也有二十几个无效对象。
select object_type,count(*) from dba_objects where owner=’源schema’;
select object_type,count(*) from dba_objects where owner=’目标schema’;
select * from dba_objects where status<>’VALID’ and owner=’目标schema’;
select count(*) from zzzzzz.yz_ongimt_jingtzt;
select owner,object_name,replace(object_type,' ','') object_type,to_char(created,'yyyy-mm-dd') as created,to_char(last_ddl_time,'yyyy-mm-dd') as last_ddl_time,status from dba_objects where status='INVALID' and owner='xxx'
手工编译方法一:
@$ORACLE_HOME/rdbms/admin/utlrp.sql
手工编译方法二:
alter view ALL_IND_STATISTICS compile;
alter view sys.USER_IND_STATISTICS compile;
alter procedure sys.VALIDATE_ORDIM compile;
alter package DBMS_CUBE_ADVISE compile body;
________________________________________________________________________
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!
Author: laven54 (lurou)
Email: [email protected]
Blog: http://blog.csdn.net/laven54