Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Oracle Database 11g.pdf
Скачиваний:
78
Добавлен:
10.06.2015
Размер:
12.69 Mб
Скачать

682  Appendix A  n  Lab Exercises

Lab 1.2: Creating ASM Disk Groups

In this lab, you will create two ASM disk groups that you will be able to use. Because of the wide variety of ways that disks might be presented, we will use a rather simplified way of creating ASM disk groups. While Oracle/ASM does not directly support creation of ASM disk groups on existing file systems, we can use a hidden parameter and some simple OS magic to get it to do so.

The method we will use in this lab is not supported by Oracle, so you should not use it in any kind of production install. Rather, refer to the Oracle documentation for the appropriate way of creating disk groups based on the disk setup that you have and your operating system. Don’t worry if this method is not directly supported by Oracle from the point of view of the OCP exam. You will not be tested on using tools such as asmtool or asmtoolg (which you might use in an actual install) in your OCP exam.

This lab is still important, though. It will give you your first experiences managing an ASM instance. You will use ASM commands and query ASM views. As a result, the material within the lab itself is fully relevant to the OCP exam.

1.Ensure that your ASM service is running (on Windows) by running net start and look for the Oracle service called OracleASMService+ASM. If you are running Unix, from the command line use the ps command (ps -ef|grep +ASM) to determine if ASM is running. If ASM is not running, start up the ASM instance as shown in Lab 1.1, step 7.

2.If ASM is running, set the following parameter so that you can create disk groups. Note that the parameter we are setting called _ASM_ALLOW_ONLY_RAW_DISKS is not supported by Oracle. We are only using is in this lab to provide a consistent way of creating a disk group that can be used on all operating systems. Never do this in an actual production database.

Alter system set ”_asm_allow_only_raw_disks”=false scope=spfile;

3.Restart your Oracle ASM instance so the parameter change will take effect:

SQL> startup

force

 

ASM instance

started

 

Total System

Global Area 535662592 bytes

Fixed Size

1334380

bytes

Variable Size

509162388

bytes

ASM Cache

25165824

bytes

ORA-15110: no diskgroups mounted

4.Create a directory to hold the files you will be creating for ASM.

Mkdir c:\oracle\oradata\asmfiles

Lab 1.2: Creating ASM Disk Groups 

683

5.You now need to create three files that can attach to your ASM instance. These three files will simulate three disk devices that might appear if you had added a disk to your system. To create these files, you will need to use the Perl interpreter that comes with Oracle.

6.CD to your ORACLE_HOME directory where your Oracle software is installed.

7.Continue to the directory where perl.exe is located. This is typically ORACLE_HOME\ perl\5.8.3\bin\MSWin32-x86-multi-thread in a Windows environment. You can quickly find the correct home on your operating system by using the dir command or the ls command and recursively finding perl.exe, as shown in this example:

C:\oracle\product\11.1.0\db_1>dir perl.exe /s

Volume in drive C has no label.

Volume Serial Number is 08DE-E1AB

Directory of C:\oracle\product\11.1.0\db_1\perl\5.8.3\

bin\MSWin32-x86-multi-thread

 

11/15/2004 12:35 PM

16,384 perl.exe

1 File(s)

16,384 bytes

8.Having found the perl.exe executable, you will need to run the following code through the interpreter three times, one time for each of the ASM files you will be using. Each ASM file in this example will be 1GB in size. Here is the code that you will execute:

my $s=’0’ x 2**20; open(DF1,”>C:/oracle/oradata/asm_disk/_file_disk1”) || die “Cannot create file - $!\n”; open(DF2,”>C:/oracle/oradata/asm_disk/_file_disk2”) || die “Cannot create file - $!\n”; open(DF3,”>C:/oracle/oradata/asm_disk/_file_disk3”) || die “Cannot create file - $!\n”;

for (my $i=1; $i<1000; $i++) { print DF1 $s;

print DF2 $s; print DF3 $s;

}

exit

9.Save this code to a file called create_files.pl and execute this file with Perl, as shown here:

Perl create_files.pl

