從本地文件系統遷移oracle數據庫到ASM

從本地文件系統遷移oracle數據庫到ASM



新建grid用戶及軟件安裝目錄並給予權限

[root@ora11g ~]# groupadd -g 5000 asmadmin

[root@ora11g ~]# groupadd -g 5001 asmdba

[root@ora11g ~]# groupadd -g 5002 asmoper

[root@ora11g ~]# useradd -g oinstall -G asmadmin,asmdba,asmoper,dba grid  

[root@ora11g ~]# usermod -a -G asmadmin oracle

[root@ora11g ~]# usermod -a -G asmdba oracle

[root@ora11g ~]# mkdir /g01

[root@ora11g ~]# chown grid:oinstall   /g01

[root@ora11g ~]# echo "oracle" | passwd --stdin grid

更改用戶grid的密碼 。

passwd: 所有的身份驗證令牌已經成功更新。



修改grid環境變量

[root@ora11g ~]# su - grid

[grid@ora11g ~]$ vi .bash_profile

[grid@ora11g ~]$ logout

[root@ora11g ~]# cat /home/grid/.bash_profile

# .bash_profile



# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi



# User specific environment and startup programs



PATH=$PATH:$HOME/bin



export PATH



export ORACLE_SID=+ASM

export ORACLE_BASE=/g01/app/grid

export ORACLE_HOME=/g01/app/11.2.0/grid

export LD_LIBRARY_PATH=$ORACLE_HOME/lib

export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"

export PATH=$ORACLE_HOME/bin:$PATH



vi /etc/security/limits.conf #添加進下面內容



# grid-rdbms-server-11gR2-preinstall setting for nofile soft limit is 1024

grid soft   nofile    1024

# grid-rdbms-server-11gR2-preinstall setting for nofile hard limit is 65536

grid hard   nofile    65536

# grid-rdbms-server-11gR2-preinstall setting for nproc soft limit is 2047

grid soft   nproc    2047

# grid-rdbms-server-11gR2-preinstall setting for nproc hard limit is 16384

grid hard   nproc    16384

# grid-rdbms-server-11gR2-preinstall setting for stack soft limit is 10240KB

grid soft   stack    10240

# grid-rdbms-server-11gR2-preinstall setting for stack hard limit is 32768KB

grid hard   stack    32768



grid安裝介質複製到主機並解壓

zhou@T530:~/career/linux$ scp p13390677_112040_Linux-x86-64_3of7.zip [email protected]:/home/grid

[email protected]'s password:

p13390677_112040_Linux-x86-64_3of7.zip      100% 1149MB  88.4MB/s   00:13    



[root@ora11g ~]# su - grid

[grid@ora11g ~]$ ls

p13390677_112040_Linux-x86-64_3of7.zip

[grid@ora11g ~]$ unzip p13390677_112040_Linux-x86-64_3of7.zip

[grid@ora11g ~]$ ls

grid p13390677_112040_Linux-x86-64_3of7.zip

[grid@ora11g ~]$ rm -f p13390677_112040_Linux-x86-64_3of7.zip

[grid@ora11g ~]$ ls

grid

[grid@ora11g ~]$ logout



查看當前磁盤狀況

[root@ora11g ~]# fdisk -l



Disk /dev/sda: 68.7 GB, 68719476736 bytes

255 heads, 63 sectors/track, 8354 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00085d4f



Device Boot      Start         End      Blocks   Id  System

/dev/sda1 *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2            26         548     4194304   82  Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3           548        8355    62708736   83  Linux



Disk /dev/sdb: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdc: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdd: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sde: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdf: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdg: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdh: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdi: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdj: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdk: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdl: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000





Disk /dev/sdm: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000



做磁盤綁定並重啓udev,使綁定生效

[root@ora11g ~]# for i in b c d e f g h i j k l m;

> do

> echo "KERNEL==\"sd*\", SUBSYSTEM==\"block\", PROGRAM==\"/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/\$name\", RESULT==\"`/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sd$i`\", NAME=\"asm-disk$i\", OWNER=\"grid\", GROUP=\"asmadmin\", MODE=\"0660\""      >> /etc/udev/rules.d/99-oracle-asmdevices.rules

> done

[root@ora11g ~]# start_udev

正在啓動udev:                                          [確定]

[root@ora11g ~]# ls -l /dev/asm*

brw-rw---- 1 grid asmadmin 8,  16 1月  1 19:24 /dev/asm-diskb

brw-rw---- 1 grid asmadmin 8,  32 1月  1 19:24 /dev/asm-diskc

brw-rw---- 1 grid asmadmin 8,  48 1月  1 19:24 /dev/asm-diskd

