Thursday, September 26, 2013

Creating a Tablespace Using an ASM Disk Group as the Destination


There are different ways to create tablespaces using ASM disks. This topic will first look at creating an ASM tablespace, allowing the default ASM disk location to be used (as a result of having set the DB_CREATE_FILE_DEST parameter). It will then describe how to create a tablespace datafile by explicitly referencing the ASM diskgroup that it is supposed to be assigned to.
Creating Tablespaces Using Default ASM Assignments
If you have defined a default ASM location, you can use the create tablespace command to create a tablepsace that will have a file in the ASM diskgroup by default as seen in this example:
create tablespace test_rgf datafile size 100k;
You can see where Oracle put the datafile by querying the DBA_DATA_FILES view:
Select tablespace_name, file_name
from dba_data_files
Where tablespace_name='TEST_RGF';
TABLESPACE FILE_NAME
---------- ---------------------------------------------------------
TEST_RGF   +COOKED_DGROUP1/rob10gr2/datafile/test_rgf.256.613064385
Note in this example that Oracle went ahead and filled out the rest of the path, giving you a complete filename in the DBA_DATA_FILES view to work with. You can also see this new file in the ASM instance using the V$ASM_FILES view as seen here:
SQL> select group_number, file_number, type, blocks, bytes
  2  from v$asm_file;

GROUP_NUMBER FILE_NUMBER TYPE                     BLOCKS      BYTES
------------ ----------- -------------------- ---------- ----------
           1         256 DATAFILE                     14     114688
If you want to drop a tablespace that contains ASM files, you only need issue the drop tablespace command. Oracle will clean up all of the ASM datafiles associated with that tablespace.
You can have a mix of ASM datafiles and normal datafiles assigned to a tablespace as seen in this create tablespace statement:
Create tablespace part_asm_tbs
Datafile 'c:\oracle\oradata\rob10gr2\part_asm_tbs_01.dbf' size 10m,
'+COOKED_DGROUP1' size 100k;
You can see where the datafiles were created:
Select tablespace_name, file_name
from dba_data_files
Where tablespace_name='PART_ASM_TBS';

TABLESPACE_NAME FILE_NAME
--------------- ------------------------------------------------------------
PART_ASM_TBS    C:\ORACLE\ORADATA\ROB10GR2\PART_ASM_TBS_01.DBF
PART_ASM_TBS    +COOKED_DGROUP1/rob10gr2/datafile/part_asm_tbs.256.613066047
Note that in this case, if you drop the part_asm_tbs tablespace, only the ASM files related to that tablespace would be removed from the disk when you issue the drop tablespace command. In cases such as these, you need to make sure you include the including contents and datafiles parameter with the drop tablespace command.
Creating Tablespaces Referencing Specific ASM Disk Groups
There are going to be many times when you will not want to define a default ASM disk group to write all tablespaces too. In this case you will want to reference the specific ASM disk group that you want a datafile created in when you issue the create tablespace command. Here is an example:
create tablespace another_test
datafile '+COOKED_DGROUP1' size 100k;
You can see where Oracle put the datafile by querying the DBA_DATA_FILES view:
Select tablespace_name, file_name
from dba_data_files
Where tablespace_name='ANOTHER_TEST';

TABLESPACE_NAME FILE_NAME
--------------- ------------------------------------------------------------
ANOTHER_TEST    +COOKED_DGROUP1/rob10gr2/datafile/another_test.256.613065911
The create tablespace command comes with a number of different options when you are using cooked file systems and there is no reason you cannot use those options when you are using ASM file systems. For example, you can create a tablespace with autoextend enabled as seen here:
create tablespace another_test
datafile '+COOKED_DGROUP1' size 100k
autoextend on next 10m maxsize 300m;
If you want to create a tablespace using a template other than the default template, this is also possible as seen in this example:
create tablespace different_template
datafile '+COOKED_DGROUP1(alternate_template)';
Tablespace Maintenance When Using Tablespaces Referencing Specific ASM Disk Groups
Tablespace maintenance is basically unchanged when using ASM disks. For example, you can add a datafile with the alter tablespace command as you normally would:
Alter tablespace part_asm_tbs
Add datafile '+COOKED_DGROUP1' size 100k;

No comments:

Post a Comment