分享
 
 
 

Original: How to duplicate database

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

Enclosed is my work note about how to do database copy. Feel free to make your comments

Copying a Database

2.1 Create ctl_test.sql script for creating new database control file

Assume I want to copy Oracle database data030d to wtest030.

Always set up oracle environment first by doing this:

root@unixserver02>su – oracle

oracle@unixserver02>. /bin/oraenv data030d

Create trace file from data030d first:

oracle@ unixserver02>sqlplus system@dada030d

SQL>alter database backup controlfile to trace;

SQL>exit

ShUClown database data030d before I copy any file from it.

oracle@ unixserver02>. /bin/oraenv data030d

oracle@ unixserver02>svrmgrl

SVRMGR>connect internal

SVRMGR>shuclown immediate

SVRMGR>exit

The trace file was created as:

/eXPort/home/oracle/admin/data030d/udump/data030d_ora_11143.trc

Delete the header up to “START NOMOUNT” and make some modification as follows:

· Change

“CREATE CONTROLFILE REUSE DATABASE “DATA030D” NORESETLOGS NOARCHIVELOG”

to

“CREATE CONTROLFILE SET DATABASE “wtest030” RESETLOGS NOARCHIVELOG”

· Comment out

“RECOVER DATABASE”

· Change

“ALTER DATABASE OPEN;”

to

“ALTER DATABASE OPEN RESETLOGS”

· Substitute data030d to wtest030

Rename the file as ctl_test.sql, I can give it any extension rather than .sql

2.2 Make init_databasename.ora file available for database wtest030

Make /export/home/oracle/admin/wtest030 Directory for the new database. The easiest way to do this is to copy /export/home/oracle/admin/data030d drectory and remove anything except for pfile directory.

oracle@ unixserver02>cd /export/home/oracle/admin/data030d

oracle@ unixserver02>cp –r * ../wtest030

Rename init_databasename.ora file to initwtest030.ora and substitute data030d to wtest030

Since oracle only contact init_databasename.ora file at /export/home/oracle/product/8.1.6/dbs directory, I need to make a link for initwtest030.ora file.

oracle@ unixserver02>ln –s /export/home/oracle/admin/wtest030/pfile/initwtest030.ora initwtest030.ora

2.3 Add an entry to oratab file

I need to add an entry to /var/opt/oracle/oratab file:

wtest030: /export/home/oracle/product/8.1.6:Y:NOPVCS

while wtest030 is databse name, /export/home/oracle/product/8.1.6 is oracle home directory, Y means this database will be started automatically after using “ oradbstart start all”. NOPVCS means no PVCS set up for this database.

2.4 Modifying tnsnames.ora file

There is a link for tnsnames.ora in /var/opt/oracle pointed to:

/export/home/oracle/product/8.1.6/network/admin/tnsnames.ora

Make a copy for tnsnames.ora, then:

Add following lines to the file just as I do on PCs:

wtest030=