Having executed this Perl program, you have in essence created three virtual disks. At least, that’s what they will look like to ASM.

684  Appendix A  n  Lab Exercises

10.Having created your three “disks,” you are ready to create disk groups and associate them with your files. ASM will need to know where to find the files. You set the parameter ASM_DISKSTRING to indicate to ASM where it will find files associated with ASM. Here you set ASM_DISKSTRING to the appropriate location:

SQL>Alter system set ASM_DISKSTRING=’c:\oracle\oradata\asmfiles\_file*’;

11.Having set the ASM_DISKSTRING parameter, you should now be able to see the “fake” disk devices you just created by querying the V$ASM_DISK view, as shown in this example:

SQL> SELECT group_number ”GROUP”, disk_number ”DISK”, mount_status, 2 header_status, state, path

3 FROM v$asm_disk;

GROUP DISK MOUNT_S HEADER_STATU STATE PATH

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

0

0

CLOSED

CANDIDATE

NORMAL C:\ORACLE\ORADATA\ASMFILES\_FILE_DISK1

0

2

CLOSED

CANDIDATE

NORMAL

C:\ORACLE\ORADATA\ASMFILES\_FILE_DISK3

0

1

CLOSED

CANDIDATE

NORMAL

C:\ORACLE\ORADATA\ASMFILES\_FILE_DISK2

12.You can now create ASM disk groups. Notice that each disk group is listed as a CANDIDATE disk. This does not mean it’s running for office, but rather that it can be used in the creation of a disk group. Let’s create our first disk group!

You will use the create diskgroup command from SQL*Plus to create two disk groups. You will call them dgroup1 and dgroup2. Dgroup1 will use two of the “disks.” They will be mirrored copies of each other, providing redundancy. Dgroup2 will use external redundancy and just use one of the “disks.” Here are the create diskgroup commands:

CREATE DISKGROUP dgroup1 NORMAL REDUNDANCY failgroup diskcontrol1 DISK

‘C:\ORACLE\ORADATA\ASMFILES\_FILE_DISK1’ NAME file_disk1 failgroup diskcontrol2 DISK ‘C:\ORACLE\ORADATA\ASMFILES\_FILE_DISK2’ NAME file_disk2; CREATE DISKGROUP dgroup2 EXTERNAL REDUNDANCY

DISK ‘C:\ORACLE\ORADATA\ASMFILES\_FILE_DISK3’ NAME file_disk3;

13.You should now be able to see the disk groups that you just created by querying the V$ASM_DISKGROUP view, as shown here.

SQL> select group_number, name from v$ASM_DISKGROUP; GROUP_NUMBER NAME

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

1 DGROUP1

2 DGROUP2

Lab 1.3: Using ASM Disk Groups from a Database 

685

14.Use show parameter to display the ASM_DISKGROUPS parameter to see that it has been updated with the new disk groups.

SQL> show parameter asm_diskgroups

 

 

NAME

TYPE

VALUE

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

-----------

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

asm_diskgroups

string

DGROUP1, DGROUP2

In the next lab, you will actually create tablespaces using these disk groups!

Lab 1.3: Using ASM Disk Groups from a Database

This lab will walk you through the creation of a tablespace using ASM. This lab assumes you have a database called ORCL created, and that your ASM instance is up and running.

1.Make sure your ASM instance is up and running. Log into the ASM instance and ensure that its status is STARTED.

C:\set ORACLE_SID=+ASM C:\>sqlplus sys as sysasm

SQL*Plus: Release 11.1.0.6.0 - Production on Mon Aug 11 20:43:28 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Enter password: Connected to:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining

and Real Application Testing options SQL> select status from v$instance; STATUS

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

STARTED

2.Using the V$ASM_DISKGROUP view, make sure you have sufficient space in your disk groups and that they are mounted.

SQL> select name, state, free_mb, total_mb

2 from v$asm_diskgroup;

 

 

 

NAME

STATE

FREE_MB TOTAL_MB

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

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

DGROUP1

MOUNTED

1896

1998

DGROUP2

MOUNTED

949

999

