The views expressed on this blog are my own and do not necessarily reflect the views of Oracle

January 5, 2012

ASM file number 5


The Template Directory - ASM file number 5 - contains information about all file templates for the disk group.

There are two types of templates - system and user created. The default (system) templates are always available for each file type supported by ASM. User created templates can be added for a custom template specifications.

Each template entry contains the following information:
  • The template name (for the default templates this corresponds to the file type)
  • The file redundancy (defaults to the disk group redundancy)
  • The file striping (default is file-type specific)
  • The system flag (set for the system templates)
Using templates

The full template information is externalized via V$ASM_TEMPLATE view. Let's have a look at my templates:

SQL> SELECT name "Template Name", redundancy "Redundancy", stripe "Striping", system "System"
FROM v$asm_template
WHERE group_number=1;

Template Name            Redundancy       Striping         System
------------------------ ---------------- ---------------- --------
PARAMETERFILE            MIRROR           COARSE           Y
ASMPARAMETERFILE         MIRROR           COARSE           Y
DUMPSET                  MIRROR           COARSE           Y
CONTROLFILE              HIGH             FINE             Y
FLASHFILE                MIRROR           COARSE           Y
ARCHIVELOG               MIRROR           COARSE           Y
ONLINELOG                MIRROR           COARSE           Y
DATAFILE                 MIRROR           COARSE           Y
TEMPFILE                 MIRROR           COARSE           Y
BACKUPSET                MIRROR           COARSE           Y
AUTOBACKUP               MIRROR           COARSE           Y
XTRANSPORT               MIRROR           COARSE           Y
CHANGETRACKING           MIRROR           COARSE           Y
FLASHBACK                MIRROR           COARSE           Y
DATAGUARDCONFIG          MIRROR           COARSE           Y
OCRFILE                  MIRROR           COARSE           Y

16 rows selected.

There is one template that stands out - CONTROLFILE. It is the default template for database control files. Note that a file created with this template will always be triple mirrored and fine striped. The most interesting thing about it is that we can use it to create any database file.

Here is an example (note that I am connected to the database instance here):

SQL> create tablespace TRIPLE_F datafile '+DATA(CONTROLFILE)' size 1m;

Tablespace created.

SQL> SELECT name FROM v$datafile WHERE name like '%triple_f%';

NAME
--------------------------------------------------------------------------------
+DATA/br/datafile/triple_f.271.771793293

ASM assigned file number 271 to my file. Let's now look at the redundancy of this file. This time I am connected to ASM instance:

SQL> SELECT group_number, name, type "Redundancy"
FROM v$asm_diskgroup
WHERE name='DATA';

GROUP_NUMBER NAME                             Redundancy
------------ -------------------------------- ----------------
           1 DATA                             NORMAL

So this is a normal redundancy disk group. Still, files created with CONTROLFILE template should be tripple mirrored. Let's check on my file 271:

SQL> SELECT xnum_kffxp "Extent", au_kffxp "AU", disk_kffxp "Disk"
FROM x$kffxp
WHERE group_kffxp=1 and number_kffxp=271
ORDER BY 1,2;

    Extent         AU       Disk
---------- ---------- ----------
         0       1126          1
         0       1130          3
         0       1136          2
         1       1131          3
         1       1132          0
         1       1137          2
...
         7       1132          1
         7       1135          3
         7       1141          2

24 rows selected.

As expected, the file is triple mirrored - we see that each virtual extent has three physical extents. But why do I see eight virtual extents when the size of my file is only 1 MB? Ah, that is because the file is fine striped as CONTROLFILE template dictates fine striping.

User templates

What if I want my file triple mirrored but with coarse striping? Well, I have to create my own template for that:

SQL> alter diskgroup DATA add template TRIPLE_COARSE attributes (HIGH COARSE);

Diskgroup altered.

Let's now use this template. Back to the database instance...

SQL> create tablespace TRIPLE_C datafile '+DATA(TRIPLE_COARSE)' size 1m;

Tablespace created.

SQL> SELECT name FROM v$datafile WHERE name like '%triple_c%';

NAME
--------------------------------------------------------------------------------
+DATA/br/datafile/triple_c.272.771794469

Note the ASM file number is 272. Back to the ASM instance to check this file:

SQL> SELECT xnum_kffxp "Extent", au_kffxp "AU", disk_kffxp "Disk"
FROM x$kffxp
WHERE group_kffxp=1 and number_kffxp=272
ORDER BY 1,2;

    Extent         AU       Disk
---------- ---------- ----------
         0       1136          3
         0       1137          0
         0       1142          2
         1       1133          1
         1       1137          3
         1       1143          2

6 rows selected.

Now I have one virtual extent allocated to my 1 MB file. Additional extent is for the file header. Note that the file is triple mirrored and coarsely striped.

I can also create a template for files that I don't want mirrored at all. Let's do that.

SQL> alter diskgroup DATA add template NO_MIRRORING attributes (UNPROTECTED);

Diskgroup altered.

And let's now use that template:

SQL> create tablespace NOT_IMPORTANT datafile '+DATA(NO_MIRRORING)' size 1m;

Tablespace created.

SQL> SELECT name FROM v$datafile WHERE name like '%not_important%';

NAME
--------------------------------------------------------------------------------
+DATA/br/datafile/not_important.273.771795255

This is ASM file number 273. Let's check it out:

SQL> SELECT xnum_kffxp "Extent", au_kffxp "AU", disk_kffxp "Disk"
FROM x$kffxp
WHERE group_kffxp=1 and number_kffxp=273
ORDER BY 1,2;

    Extent         AU       Disk
---------- ---------- ----------
         0       1138          0
         1       1134          1

And we can see that this file is not mirrored.

Conclusion

The template directory contains the information about file templates in the disk group. Each disk group would have the default set of system templates and users can create additional templates as required. One good use of the templates is for creating triple mirrored files in normal redundancy disk groups. Note that for this to work we need at least three failgroups in the disk group.