brw-rw---- 1 grid asmadmin 8,  64 1月  1 19:24 /dev/asm-diske

brw-rw---- 1 grid asmadmin 8,  80 1月  1 19:24 /dev/asm-diskf

brw-rw---- 1 grid asmadmin 8,  96 1月  1 19:24 /dev/asm-diskg

brw-rw---- 1 grid asmadmin 8, 112 1月  1 19:24 /dev/asm-diskh

brw-rw---- 1 grid asmadmin 8, 128 1月  1 19:24 /dev/asm-diski

brw-rw---- 1 grid asmadmin 8, 144 1月  1 19:24 /dev/asm-diskj

brw-rw---- 1 grid asmadmin 8, 160 1月  1 19:24 /dev/asm-diskk

brw-rw---- 1 grid asmadmin 8, 176 1月  1 19:24 /dev/asm-diskl

brw-rw---- 1 grid asmadmin 8, 192 1月  1 19:24 /dev/asm-diskm



在主機內執行grid安裝

[root@ora11g ~]# cd /home/grid/grid/rpm/

[root@ora11g rpm]# ls

cvuqdisk-1.0.9-1.rpm

[root@ora11g rpm]# rpm -ivh cvuqdisk-1.0.9-1.rpm

Preparing...              ########################################### [100%]

1:cvuqdisk             ########################################### [100%]

[root@ora11g rpm]# logout

[grid@ora11g grid]$ ls

install    response  runcluvfy.sh  sshsetup  welcome.html

readme.html rpm       runInstaller  stage

[grid@ora11g grid]$ ./runInstaller

Starting Oracle Universal Installer...



Checking Temp space: must be greater than 120 MB.   Actual 46471 MB    Passed

Checking swap space: must be greater than 150 MB.   Actual 4095 MB    Passed

Checking monitor: must be configured to display at least 256 colors.    Actual 16777216    Passed

Preparing to launch Oracle Universal Installer from /tmp/OraInstall2016-01-01_07-31-01PM. Please wait ...[grid@ora11g grid]$ You can find the log of this install session at:

/u01/app/oraInventory/logs/installActions2016-01-01_07-31-01PM.log



執行root.sh腳本

[root@ora11g ~]# sh /g01/app/11.2.0/grid/root.sh

Performing root user operation for Oracle 11g



The following environment variables are set as:

ORACLE_OWNER= grid

ORACLE_HOME= /g01/app/11.2.0/grid



Enter the full pathname of the local bin directory: [/usr/local/bin]:

The contents of "dbhome" have not changed. No need to overwrite.

The contents of "oraenv" have not changed. No need to overwrite.

The contents of "coraenv" have not changed. No need to overwrite.



Entries will be added to the /etc/oratab file as needed by

Database Configuration Assistant when a database is created

Finished running generic part of root script.

Now product-specific root actions will be performed.

Using configuration parameter file: /g01/app/11.2.0/grid/crs/install/crsconfig_params

Creating trace directory

LOCAL ADD MODE

Creating OCR keys for user 'grid', privgrp 'oinstall'..

Operation successful.

LOCAL ONLY MODE

Successfully accumulated necessary OCR keys.

Creating OCR keys for user 'root', privgrp 'root'..

Operation successful.

CRS-4664: Node ora11g successfully pinned.

Adding Clusterware entries to upstart



ora11g   2016/01/01 19:37:03     /g01/app/11.2.0/grid/cdata/ora11g/backup_20160101_193703.olr

Successfully configured Oracle Grid Infrastructure for a Standalone Server





將數據庫註冊到grid裏進行管理

SQL> show parameter name

db_unique_name   string ORCL

SQL> !

[oracle@ora11g dbs]$ srvctl add database -d ORCL -o /u01/app/oracle/product/11.2.0/dbhome_1/



[oracle@ora11g dbs]$ exit



遷移控制文件

SQL> show parameter control

control_files   string /u01/app/oracle/oradata/ORCL/c

ontrol01.ctl, /u01/app/oracle/

fast_recovery_area/ORCL/contro

l02.ctl



SQL> alter system set control_files='+DATA','+FRA' SCOPE=spfile;



System altered.



SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup nomount

ORACLE instance started.



Total System Global Area  835104768 bytes

Fixed Size    2257840 bytes

Variable Size  536874064 bytes

Database Buffers  289406976 bytes

Redo Buffers    6565888 bytes

SQL> show parameter control

control_files   string +DATA, +FRA



[oracle@ora11g ~]$ rman target /



Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jan 1 21:07:11 2016



Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.