686  Appendix A  n  Lab Exercises

3.Log into the ORCL database.

C:\>set oracle_sid=orcl C:\>sqlplus sys as sysdba

SQL*Plus: Release 11.1.0.6.0 - Production on Mon Aug 11 20:50:06 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Enter password: Connected to:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining

and Real Application Testing options

4.Create the first tablespace called ASM_TBS_ONE. We will use the ASM disk group DGROUP1 to store the underlying database datafile.

SQL> Create tablespace ASM_TBS_ONE Datafile ‘+DGROUP1’ size 200m; Tablespace created.

5.Once the tablespace is created, look at the filename information in DBA_DATA_FILES.

SQL> select file_name from dba_data_files where tablespace_name=’ASM_TBS_ONE’; FILE_NAME

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

+DGROUP1/orcl/datafile/asm_tbs_one.256.662503917

Note the file-naming convention. When you used just the DGROUP1 in the CREATE TABLESPACE command, Oracle created a default directory structure and also a default file-naming convention.

6.Create the second tablespace ASM_TBS_TWO in DGROUP2. This time we will use our own directory structure and file-naming convention.

SQL> Create tablespace ASM_TBS_TWO

2 Datafile ‘+DGROUP2/oradata/orcl/dbf/asm_tbs_two.dbf’ size 200m; Create tablespace ASM_TBS_TWO

*

ERROR at line 1:

ORA-01119: error in creating database file ‘+DGROUP2/oradata/orcl/dbf/asm_tbs_two.dbf’ ORA-17502: ksfdcre:4 Failed to create file +DGROUP2/oradata/orcl/dbf/asm_tbs_two.dbf

ORA-15173: entry ‘oradata’ does not exist in directory ‘/‘

Lab 1.3: Using ASM Disk Groups from a Database 

687

The error occurred because we did not create the underlying directory structure. We will need to do this from the ASM instance.

7.Connect to the ASM instance.

C:\set ORACLE_SID=+ASM C:\>sqlplus sys as sysasm

SQL*Plus: Release 11.1.0.6.0 - Production on Mon Aug 11 20:43:28 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Enter password: Connected to:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining

and Real Application Testing options

8.Using the ALTER DISKGROUP command, create the directory structure in DGROUP2.

SQL> Alter diskgroup dgroup2

2 Add directory ‘+DGROUP2/oradata’; Diskgroup altered.

SQL> Alter diskgroup dgroup2

2 Add directory ‘+DGROUP2/oradata/orcl’; Diskgroup altered.

SQL> Alter diskgroup dgroup2

2 Add directory ‘+DGROUP2/oradata/orcl/dbf’; Diskgroup altered.

9.Now log into the ORCL database and try again.

C:\>set oracle_sid=orcl C:\>sqlplus sys as sysdba

SQL*Plus: Release 11.1.0.6.0 - Production on Mon Aug 11 20:50:06 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Enter password: Connected to:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining

and Real Application Testing options Create tablespace ASM_TBS_TWO

Datafile ‘+DGROUP2/oradata/orcl/dbf/asm_tbs_two.dbf’ size 200m;

688  Appendix A  n  Lab Exercises

Lab 2.1: Executing a Manual Offline

(Cold) Backup

In this lab, you will perform an offline backup. This lab will work if your database is in NOARCHIVELOG or ARCHIVELOG mode. In the Chapter 3 lab exercises, you will use the backup created in this lab to restore your database.

This exercise assumes that you do not have any tablespaces using space in an ASM instance. Though offline backups are possible with ASM, we

strongly advise that you use RMAN to perform your backups. The OCP exam will not test your knowledge of manual backups of databases using ASM.

1.Create a directory to copy your backup-related files to. In this example, we will be using c:\oracle\orabackup\orcl\cold.

C:\>mkdir oracle C:\>cd oracle

C:\oracle>mkdir orabackup C:\oracle>cd orabackup C:\oracle\orabackup>mkdir orcl C:\oracle\orabackup>cd orcl C:\oracle\orabackup\orcl>mkdir cold

2.Log into your database using SQL*Plus.

