Showing posts with label ASM. Show all posts
Showing posts with label ASM. Show all posts

2018-01-19

AWK Usage Example: Generating Archivelog Register Statements

Here examples of generating Oracle DB statements in order to register archived log files stored in ASM into the DB.

In order to keep the implementation simple, only one archived log directory (variable P) is processed by each call.

Meaning of the awk Variables below:
  • A <- used in order print the character '
  • p <- holds the archived log directory path specified by the environment variable P
  • $8 <- Holds the strings of the 8th column. That means, contains the names of the archive log files

OS>
P="U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/"
echo "ls -l $P" |
  asmcmd |
  awk -v A="'" -v p="$P" '/^ARCH/{ print "ALTER DATABASE REGISTER LOGFILE "A p $8 A";" }' |
  more
 
Output
. . .
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12145.643.965816317';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12146.644.965816317';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12147.266.965815979';
 
Instead of the statement more as last command in the pipe, the output could by written into a file.

Another example of generating statements for archivelogs with sequence numbers >= than a given number (here 12090)  (SeqNo="12090"):
SeqNo="12094"
P="U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/"
echo "ls -l $P" |
  asmcmd |
  head |
  awk -v A="'" -v p="$P" -v n="$SeqNo" '/^ARCH/{
    if(n!="") { 
      match($0, /.+_([0-9]+)\./, sn)
    }
    if(n=="" || sn[1]>=n) {
      print "ALTER DATABASE REGISTER LOGFILE "A p $8 A";" 
    }
  }' |
  more

Output
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12094.415.965815957';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12095.432.965815957';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12096.428.965815957';


If an "empty" SeqNo is given, this parameter will be ignored
SeqNo=""
P="U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/"
echo "ls -l $P" |
  asmcmd |
  head |
  awk -v A="'" -v p="$P" -v n="$SeqNo" '/^ARCH/{
    if(n!="") { 
      match($0, /.+_([0-9]+)\./, sn)
    }
    if(n=="" || sn[1]>=n) {
      print "ALTER DATABASE REGISTER LOGFILE "A p $8 A";" 
    }
  }' |
  more

Output: all archivelogs are now listed
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_1.444.965820029';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_10.440.965828087';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12090.404.965815957';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12091.399.965815959';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12092.398.965815959';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12093.397.965815959';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12094.415.965815957';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12095.432.965815957';
ALTER DATABASE REGISTER LOGFILE 'U02/<DbUniqueName>/ARCHIVELOG/2018_01_19/thread_1_seq_12096.428.965815957';


2016-09-28

ASM: Queries Hanging (v$asm_disk)

Solved Problem When ASM Queries on v$asm_disk Hang / Block 

Wenn trying to display ASM information, Oracle Cloud Control (Enterprise Manager) displays nothing.
Also when trying to perform some queries on ASM, they "hang" and no answer is returned.
(For example: SELECT * FROM v$asm_disk; hangs)

Commands with the ASM tool asmcmdh still work:

oracle@<Host>:~/ [+ASM] asmcmdh
ASMCMD> lsdsk -p
Group_Num  Disk_Num      Incarn  Mount_Stat  Header_Stat  Mode_Stat  State   Path
        1         0  2526484498  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/grid
        2         6  2526484516  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/u01_07
        2         7  2526484517  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/u01_08
        2         8  2526484518  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/u01_09
        2         9  2526484519  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/u01_10
        3         0  2526484503  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/u02_01
        3         1  2526484505  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/u02_02
        3         2  2526484504  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/u02_03
        3         3  2526484507  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/u02_04
        3         4  2526484506  CACHED      MEMBER       ONLINE     NORMAL  /dev/ASM/u02_05