connected to target database: ORCL (not mounted)



RMAN> restore controlfile from '/u01/app/oracle/oradata/ORCL/control01.ctl';



Starting restore at 2016-01-01 21:08:46

using channel ORA_DISK_1



channel ORA_DISK_1: copied control file copy

output file name=+DATA/orcl/controlfile/current.256.900018527

output file name=+FRA/orcl/controlfile/current.256.900018527

Finished restore at 2016-01-01 21:08:47



遷移數據文件

RMAN> alter database mount;



database mounted

released channel: ORA_DISK_1



RMAN> backup as copy database format '+DATA';



Starting backup at 2016-01-01 21:11:01

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=135 device type=DISK

channel ORA_DISK_1: starting datafile copy

input datafile file number=00001 name=/u01/app/oracle/oradata/ORCL/system01.dbf

output file name=+DATA/orcl/datafile/system.257.900018661 tag=TAG20160101T211101 RECID=1 STAMP=900018667

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002 name=/u01/app/oracle/oradata/ORCL/sysaux01.dbf

output file name=+DATA/orcl/datafile/sysaux.258.900018669 tag=TAG20160101T211101 RECID=2 STAMP=900018672

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07

channel ORA_DISK_1: starting datafile copy

input datafile file number=00003 name=/u01/app/oracle/oradata/ORCL/undotbs01.dbf

output file name=+DATA/orcl/datafile/undotbs1.259.900018675 tag=TAG20160101T211101 RECID=3 STAMP=900018676

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting datafile copy

copying current control file

output file name=+DATA/orcl/controlfile/backup.260.900018677 tag=TAG20160101T211101 RECID=4 STAMP=900018676

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004 name=/u01/app/oracle/oradata/ORCL/users01.dbf

output file name=+DATA/orcl/datafile/users.261.900018677 tag=TAG20160101T211101 RECID=5 STAMP=900018677

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 2016-01-01 21:11:18

channel ORA_DISK_1: finished piece 1 at 2016-01-01 21:11:19

piece handle=+DATA/orcl/backupset/2016_01_01/nnsnf0_tag20160101t211101_0.262.900018679 tag=TAG20160101T211101 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 2016-01-01 21:11:19



RMAN> switch database to copy;



datafile 1 switched to datafile copy "+DATA/orcl/datafile/system.257.900018661"

datafile 2 switched to datafile copy "+DATA/orcl/datafile/sysaux.258.900018669"

datafile 3 switched to datafile copy "+DATA/orcl/datafile/undotbs1.259.900018675"

datafile 4 switched to datafile copy "+DATA/orcl/datafile/users.261.900018677"



RMAN> report schema;



Report of database schema for database with db_unique_name ORCL



List of Permanent Datafiles

===========================

File Size(MB) Tablespace           RB segs Datafile Name

---- -------- -------------------- ------- ------------------------

1  740      SYSTEM               ***     +DATA/orcl/datafile/system.257.900018661

2  490      SYSAUX               ***     +DATA/orcl/datafile/sysaux.258.900018669

3  70       UNDOTBS1             ***     +DATA/orcl/datafile/undotbs1.259.900018675

4  5        USERS                ***     +DATA/orcl/datafile/users.261.900018677



List of Temporary Files

=======================

File Size(MB) Tablespace           Maxsize(MB) Tempfile Name

---- -------- -------------------- ----------- --------------------

1  29       TEMP                 32767       /u01/app/oracle/oradata/ORCL/temp01.dbf



遷移臨時文件

RMAN> run {

2> set newname for tempfile 1 to '+DATA';

3> switch tempfile all;

4> }



executing command: SET NEWNAME



renamed tempfile 1 to +DATA in control file



RMAN> report schema;



Report of database schema for database with db_unique_name ORCL



List of Permanent Datafiles

===========================

File Size(MB) Tablespace           RB segs Datafile Name

---- -------- -------------------- ------- ------------------------

1  740      SYSTEM               ***     +DATA/orcl/datafile/system.257.900018661

2  490      SYSAUX               ***     +DATA/orcl/datafile/sysaux.258.900018669

3  70       UNDOTBS1             ***     +DATA/orcl/datafile/undotbs1.259.900018675

4  5        USERS                ***     +DATA/orcl/datafile/users.261.900018677



List of Temporary Files

=======================

File Size(MB) Tablespace           Maxsize(MB) Tempfile Name

---- -------- -------------------- ----------- --------------------

1  29       TEMP                 32767       +DATA





SQL> alter database open;



Database altered.



遷移日誌文件