C:\oracle\orabackup\orcl>sqlplus sys as sysdba

SQL*Plus: Release 11.1.0.6.0 - Production on Thu Aug 14 18:57:13 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Enter password: Connected to:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining

and Real Application Testing options SQL>

3.Using the DBA_DATA_FILES view, determine the datafiles that you will need to back up.

SQL> select tablespace_name, file_name from dba_data_files; TABLESPACE_NAME FILE_NAME

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

USERS C:\ORACLE\ORADATA\ORCL\USERS01.DBF

UNDOTBS1 C:\ORACLE\ORADATA\ORCL\UNDOTBS01.DBF

Lab 2.1: Executing a Manual Offline (Cold) Backup 

689

SYSAUX C:\ORACLE\ORADATA\ORCL\SYSAUX01.DBF

SYSTEM C:\ORACLE\ORADATA\ORCL\SYSTEM01.DBF

Note, for the purpose of this lab, that all of our datafiles, control files, and online redo logs are in the same directory. Also note that the number of files in your database may be different than those shown in this lab.

4.Using the V$LOGFILE view, determine the online redo logs that will require a backup.

SQL> select member from v$logfile; MEMBER

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

C:\ORACLE\ORADATA\ORCL\REDO03.LOG

C:\ORACLE\ORADATA\ORCL\REDO02.LOG

C:\ORACLE\ORADATA\ORCL\REDO01.LOG

Again, the number of online redo logs in your database may be different than the number in this lab.

5.Using the V$CONTROLFILE view, determine the location of the database control files that will be backed up.

SQL> select name from v$controlfile; NAME

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

C:\ORACLE\ORADATA\ORCL\CONTROL01.CTL

C:\ORACLE\ORADATA\ORCL\CONTROL02.CTL

C:\ORACLE\ORADATA\ORCL\CONTROL03.CTL

6.From the SQL*Plus prompt, shut down the database with the shutdown immediate command.

SQL> shutdown immediate Database closed. Database dismounted.

ORACLE instance shut down.

7.Once the database is shut down, exit SQL*Plus.

SQL>exit

C:\oracle\orabackup\orcl>

690  Appendix A  n  Lab Exercises

8.Using the OS Copy command, copy the database datafiles, control files, and online redo logs to the backup directory created in step 1. In our example, they are all in the same directory, so this is easy to do.

C:\oracle\orabackup\orcl>Copy c:\oracle\oradata\orcl\*.* c:\oracle\orabackup\orcl\cold

c:\oracle\oradata\orcl\CONTROL01.CTL

c:\oracle\oradata\orcl\CONTROL02.CTL

c:\oracle\oradata\orcl\CONTROL03.CTL

c:\oracle\oradata\orcl\REDO01.LOG

c:\oracle\oradata\orcl\REDO02.LOG

c:\oracle\oradata\orcl\REDO03.LOG

c:\oracle\oradata\orcl\SYSAUX01.DBF

c:\oracle\oradata\orcl\SYSTEM01.DBF

c:\oracle\oradata\orcl\TEMP01.DBF

c:\oracle\oradata\orcl\UNDOTBS01.DBF

c:\oracle\oradata\orcl\USERS01.DBF 11 file(s) copied.

You will notice that we backed up a file called TEMP01.DBF that didn’t show up in the list of files. This is the tempfile associated with the temporary tablespace. Technically, we didn’t need to back this file up because when we do a restore, we just re-create it.

9.Start SQL*Plus connecting as sys as sysdba. Restart the database with the startup command. You have completed your backup.

C:\oracle\orabackup\orcl>sqlplus sys as sysdba

SQL*Plus: Release 11.1.0.6.0 - Production on Thu Aug 14 19:31:56 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Enter password:

Connected to an idle instance.

SQL> startup

 

 

ORACLE instance started.

 

 

Total System Global Area

397557760

bytes

Fixed Size

1333452

bytes

Variable Size

268437300

bytes

Database Buffers

121634816

bytes

Redo Buffers

6152192

bytes

Database mounted.

 

 

Database opened.

 

 

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]