背景:做为一名DBA,oracle数据库迁移是经常要遇到的事情,正好最近我也在迁移一个业务系统,数据库就是oracle,顺便记录一下。
说明:为了方便说明,旧的数据库称为A,新的为B。用户和密码是IRP/IRP , B是全新的环境。
步骤思路:
1.从 A 上导出数据文件。
123sqlplus
/
nolog
conn
/
as sysdba
EXP IRP
/
IRP
BUFFER
=
64000
FILE
=
D:\test.DMP log
=
D:\test.log OWNER
=
IRP
2.在A机器上查看用户默认表空间,以便导入时创建一样的表空间
12345SQL> select username,default_tablespace
from
dba_users where username
=
'IRP'
;
USERNAME DEFAULT_TABLESPACE
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
IRP IRP
3.查看用户使用的表空间
12345SQL> select DISTINCT owner ,tablespace_name
from
dba_extents where owner like
'IRP'
;
OWNER TABLESPACE_NAME
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
IRP IRP
4.查看表空间对应的数据文件,以便在B上创建大小合适的数据文件。
1234567SQL> select file_name,tablespace_name
from
dba_data_files where tablespace_name
in
'IRP'
;
FILE_NAME TABLESPACE_NAME
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
D:\APP\ADMINISTRATOR\ORADATA\ORCL\IRP.DBF IRP
如果用户使用多个表空间,查询语句如下
select file_name,tablespace_name
from
dba_data_files where tablespace_name
in
(
'IRP1'
,
'IRP2'
);
5.检查B机器的表空间,看是否存在IRP(如果是新的服务器,不需要这一步)
12select name
from
v$tablespace where name
in
'IRP'
查找不到,说明没有这个两个表空间,需要创建。
6.在B上创建表空间、用户并授权
12345678910111213创建大文件表空间
CREATE BIGFILE TABLESPACE
"IRP"
DATAFILE
'D:\app\oracle\oradata\orcl\irp.dbf'
SIZE
100M
AUTOEXTEND ON
NEXT
100M
MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
创建默认表空间
或者 CREATE TABLESPACE
"IRP"
DATAFILE
'D:\app\oracle\oradata\orcl\irp.dbf'
SIZE
100M
AUTOEXTEND ON
NEXT
100M
MAXSIZE
10000M
LOGGING EXTENT MANAGEMENT LOCAL;
创建用户
CREATE USER
"IRP"
PROFILE
"DEFAULT"
IDENTIFIED BY
"IRP"
DEFAULT TABLESPACE
"IRP"
TEMPORARY TABLESPACE
"TEMP"
ACCOUNT UNLOCK;
授权
GRANT
"CONNECT"
TO
"IRP"
;
GRANT
"RESOURCE"
TO
"IRP"
;
GRANT unlimited tablespace TO
"IRP"
;
注: BigFile表空间只能创建一个datafile数据文件,SmallFile表空间最多可以创建1024个数据文件
7.如果在服务器B上已经存在该用户,怎么样删除该用户.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
查看是否存在该用户SQL> select username
from
dba_users where username
=
'IRP'
;
删除用户及其拥有的所有对象
drop user IRP cascade;
查看这个用户下面是否有对象;
select object_type,count(
*
)
from
all_objects where owner
=
'IRP'
group by object_type
OBJECT_TYPE COUNT(
*
)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
1
SEQUENCE
3
2
PROCEDURE
5
3
LOB
139
4
PACKAGE
3
5
PACKAGE BODY
2
6
TRIGGER
1
7
TABLE
384
8
INDEX
426
9
FUNCTION
6
|
此时如果这个用户在连接,drop会出错,必须先杀掉用户的session,然后再drop user
1234567891011121314151617构建杀掉IRP用户session的语句并执行,
SELECT
'alter system kill session '
'
'||SID||'
,
'||SERIAL#||'
'
' immediate;'
FROM V$SESSION WHERE USERNAME
=
'IRP'
;
上面的语句是构建出杀掉IRP用户session的语句,再复制这些语句,粘贴到sqlplus中执行,来杀掉IRP的session。
'ALTERSYSTEMKILLSESSION'
'
'||SID||'
,
'||SERIAL#||'
'
'IMMEDIATE;'
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
alter system kill session
'9,42043'
immediate;
alter system kill session
'10,9137'
immediate;
alter system kill session
'72,17487'
immediate;
alter system kill session
'84,3280'
immediate;
alter system kill session
'91,976'
immediate;
alter system kill session
'100,13516'
immediate;
alter system kill session
'111,5973'
immediate;
alter system kill session
'115,4751'
immediate;
alter system kill session
'120,10356'
immediate;
alter system kill session
'211,4075'
immediate;
alter system kill session
'216,48068'
immediate;
8.最后在B上导入数据
一定注意执行imp时要退出sqlplus,直接在命令行执行。
1
|
IMP test
/
test
BUFFER
=
64000
FILE
=
D:\test.DMP log
=
D:\imptest.log FROMUSER
=
IRP TOUSER
=
IRP
|
本文转自pizibaidu 51CTO博客,原文链接:http://blog.51cto.com/pizibaidu/1854468,如需转载请自行联系原作者