遇到下面的錯誤,不需要驚慌,切一遍日誌就好,這是日誌組內成員狀態不一致造成的

SQL> alter database drop logfile member '/u01/app/oracle/oradata/ORCL/redo02.log';

alter database drop logfile member '/u01/app/oracle/oradata/ORCL/redo02.log'

*

ERROR at line 1:

ORA-00362: member is required to form a valid logfile in group 2

ORA-01517: log member: '/u01/app/oracle/oradata/ORCL/redo02.log'



SQL> alter system switch logfile;



System altered.



SQL> alter system switch logfile;



System altered.



SQL> alter system switch logfile;



System altered.



SQL> SELECT a.group#, b.member, a.status FROM v$log a, v$logfile b WHERE a.group#=b.group#;



GROUP# MEMBER      STATUS

---------- -------------------------------------------------- ----------------

3 /u01/app/oracle/oradata/ORCL/redo03.log      CURRENT

2 /u01/app/oracle/oradata/ORCL/redo02.log      ACTIVE

1 /u01/app/oracle/oradata/ORCL/redo01.log      ACTIVE

1 +DATA/orcl/onlinelog/group_1.264.900020821      ACTIVE

2 +DATA/orcl/onlinelog/group_2.265.900020833      ACTIVE

3 +DATA/orcl/onlinelog/group_3.266.900020839      CURRENT



6 rows selected.



SQL> alter database drop logfile member '/u01/app/oracle/oradata/ORCL/redo01.log';



Database altered.



SQL> alter database drop logfile member '/u01/app/oracle/oradata/ORCL/redo02.log';



Database altered.



SQL> alter system switch logfile;



System altered.



SQL> alter database drop logfile member '/u01/app/oracle/oradata/ORCL/redo03.log';



Database altered.



SQL> SELECT a.group#, b.member, a.status FROM v$log a, v$logfile b WHERE a.group#=b.group#;



GROUP# MEMBER      STATUS

---------- -------------------------------------------------- ----------------

1 +DATA/orcl/onlinelog/group_1.264.900020821      CURRENT

2 +DATA/orcl/onlinelog/group_2.265.900020833      ACTIVE

3 +DATA/orcl/onlinelog/group_3.266.900020839      ACTIVE





SQL> select name from v$controlfile

2 union all

3 select name from v$datafile

4 union all

5 select name from v$tempfile

6 union all

7 select member from v$logfile;



NAME

--------------------------------------------------------------------------------

+DATA/orcl/controlfile/current.256.900018527

+FRA/orcl/controlfile/current.256.900018527

+DATA/orcl/datafile/system.257.900018661

+DATA/orcl/datafile/sysaux.258.900018669

+DATA/orcl/datafile/undotbs1.259.900018675

+DATA/orcl/datafile/users.261.900018677

+DATA/orcl/tempfile/temp.263.900020265

+DATA/orcl/onlinelog/group_1.264.900020821

+DATA/orcl/onlinelog/group_2.265.900020833

+DATA/orcl/onlinelog/group_3.266.900020839



10 rows selected.



遷移參數文件

SQL> create pfile from spfile;



File created.



SQL> create spfile='+DATA' from pfile;



File created.



SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> !

[oracle@ora11g dbs]$ ls

hc_ORCL.dat init.ora  initORCL.ora  lkORCL  orapwORCL  spfileORCL.ora

[grid@ora11g ~]$ asmcmd

ASMCMD> ls

DATA/

FRA/

ASMCMD> cd data

ASMCMD> ls

ASM/

ORCL/

ASMCMD> cd orcl

ASMCMD> ls

BACKUPSET/

CONTROLFILE/

DATAFILE/

ONLINELOG/

PARAMETERFILE/

TEMPFILE/

ASMCMD> cd PARAMETERFILE/

ASMCMD> ls

spfile.267.900022587

ASMCMD> pwd

+data/orcl/PARAMETERFILE



[oracle@ora11g dbs]$ mv spfileORCL.ora ~

[oracle@ora11g dbs]$ vi initORCL.ora

[oracle@ora11g dbs]$ cat initORCL.ora

spfile='+DATA/ORCL/PARAMETERFILE/spfile.267.900022587'



SQL> startup

ORACLE instance started.



Total System Global Area  835104768 bytes

Fixed Size    2257840 bytes

Variable Size  536874064 bytes

Database Buffers  289406976 bytes

Redo Buffers    6565888 bytes

Database mounted.

Database opened.

SQL> show parameter pfile



NAME   TYPE VALUE

------------------------------------ ----------- ------------------------------

spfile   string +DATA/orcl/parameterfile/spfil

e.267.900022587





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章