(DESCRIPTION=

(ADDRESS = (PROTOCOL= TCP) (Host= unixserver02.daye.com) (Port= 1521)

(CONNECT_DATA = (SID = wtest030))

2.5 Modifying listener.ora file, reload the listener

There is a link for listener.ora in /var/opt/oracle pointed to:

/export/home/oracle/product/8.1.6/network/admin/listener.ora

Make a copy for listener.ora, then:

Add following lines to the file:

(SID_DESC=

(GLOBAL_NAME=wtest030)

(GLOBAL_HOME= /export/home/oracle/product/8.1.6)

(SID_NAME = wtest030)

Since Oracle listener is already running, I only need to reload it:

oracle@ unixserver02>lsnrctl reload

If this command won’t work, try this:

oracle@ unixserver02> cd /export/home/oracle

oracle@ unixserver02>. /bin/oraenv wtest030

oracle@ unixserver02>lsnrctl status

I should find line like this:

Wtest030 has 1 service handler(s)

If not, do this:

oracle@ unixserver02>lsnrctl stop

oracle@ unixserver02>lsnrctl start

2.6 Copy database from data030d to wtest030

Assume data030d is only on /u02/oradata/data030d and the newly copied database is at:

/u02/oradata/wtest030.

I can copy the files by doing this:

oracle@ unixserver02>cd /u02/oradata

oracle@ unixserver02>mkdir wtest030

oracle@ unixserver02>cd /u02/oradata/data030d

oracle@ unixserver02>cp –r * ../wtest030

After that, all old control files need to be removed:

oracle@ unixserver02>rm /u02/oradata/wtest030/*.ctl

2.7 Create control files for new database wtest030 and more

Set up oracle environment for the new database.

oracle@ unixserver02>. /bin/oraenv wtest030

oracle@ unixserver02>cd /export/home/oracle/admin/data030d/udump

Run ctl_test.sql script to create control files for database wtest030

oracle@ unixserver02>svrmgrl

SVRMGR>connect internal

Note: Here I do not need to edacute command “startup nomount” because this line is already inside ctl_test.sql script

SVRMGR>@ctl_test.sql

Change global_name from xta030d to wtest030

SVRGMR>alter database rename global_name to wtest030;

Since only development database has sqlnav user, I need to drop sqlnav:

SVRMGR>drop user sqlnav cascade;

If I want to change passWord to daye for a user, say daye:

SVRMGR>alter user daye identified by daye;

Then shuclown and restart the database:

SVRMGR> shuclown normal

SVRMGR>exit

2.8 If I want to copy database from one server to another server

When I try to copy database from one server to another server, I need to finish the following steps. Suppose I want to copy database clta030 from server unixserver01 to database clta030r on server unixserver02.

2.8.1. Share the directories on which databases reside

Do this as superuser.

Since clta030 is on /u01 and /u02, I run this command:

root@ unixserver01>share /u01

root@ unixserver01>share /u02

2.8.2. Mount the shared directories on the destination server to the meaningful mount points on the destination sever

Do this as superuser

root@ unixserver02>cd /

root@ unixserver02>mkdir unixserver01_u01

root@ unixserver02>mkdir unixserver01_u02

root@ unixserver02>mount unixserver01:/u01 /unixserver01_u01

root@ unixserver02>mount unixserver01:/u02 /unixserver01_u02

2.8.3. Build up database copy script and double check

Before I copy the database, I need to check if there is enough space on the related file systems of the destination server.

root@ unixserver02>df –k

There are also file systems named /u01 and /u02 on unixserver02, I want to copy the database to them.

oracle@ unixserver02>cd /u01/oradata

oracle@ unixserver02>mkdir clta030r

oracle@ unixserver02>cd /u02/oradata

oracle@ unixserver02>mkdir clta030r

The database copy script is: dbcopy_clta030r

#!

/bin/kshPrint “Removing the original data in clta030r”rm –f /u01/oradata/clta030r/*rm –f /u02/oradata/clta030r/*Print “Copy from unixserver01”cp /unixserver01_u01/oradata/clta030/* /u01/oradata/clta030rcp /unixserver02_u02/oradata/clta030/* /u02/oradata/clta030rPrint “Remove the original control file”rm –f /u01/oradata/clta030r/*.ctlrm –f /u02/oradata/clta030r/*.ctl

2.8.4. Create ctl_test.sql script for creating new database control file

2.8.5. Create admin directory

Every database has an admin directory. If the database SID is clta030, then the directory is “/export/home/oracle/admin/clta030”. Inside it, there are following subdirectories: audit, export, create, bdump, cdump, udump and pfile. I can copy these sub directories or create them myself.

If I want to copy these sub directories, I need to copy the whole admin directory of clta030 from server unixserver01 to database clta030r on server unixserver02.

Share /export/home on unixserver01, create a mount point unixserver01_export_home on unixserver02 and mount /export/home of unixserver01.

root@ unixserver02>mount unixserver01:/export/home /unixserver01_export_home

oracle@ unixserver02>cd /unixserver01_export_home/oracle/admin/clta030

oracle@ unixserver02>cp –r * /export/home/oracle/admin/clta030r

Make init_databasename.ora file available for database clta030r

First change initclta030.ora to initclta030r.ora. Substitute clta030 by clta030r, then make a link in /export/home/oracle/product/8.1.6/dbs

oracle@ unixserver02>cd /export/home/oracle/product/8.1.6/dbs

oracle@ unixserver02>ln –s /export/home/oracle/admin/wtest030/pfile/initclta030r.ora initclta030r.ora

2.8.6. Add an entry to oratab file

2.8.7. Modifying tnsnames.ora file

2.8.8. Modifying listener.ora file, reload the listener

2.8.9. Shuclown source database then begin to copy it and remove old control files

oracle@ unixserver01>su – oracle

oracle@ unixserver01>. /bin/oraenv clta030

oracle@

unixserver01>svrmgrl

SVRMGR>connect internal

SVRMGR>shuclown immediate

SVRMGR>exit

oracle@ unixserver02>./dbcopy_clta030r

2.8.10. Create new control files for new database clta030r

Set up oracle environment for the new database.

oracle@ unixserver02>. /bin/oraenv clta030r

oracle@ unixserver02>cd /export/home/oracle/admin

Run ctl.sql script to create control files for database clta030r

oracle@ unixserver02>svrmgrl

SVRMGR>connect internal

Note: Here I do not need to edacute command “startup nomount” because this line is already inside ctl.sql script

SVRMGR>@ctl.sql

Note: script ctl.sql was generated from clta030 on unixserver01.

2.8.11. Change global name for new database

Change global_name from clta030 to clta030r

SVRGMR>alter database rename global_name to clta030r;

Since only development database has sqlnav user, I need to drop sqlnav:

SVRMGR>drop user sqlnav cascade;

If I want to change password to daye for a user, say daye:

SVRMGR>alter user daye identified by daye;

Then shuclown and restart the database:

SVRMGR> shuclown normal

SVRMGR>exit

2.8.12. Unmount the shared directories on the destination server

root@ unixserver02> umount /unixserver01_u01

root@ unixserver02> umount /unixserver01_u02

2.8.13. Unshare the shared directories on the source serve

root@ unixserver01>unshare /u01

root@ unixserver01>unshare /u02

2.8.14. Bring up the source database

oracle@ unixserver01>. /bin/oraenv clta030

oracle@ unixserver01>echo $ORACLE_SID

oracle@ unixserver01>svrmgrl

SVRMGR>connect internal

SVRMGR>startup

SVRMGR>exit

2.8.15. Clean up user daye registry

Log on to clta030r by user daye. Run cleardaregs.sql

SQL>@/export/home/oracle/admin/scripts/dbcopy/cleardaregs.sql

It will display “12”, then type”/”.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有