The Metalink Doc ID 8786114.8 suggests to verify / correct the ASM discovery string in order to exclude "invalid devices"
like /dev/kmem or other devices that should not be scanned by the ASM disk discovery.
For example it suggests not to use /dev/* as an ASM disk discovery string.

Querying the DB for the ASM disk discovery string, returns:

SQL> show parameter asm_diskstring
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
asm_diskstring                       string      /dev/ASM

Listing the mount points using the result from above, shows that still some mount points exits (highlighted)
that are not valid any more. (i.e. no storage is mounted on these mount points any more)
(These are not listed be the asmcmdh command from above.)
(This is not directly apparent from the result below. But I knew, that nothing was mounted at these mount points any more.)
oracle@<Host>:~/ [+ASM] ll /dev/ASM*
total 0
drwxr-xr-x  2 root root  360 Jan 24 10:29 .
drwxr-xr-x 12 root root 3660 Mar 26 15:47 ..
lrwxrwxrwx  1 root root    7 Apr 18  2013 grid -> ../xvdf
lrwxrwxrwx  1 root root    7 Apr 18  2013 u01_01 -> ../xvdb
lrwxrwxrwx  1 root root    7 Apr 18  2013 u01_02 -> ../xvdc
lrwxrwxrwx  1 root root    7 Apr 18  2013 u01_03 -> ../xvdd
lrwxrwxrwx  1 root root    7 Apr 18  2013 u01_04 -> ../xvde
lrwxrwxrwx  1 root root    7 Oct  4  2013 u01_05 -> ../xvdl
lrwxrwxrwx  1 root root    7 Oct  4  2013 u01_06 -> ../xvdm
lrwxrwxrwx  1 root root    7 Jan 24 10:29 u01_07 -> ../xvdn
lrwxrwxrwx  1 root root    7 Jan 24 10:29 u01_08 -> ../xvdo
lrwxrwxrwx  1 root root    7 Jan 24 10:29 u01_09 -> ../xvdp
lrwxrwxrwx  1 root root    7 Jan 24 10:29 u01_10 -> ../xvdq
lrwxrwxrwx  1 root root    7 Apr 18  2013 u02_01 -> ../xvdg
lrwxrwxrwx  1 root root    7 Apr 18  2013 u02_02 -> ../xvdh
lrwxrwxrwx  1 root root    7 Apr 18  2013 u02_03 -> ../xvdi
lrwxrwxrwx  1 root root    7 Apr 18  2013 u02_04 -> ../xvdj
lrwxrwxrwx  1 root root    7 Apr 18  2013 u02_05 -> ../xvdk

Problem Cause
As described in the Metalink-Article from above, the SQL statement and Cloud Control hang,
because the statement tried to query inexistent LUNs with a very long timeout.

Solution
In my case, the solution was to remove the old (invalid) mount points.
I did not need to change the ASM disk discovery string.


Tags: Oracle, ASM, Problems&Solutions, LUN, Hang, blockiert, Publish
May 06, 2014 at 09:21AM

2016-07-29

ASM: Miscellaneous Queries


Preconditions

Connected as oracle user on the DB host, set the environment to the +ASM instance.

For example:

OS> export ORACLE_HOME=/u00/app/grid/11.2.0.4.0.P0_GI
OS> export ORACLE_SID=+ASM

Logon to the +ASM instance as SYSDBA:

OS> sqlplus / as sysdba
SQL>


Queries

Diskgroup Space Usage Overview

Lists for each diskgroup, the total size, free size, usable size and used size in GB.
  • The "usable size" is the amount of free space taking in account the space needed for mirroring.
    It is calculated by subtracting required_missor_free_mb (not displayed here) from free_mb.
    For example, if normal redundancy is used, the files are mirrored. So they use twice their size space.
    In this case, if you have 10 GB free space the "usable size" would show around 5 GB.
    Since no redundancy is used in the output example below (we are using Data Guard for high availability),
    free and usable sizes are equal.

SELECT name, total_mb/1024 AS "Total GB", free_mb/1024 AS "Free GB", usable_file_mb/1024 AS "Usable GB", (total_mb-usable_file_mb)/1024 AS "Used GB"
  FROM v$asm_diskgroup;

Output example:

NAME                             Total GB    Free GB  Usable GB    Used GB
------------------------------ ---------- ---------- ---------- ----------
U01                                  1600 713.609375 713.609375 886.390625
U02                                   800 757.382813 757.382813 42.6171875


Files Overview

Lists files with their type, size, creation date and file number:

COLUMN gname   FORMAT A9           HEADING "Diskgroup|Name"
COLUMN fname   FORMAT A35          HEADING "File|Name"
COLUMN type    FORMAT A20          HEADING "File|Type"
COLUMN sizemb  FORMAT 9,999,999.99 HEADING "File|Size MB"
COLUMN credate FORMAT A16          HEADING "File|Creation Date"

SELECT g.name gname, a.name fname, f.type, f.bytes/(1024*1024) sizemb, TO_CHAR(f.creation_date,'YYYY.MM.DD HH24:MI') credate, f.file_number
  FROM v$asm_file f, v$asm_alias a, v$asm_diskgroup g
 WHERE g.group_number = a.group_number
   AND f.group_number = a.group_number
   AND f.file_number = a.file_number
   AND f.type NOT IN ('FLASHBACK','ARCHIVELOG')
 ORDER BY 2, 1;

Output example:

Diskgroup File                                File                          File File
Name      Name                                Type                       Size MB Creation Date    FILE_NUMBER
--------- ----------------------------------- -------------------- ------------- ---------------- -----------
U01       Current.256.904578613               CONTROLFILE                  32.36 2016.02.23 15:50         256
U02       Current.256.904578613               CONTROLFILE                  32.36 2016.02.23 15:50         256
U01       SYSAUX.261.904578637                DATAFILE                  4,096.01 2016.02.23 15:50         261
U01       SYSTEM.260.904578633                DATAFILE                  1,024.01 2016.02.23 15:50         260
U01       TEMP.263.904578645                  TEMPFILE                  6,144.01 2016.02.23 15:50         263
U01       TOOLS.273.904745439                 DATAFILE                     10.01 2016.02.25 14:10         273
U01       TS_APP01_DATA.306.907928707         DATAFILE                  2,048.01 2016.03.31 10:25         306
U01       TS_APP02_DATA.269.904748123         DATAFILE                    300.01 2016.02.25 14:55         270
U01       TS_APP02_IDX.274.904748203          DATAFILE                    120.01 2016.02.25 14:56         274
U01       TS_APP03_ARCH.275.904745853         DATAFILE                 32,520.01 2016.02.25 14:17         275
U01       TS_APP03_DATA.268.904748393         DATAFILE                 21,504.01 2016.02.25 14:59         268
U01       TS_APP03_IDX.268.904748394          DATAFILE                 21,504.01 2016.02.25 15:01         269
. . .


I/O and Error Statistics per DB-Instance, Disk-Group and Disk

COLUMN instname     FORMAT A10         HEADING "Instance"
COLUMN name         FORMAT A9          HEADING "Diskgroup|Name"
COLUMN group_number FORMAT 999         HEADING "Diskgroup|Number"
COLUMN disk_number  FORMAT 999         HEADING "Disk|Number"
COLUMN reads        FORMAT 999,999,999 HEADING "Total Read|Requests"
COLUMN writes       FORMAT 999,999,999 HEADING "Total Write|Requests"
COLUMN read_time    FORMAT 999,999     HEADING "Total Read|Time [1/100s]"
COLUMN write_time   FORMAT 999,999     HEADING "Total Write|Time [1/100s]"
COLUMN read         FORMAT 999,999,999 HEADING "Total Read|[MB]"
COLUMN written      FORMAT 999,999,999 HEADING "Total Write|[MB]"


SELECT d.instname, g.name, d.group_number, d.disk_number,
       d.reads, d.writes, d.read_errs, d.write_errs,
       d.read_time, d.write_time, d.bytes_read/(1024*1024) read, d.bytes_written/(1024*1024) written
  FROM v$asm_disk_iostat d, v$asm_diskgroup g
 WHERE g.group_number = d.group_number
 ORDER BY 1, 2, 3;

Output example:

           Diskgroup Diskgroup   Disk   Total Read  Total Write Total Read Total Write    Total Read   Total Write   Total Read  Total Write
Instance   Name         Number Number     Requests     Requests     Errors      Errors Time [1/100s] Time [1/100s]         [MB]         [MB]
---------- --------- --------- ------ ------------ ------------ ---------- ----------- ------------- ------------- ------------ ------------
TEST_DB    U01               1      1   16,174,066    8,985,315          0           0       546,514       464,285    3,175,899      837,536
TEST_DB    U01               1      0   16,860,897    9,075,988          0           0       597,154       462,099    3,183,002      836,577
TEST_DB    U02               2      0    1,716,125    3,428,283          0           0        78,300       119,095      721,684    1,708,365


Status and Error Statistics per Disk-Group and Disk

COLUMN name          FORMAT A9          HEADING "Diskgroup|Name"
COLUMN mount_status  FORMAT A12
COLUMN header_status FORMAT A13
COLUMN mode_status   FORMAT A11

SELECT g.name, d.group_number, d.disk_number, d.mount_status, d.header_status, d.mode_status, d.state, d.read_errs, d.write_errs
  FROM v$asm_disk d, v$asm_diskgroup g
 WHERE g.group_number = d.group_number
 ORDER BY 1, 2;

Output example:

Diskgroup Diskgroup   Disk                                                 Total Read Total Write
Name         Number Number MOUNT_STATUS HEADER_STATUS MODE_STATUS STATE        Errors      Errors
--------- --------- ------ ------------ ------------- ----------- -------- ---------- -----------
U01               1      1 CACHED       MEMBER        ONLINE      NORMAL            0           0
U01               1      0 CACHED       MEMBER        ONLINE      NORMAL            0           0
U02               2      0 CACHED       MEMBER        ONLINE      NORMAL            0           0







Tags: Oracle, ASM, Usage, Disk, Error, Space, Publish
August 19, 2011 at 01:37PM