Sunday, June 30, 2013

Oracle Golden Gate

http://www.oraclegis.com
http://ggsig.blogspot.in/2012/12/golden-gate-replication-oracle-db.html --> Steps to configure Replication between Oracle->Oracle
http://oraclespot.wordpress.com/2011/06/15/oracle_goldengate/

Cannot load ICU resource bundle 'ggMessage', error code 2 - No such file or directory


Move to the GG install directory and invoke ggsci.. 
ggsci> dblogin userid <>,password <>

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

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=ggdb1
export GG_HOME=/u01/app/oracle/ggs/11.2.0
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$GG_HOME:$LD_LIBRARY_PATH
export PATH=GG_HOME:$ORACLE_HOME/bin:$PATH


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

Before configuring Golden Gate at DB level:

1). Put database in archivelog mode --> Requires bounce till 11gR2, but not from 12c(Need to check).
2). Enable Supplemental Logging
SELECT SUPPLEMENTAL_DATA_LOG_MIN FROM V$DATABASE;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

Saturday, June 29, 2013

ORA-00845: MEMORY_TARGET not supported on this system

A known issue, when starting database.

SQL> startup
ORA-00845: MEMORY_TARGET not supported on this system

This is due to low space on tmpfs (/dev/shm)

[oracle@node1 ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                1006M  520M  486M  52% /dev/shm

[root@node1 +ASM]#  mount -o remount,size=3G /dev/shm
[root@node1 +ASM]# df -h
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 3.0G  520M  2.5G  17% /dev/shm
[root@node1 +ASM]# vi /etc/fstab
Update fstab file with size=<size> for tmpfs
tmpfs                   /dev/shm                tmpfs   defaults,size=3G       0 0
[root@node1 +ASM]# mount -a
[root@node1 +ASM]# df -h
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 3.0G  520M  2.5G  17% /dev/shm


Start the database and it starts normally.

Friday, June 28, 2013

archivelog generation per hour in gb

archivelog generation per hour in gb

SELECT A.*,
Round(A.Count#*B.AVG#/1024/1024/1024) Daily_Avg_GB
FROM
(
SELECT
To_Char(First_Time,'YYYY-MM-DD') DAY,
Count(1) Count#,
Min(RECID) Min#,
Max(RECID) Max#
FROM
v$log_history
GROUP
BY To_Char(First_Time,'YYYY-MM-DD')
ORDER
BY 1 DESC
) A,
(
SELECT
Avg(BYTES) AVG#,
Count(1) Count#,
Max(BYTES) Max_Bytes,
Min(BYTES) Min_Bytes
FROM
v$log
) B;

Defalt Oracle 12c Background Process --> Not Detailed

oracle    4897     1  0 13:22 ?        00:00:00 ora_pmon_Ora12c
oracle    4899     1  0 13:22 ?        00:00:00 ora_psp0_Ora12c
oracle    4901     1  0 13:22 ?        00:00:00 ora_vktm_Ora12c
oracle    4905     1  0 13:22 ?        00:00:00 ora_gen0_Ora12c
oracle    4907     1  0 13:22 ?        00:00:00 ora_mman_Ora12c
oracle    4911     1  0 13:22 ?        00:00:00 ora_diag_Ora12c
oracle    4913     1  0 13:22 ?        00:00:00 ora_dbrm_Ora12c
oracle    4916     1  0 13:22 ?        00:00:00 ora_dia0_Ora12c
oracle    4918     1  0 13:22 ?        00:00:00 ora_dbw0_Ora12c
oracle    4920     1  0 13:22 ?        00:00:00 ora_lgwr_Ora12c
oracle    4922     1  0 13:22 ?        00:00:00 ora_ckpt_Ora12c
oracle    4924     1  0 13:22 ?        00:00:00 ora_smon_Ora12c
oracle    4926     1  0 13:22 ?        00:00:00 ora_reco_Ora12c
oracle    4928     1  0 13:22 ?        00:00:02 ora_lreg_Ora12c
oracle    4930     1  0 13:22 ?        00:00:03 ora_mmon_Ora12c
oracle    4932     1  0 13:22 ?        00:00:04 ora_mmnl_Ora12c
oracle    4934     1  0 13:22 ?        00:00:00 ora_d000_Ora12c
oracle    4936     1  0 13:22 ?        00:00:00 ora_s000_Ora12c
oracle    4949  4884  0 13:22 ?        00:00:17 oracleOra12c (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle    4954     1  0 13:22 ?        00:00:00 ora_tmon_Ora12c
oracle    4956     1  0 13:22 ?        00:00:00 ora_tt00_Ora12c
oracle    4958     1  0 13:22 ?        00:00:00 ora_smco_Ora12c
oracle    4967     1  0 13:22 ?        00:00:00 ora_aqpc_Ora12c
oracle    4989     1  0 13:23 ?        00:00:00 ora_qm02_Ora12c
oracle    4997     1  0 13:23 ?        00:00:00 ora_q002_Ora12c
oracle    4999     1  0 13:23 ?        00:00:00 ora_q003_Ora12c
oracle    5016     1  0 13:23 ?        00:02:05 ora_cjq0_Ora12c
oracle   11855     1  0 18:03 ?        00:00:00 ora_w000_Ora12c

Oracle 12C Miscellaneous

To Get Current Container:

SQL> SELECT sys_context ('USERENV','CON_NAME') from dual;
SYS_CONTEXT('USERENV','CON_NAME')
------------------------------------------------------
CDB$ROOT

SQL> Select Name,Con_name,Con_ID from v$active_services;
SQL> Show CON_NAME;
SQL> SELECT pdb FROM dba_services;

 SQL> SELECT sys_context(‘userenv’,’con_name’) “MY_CONTAINER” FROM dual;

DBA_PDBS --> Gives list of PDBS (PDB$SEED,PDB1)
v$PDBS --> Gives list of PDB's along with open_mode,start time..
CDB_PDBS
DBA_PDB_HISTORY

Table 5-11 Predefined Parameters of Namespace USERENV
ParameterReturn Value
ACTIONIdentifies the position in the module (application name) and is set through the DBMS_APPLICATION_INFO package or OCI.
AUDITED_CURSORIDReturns the cursor ID of the SQL that triggered the audit. This parameter is not valid in a fine-grained auditing environment. If you specify it in such an environment, then Oracle Database always returns NULL.
AUTHENTICATED_IDENTITYReturns the identity used in authentication. In the list that follows, the type of user is followed by the value returned:
  • Kerberos-authenticated enterprise user: kerberos principal name
  • Kerberos-authenticated external user : kerberos principal name; same as the schema name
  • SSL-authenticated enterprise user: the DN in the user's PKI certificate
  • SSL-authenticated external user: the DN in the user's PKI certificate
  • Password-authenticated enterprise user: nickname; same as the login name
  • Password-authenticated database user: the database username; same as the schema name
  • OS-authenticated external user: the external operating system user name
  • Radius-authenticated external user: the schema name
  • Proxy with DN : Oracle Internet Directory DN of the client
  • Proxy with certificate: certificate DN of the client
  • Proxy with username: database user name if client is a local database user; nickname if client is an enterprise user.
  • SYSDBA/SYSOPER using Password File: login name
  • SYSDBA/SYSOPER using OS authentication: operating system user name
AUTHENTICATION_DATAData being used to authenticate the login user. For X.503 certificate authenticated sessions, this field returns the context of the certificate in HEX2 format.
Note: You can change the return value of the AUTHENTICATION_DATA attribute using the length parameter of the syntax. Values of up to 4000 are accepted. This is the only attribute of USERENV for which Oracle Database implements such a change.
AUTHENTICATION_METHODReturns the method of authentication. In the list that follows, the type of user is followed by the method returned:
  • Password-authenticated enterprise user, local database user, or SYSDBA/SYSOPER using Password File; proxy with username using password: PASSWORD
  • Kerberos-authenticated enterprise or external user: KERBEROS
  • SSL-authenticated enterprise or external user: SSL
  • Radius-authenticated external user: RADIUS
  • OS-authenticated external user or SYSDBA/SYSOPER: OS
  • Proxy with certificate, DN, or username without using password: NONE
  • Background process (job queue slave process): JOB
  • Parallel Query Slave process: PQ_SLAVE
You can use IDENTIFICATION_TYPE to distinguish between external and enterprise users when the authentication method is Password, Kerberos, or SSL.
BG_JOB_IDJob ID of the current session if it was established by an Oracle Database background process. Null if the session was not established by a background process.
CLIENT_IDENTIFIERReturns an identifier that is set by the application through the DBMS_SESSION.SET_IDENTIFIER procedure, the OCI attribute OCI_ATTR_CLIENT_IDENTIFIER, or Oracle Dynamic Monitoring Service (DMS). This attribute is used by various database components to identify lightweight application users who authenticate as the same database user.
CLIENT_INFOReturns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
CURRENT_BINDThe bind variables for fine-grained auditing. You can specify this attribute only inside the event handler for the fine-grained auditing feature.
CURRENT_EDITION_IDThe identifier of the current edition.
CURRENT_EDITION_NAMEThe name of the current edition.
CURRENT_SCHEMAThe name of the currently active default schema. This value may change during the duration of a session through use of an ALTER SESSION SET CURRENT_SCHEMA statement. This may also change during the duration of a session to reflect the owner of any active definer's rights object. When used directly in the body of a view definition, this returns the default schema used when executing the cursor that is using the view; it does not respect views used in the cursor as being definer's rights.
Note: Oracle recommends against issuing the SQL statement ALTER SESSION SET CURRENT_SCHEMA from within all types of stored PL/SQL units except logon triggers.
CURRENT_SCHEMAIDIdentifier of the currently active default schema.
CURRENT_SQL
CURRENT_SQLn
CURRENT_SQL returns the first 4K bytes of the current SQL that triggered the fine-grained auditing event. The CURRENT_SQLn attributes return subsequent 4K-byte increments, where n can be an integer from 1 to 7, inclusive. CURRENT_SQL1 returns bytes 4K to 8K; CURRENT_SQL2 returns bytes 8K to 12K, and so forth. You can specify these attributes only inside the event handler for the fine-grained auditing feature.
CURRENT_SQL_LENGTHThe length of the current SQL statement that triggers fine-grained audit or row-level security (RLS) policy functions or event handlers. You can specify this attribute only inside the event handler for the fine-grained auditing feature.
CURRENT_USERThe name of the database user whose privileges are currently active. This may change during the duration of a session to reflect the owner of any active definer's rights object. When no definer's rights object is active, CURRENT_USER returns the same value as SESSION_USER. When used directly in the body of a view definition, this returns the user that is executing the cursor that is using the view; it does not respect views used in the cursor as being definer's rights.
CURRENT_USERIDThe identifier of the database user whose privileges are currently active.
DATABASE_ROLEThe database role using the SYS_CONTEXT function with the USERENV namespace. The role is one of the following: PRIMARY, PHYSICAL STANDBY, LOGICAL STANDBY, SNAPSHOT STANDBY.
DB_DOMAINDomain of the database as specified in the DB_DOMAIN initialization parameter.
DB_NAMEName of the database as specified in the DB_NAME initialization parameter.
DB_UNIQUE_NAMEName of the database as specified in the DB_UNIQUE_NAME initialization parameter.
DBLINK_INFOReturns the source of a database link session. Specifically, it returns a string of the form:
SOURCE_GLOBAL_NAME=dblink_src_global_name, DBLINK_NAME=dblink_name, SOURCE_AUDIT_SESSIONID=dblink_src_audit_sessionid
where:
  • dblink_src_global_name is the unique global name of the source database
  • dblink_name is the name of the database link on the source database
  • dblink_src_audit_sessionid is the audit session ID of the session on the source database that initiated the connection to the remote database using dblink_name
ENTRYIDThe current audit entry number. The audit entryid sequence is shared between fine-grained audit records and regular audit records. You cannot use this attribute in distributed SQL statements. The correct auditing entry identifier can be seen only through an audit handler for standard or fine-grained audit.
ENTERPRISE_IDENTITYReturns the user's enterprise-wide identity:
  • For enterprise users: the Oracle Internet Directory DN.
  • For external users: the external identity (Kerberos principal name, Radius schema names, OS user name, Certificate DN).
  • For local users and SYSDBA/SYSOPER logins: NULL.
The value of the attribute differs by proxy method:
  • For a proxy with DN: the Oracle Internet Directory DN of the client
  • For a proxy with certificate: the certificate DN of the client for external users; the Oracle Internet Directory DN for global users
  • For a proxy with username: the Oracle Internet Directory DN if the client is an enterprise users; NULL if the client is a local database user.
FG_JOB_IDJob ID of the current session if it was established by a client foreground process. Null if the session was not established by a foreground process.
GLOBAL_CONTEXT_MEMORYReturns the number being used in the System Global Area by the globally accessed context.
GLOBAL_UIDReturns the global user ID from Oracle Internet Directory for Enterprise User Security (EUS) logins; returns null for all other logins.
HOSTName of the host machine from which the client has connected.
IDENTIFICATION_TYPEReturns the way the user's schema was created in the database. Specifically, it reflects the IDENTIFIED clause in the CREATE/ALTER USER syntax. In the list that follows, the syntax used during schema creation is followed by the identification type returned:
  • IDENTIFIED BY password: LOCAL
  • IDENTIFIED EXTERNALLY: EXTERNAL
  • IDENTIFIED GLOBALLY: GLOBAL SHARED
  • IDENTIFIED GLOBALLY AS DN: GLOBAL PRIVATE
INSTANCEThe instance identification number of the current instance.
INSTANCE_NAMEThe name of the instance.
IP_ADDRESSIP address of the machine from which the client is connected. If the client and server are on the same machine and the connection uses IPv6 addressing, then ::1 is returned.
ISDBAReturns TRUE if the user has been authenticated as having DBA privileges either through the operating system or through a password file.
LANGThe abbreviated name for the language, a shorter form than the existing 'LANGUAGE' parameter.
LANGUAGEThe language and territory currently used by your session, along with the database character set, in this form:
language_territory.characterset
MODULEThe application name (module) set through the DBMS_APPLICATION_INFO package or OCI.
NETWORK_PROTOCOLNetwork protocol being used for communication, as specified in the 'PROTOCOL=protocol' portion of the connect string.
NLS_CALENDARThe current calendar of the current session.
NLS_CURRENCYThe currency of the current session.
NLS_DATE_FORMATThe date format for the session.
NLS_DATE_LANGUAGEThe language used for expressing dates.
NLS_SORTBINARY or the linguistic sort basis.
NLS_TERRITORYThe territory of the current session.
OS_USEROperating system user name of the client process that initiated the database session.
POLICY_INVOKERThe invoker of row-level security (RLS) policy functions.
PROXY_ENTERPRISE_IDENTITYReturns the Oracle Internet Directory DN when the proxy user is an enterprise user.
PROXY_USERName of the database user who opened the current session on behalf of SESSION_USER.
PROXY_USERIDIdentifier of the database user who opened the current session on behalf of SESSION_USER.
SERVER_HOSTThe host name of the machine on which the instance is running.
SERVICE_NAMEThe name of the service to which a given session is connected.
SESSION_EDITION_IDThe identifier of the session edition.
SESSION_EDITION_NAMEThe name of the session edition.
SESSION_USERThe name of the database user at logon. For enterprise users, returns the schema. For other users, returns the database user name. This value remains the same throughout the duration of the session.
SESSION_USERIDThe identifier of the database user at logon.
SESSIONIDThe auditing session identifier. You cannot use this attribute in distributed SQL statements.
SIDThe session ID.
STATEMENTIDThe auditing statement identifier. STATEMENTID represents the number of SQL statements audited in a given session. You cannot use this attribute in distributed SQL statements. The correct auditing statement identifier can be seen only through an audit handler for standard or fine-grained audit.
TERMINALThe operating system identifier for the client of the current session. In distributed SQL statements, this attribute returns the identifier for your local session. In a distributed environment, this is supported only for remote SELECT statements, not for remote INSERT, UPDATE, or DELETE operations. (The return length of this parameter may vary by operating system.)
Table 5-12 lists the parameters of namespace USERENV that have been deprecated. Do not specify any of these parameters. Instead use the alternatives suggested in the Comments column.
Table 5-12 Deprecated Parameters of Namespace USERENV
ParameterComments
AUTHENTICATION_TYPEThis parameter returned a value indicating how the user was authenticated. The same information is now available from the new AUTHENTICATION_METHOD parameter combined with IDENTIFICATION_TYPE.
EXTERNAL_NAMEThis parameter returned the external name of the user. More complete information can now be obtained from the AUTHENTICATED_IDENTITY and ENTERPRISE_IDENTITY parameter.

Thursday, June 27, 2013

Query to find user privileges and roles


SQL> SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE='HOLDWIND';

GRANTEE                        PRIVILEGE                                ADM
------------------------------ ---------------------------------------- ---
HOLDWIND                       UNLIMITED TABLESPACE                     NO

SQL> SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE='DHOLDWIN';

GRANTEE                        PRIVILEGE                                ADM
------------------------------ ---------------------------------------- ---
DHOLDWIN                       CREATE TABLE                             NO
DHOLDWIN                       UNLIMITED TABLESPACE                     NO

SQL>

SQL> SELECT * FROM DBA_ROLE_PRIVS WHERE GRANTEE = 'HOLDWIND';

GRANTEE                        GRANTED_ROLE                   ADM DEF
------------------------------ ------------------------------ --- ---
HOLDWIND                       DBA                            NO  YES
HOLDWIND                       ICS_USER                       NO  YES

SQL> SELECT * FROM DBA_ROLE_PRIVS WHERE GRANTEE = 'DHOLDWIN';

GRANTEE                        GRANTED_ROLE                   ADM DEF
------------------------------ ------------------------------ --- ---
DHOLDWIN                       DBA                            NO  YES

query for user DDL - ORACLE

query for user DDL - ORACLE

set long 200000 pages 0 lines 131
column meta format a121 word_wrapped
select dbms_metadata.get_ddl('USER', '&&username') meta from dual;
select dbms_metadata.get_granted_ddl('OBJECT_GRANT', '&&username') meta from dual;
select dbms_metadata.get_granted_ddl('ROLE_GRANT', '&&username') meta from dual;
select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', '&&username') meta from dual;




Query to find the DDL of schema's in Oracle Database


select dbms_metadata.get_ddl( 'USER','username' ) from dual
     UNION ALL
     select dbms_metadata.get_granted_ddl('SYSTEM_GRANT','username') from dual
          UNION ALL 
          select dbms_metadata.get_granted_ddl('OBJECT_GRANT','username') from dual
               UNION ALL 
               select dbms_metadata.get_granted_ddl('ROLE_GRANT','username') from dual;

Get Oracle User DDL with dbms_metadata

Get Oracle User DDL with dbms_metadata



SYS@orcl > SELECT dbms_metadata.get_ddl('USER','SCOTT') FROM dual;

DBMS_METADATA.GET_DDL('USER','SCOTT')
--------------------------------------------------------------------------------
   CREATE USER "SCOTT" IDENTIFIED BY VALUES 'F894844C34402B67'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP"



SYS@orcl > SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT','SCOTT') from dual;

DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT','SCOTT')
--------------------------------------------------------------------------------
   GRANT "CONNECT" TO "SCOTT"
   GRANT "RESOURCE" TO "SCOTT"


SYS@orcl > SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT','SCOTT') from dual;

DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT','SCOTT')
--------------------------------------------------------------------------------
  GRANT SELECT ON "HR"."EMPLOYEES" TO "SCOTT"



SYS@orcl > SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','SCOTT') from dual;

DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','SCOTT')
--------------------------------------------------------------------------------
  GRANT UNLIMITED TABLESPACE TO "SCOTT"



SYS@orcl >  SELECT dbms_metadata.get_ddl('ROLE','RESOURCE') from dual;

DBMS_METADATA.GET_DDL('ROLE','RESOURCE')
--------------------------------------------------------------------------------
   CREATE ROLE "RESOURCE"



SYS@orcl > SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','RESOURCE') from dual;

DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','RESOURCE')
--------------------------------------------------------------------------------
  GRANT CREATE INDEXTYPE TO "RESOURCE"
  GRANT CREATE OPERATOR TO "RESOURCE"
  GRANT CREATE TYPE TO "RESOURCE"
  GRANT CREATE TRIGGER TO "RESOURCE"
  GRANT CREATE PROCEDURE TO "RESOURCE"
  GRANT CREATE SEQUENCE TO "RESOURCE"
  GRANT CREATE CLUSTER TO "RESOURCE"

Friday, June 21, 2013

Permitting a user on UNIX / Linux to use sqlplus

http://databaseoracle.blogspot.co.uk/2006/11/permitting-user-on-unix-linux-to-use.html

  1. For any normal user (not a part of "oinstall" / "dba" groups ) to be able to run sqlplus and access an ORACLE database , read/execute permissions are required for these 4 directories :
    1. $ORACLE_HOME/bin
    2. $ORACLE_HOME/lib
    3. $ORACLE_HOME/oracore
    4. $ORACLE_HOME/sqlplus
  2. In addition, these 4 parameters should also be set in the user's environment (.profile) :
    1. ORACLE_HOME,
    2. LD_LIBRARY_PATH,
    3. ORACLE_SID,
    4. PATH

Monday, June 17, 2013

Adding a new disk to Linux in VMWARE

Please follow the steps in below link:

http://www.matttopper.com/2006/05/adding-a-new-disk-to-a-vmware-virtual-machine-in-linux/

for any issues during mounting like:

fsck.ext3: Unable to resolve 'LABEL=/boot'
fsck.ext3: Unable to resolve 'LABEL=/home'

*** An error occurred during the file system check.
*** Dropping you to a shell; the system will reboot
*** when you leave the shell.
Give root password for maintenance

From maintainence, 

A few useful commands here; just in brief, enough as keywords for you to go googling for details, or check the man pages.

fdisk -l(to find out the partitions on the disks)
e2label/dev/sda1(find out or write the label for a partition. in this case, partition 1 of /dev/sda. of course, IDE disks will show as /dev/hda etc)
mount -o remount,rw /(remount a readonly filesystem readwrite so changes can be made, especially to files like /etc/shadow, /etc/fstab, /boot/grub/menu.lst etc)
passwd(change the root password if you have forgotten)

Sometimes it is useful to go into single user mode, especially if the server hangs when it tries to bring up the network. To do so, when grub comes up, press the up or down arrow keys, select one of the kernel, press 'e' for edit, and append "single" to the end of the line. come out of the editing by pressing enter, and press 'b' for boot. Also useful when you have SCSI RAID drivers, other than provided on the installation disk, on the server. So you really want the server to boot up with the drivers.

Usually, if you have access to the console, it is easy to boot up using CD. example, the server cd of centos. key in linux rescue at the prompt, and you will get a nice environment to use for fixing your server.

Thursday, June 13, 2013

ASM Script

The ASM script of all ASM scripts !

Posted by John Hallas on February 1, 2009
The asm information script I use which gives me everything I think I need in one go.
If there are any queries that others find useful please comment on them and I will add them to the script.

Credit where credit is due. I think Alan Cooper wrote the original version, although it has been amended since then.

set wrap off
set lines 120
set pages 999
col “Group Name”   form a25
col “Disk Name”    form a30
col “State”  form a15
col “Type”   form a7
col “Free GB”   form 9,999

prompt
prompt ASM Disk Groups
prompt ===============
select group_number  “Group”
,      name          “Group Name”
,      state         “State”
,      type          “Type”
,      total_mb/1024 “Total GB”
,      free_mb/1024  “Free GB”
from   v$asm_diskgroup
/

prompt
prompt ASM Disks
prompt =========

col “Group”          form 999
col “Disk”           form 999
col “Header”         form a9
col “Mode”           form a8
col “Redundancy”     form a10
col “Failure Group”  form a10
col “Path”           form a19

select group_number  “Group”
,      disk_number   “Disk”
,      header_status “Header”
,      mode_status   “Mode”
,      state         “State”
,      redundancy    “Redundancy”
,      total_mb      “Total MB”
,      free_mb       “Free MB”
,      name          “Disk Name”
,      failgroup     “Failure Group”
,      path          “Path”
from   v$asm_disk
order by group_number
,        disk_number
/

prompt
prompt Instances currently accessing these diskgroups
prompt ==============================================
col “Instance” form a8
select c.group_number  “Group”
,      g.name          “Group Name”
,      c.instance_name “Instance”
from   v$asm_client c
,      v$asm_diskgroup g
where  g.group_number=c.group_number
/

prompt
prompt Current ASM disk operations
prompt ===========================
select *
from   v$asm_operation
/

prompt
prompt free ASM disks and their paths
prompt ===========================
select header_status , mode_status, path from V$asm_disk
where header_status in (‘FORMER’,'CANDIDATE’)
/

clear columns

Got it from 

Wednesday, June 12, 2013

Logical Standby Sync

## if you are using a logical standby then you need to check the following to confirm the redo has been
## applied

sql> select applied_scn, latest_scn, mining_scn from v$logstdby_progress;

## if the mining scn is behind you may have a gap check this by using the following

sql> select status from v$logstdby_process where type = 'READER';

SELECT APPLIED_SCN, APPLIED_TIME, READ_SCN, READ_TIME, NEWEST_SCN, NEWEST_TIME
FROM DBA_LOGSTDBY_PROGRESS;

From:
http://aprilcsims.wordpress.com/logical-standby-10gr2-open-issues/
http://www.datadisk.co.uk/html_docs/oracle_dg/cheatsheet.htm

Tuesday, June 11, 2013

ASM diskgroup space usage queries

From Gavin Soorma:

Monitor space used in ASM Disk Groups

SET LINESIZE  145
SET PAGESIZE 9999
SET VERIFY off
COLUMN group_name FORMAT a20 HEAD 'Disk Group|Name'
COLUMN sector_size FORMAT 99,999 HEAD 'Sector|Size'
COLUMN block_size FORMAT 99,999 HEAD 'Block|Size'
COLUMN allocation_unit_size FORMAT 999,999,999 HEAD 'Allocation|Unit Size'
COLUMN state FORMAT a11 HEAD 'State'
COLUMN type FORMAT a6 HEAD 'Type'
COLUMN total_mb FORMAT 999,999,999 HEAD 'Total Size (MB)'
COLUMN used_mb FORMAT 999,999,999 HEAD 'Used Size (MB)'
COLUMN pct_used FORMAT 999.99 HEAD 'Pct. Used'



break on report on disk_group_name skip 1
compute sum label "Grand Total: " of total_mb used_mb on report


SELECT
name group_name
, sector_size sector_size
, block_size block_size
, allocation_unit_size allocation_unit_size
, state state
, type type
, total_mb total_mb
, (total_mb - free_mb) used_mb
, ROUND((1- (free_mb / total_mb))*100, 2) pct_used
FROM
v$asm_diskgroup
ORDER BY
name
/
-----------------------------------------------------------------------------
To find the free space in an ASM disk : select group_number, disk_number, name, failgroup, create_date, path, total_mb,free_mb from v$asm_disk; 
To find the free space in an ASM diskgroup : select name, group_number, name, type, state, total_mb, free_mb from v$asm_diskgroup; To see the current ASM operations in Progress :select group_number, operation, state, power, actual, sofar, est_work, est_rate, est_minutes from v$asm_operation;
---------------------------------------------------------------------------------------

dfdg for 11g Oracle and HP-UX OS:



#!/usr/local/bin/bash

# ------------------------------------------------------------------------------
# FUNCTION
# Displays ASM diskgroup information, space usage. Displays usage by DISKS.
# Displays ongoing operations and list of files on diskgroup.
# NOTES
# Developed for 11g Oracle Version. The entry must be in the /etc/oratab
# for ASM instance
# CREATED
# Aychin Gasimov 03/2011 aychin.gasimov@gmail.com
# MODIFIED
# Xavier Picamal 08/2012
# Added -r key
# ------------------------------------------------------------------------------

TMP1=`grep -E '^\+' /etc/oratab`

if [ -z $TMP1 ]; then
echo "Please check /etc/oratab file, there is no entry for ASM instance."
exit 1
fi

ORACLE_HOME=`echo ${TMP1//\:/ } | awk {'print $2'}`
ORACLE_SID=`echo ${TMP1//\:/ } | awk {'print $1'}`

cd $ORACLE_HOME/bin

dispinfo () {
echo "Use -d key to display usage by disks"
echo "Use -o key to display asm operations in progress (disk rebalancing)"
echo "Use -r key to display min, max and avergage free megabytes by diskgroups"
echo "Use -f to list files and directories of the disk group"
}

case "$1" in
-d)
sqlplus -S '/ as sysasm' << EOF
set linesize 200
set pagesize 50000
col path format a50
col free_pct format a8
select group_number,name,path,state,os_mb,total_mb,free_mb,round(free_mb*100/total_mb)||'%' free_pct from v\$asm_disk where header_status='MEMBER';
EOF
dispinfo;
;;
-o)
sqlplus -S '/ as sysasm' << EOF
set linesize 200
select * from v\$asm_operation;
EOF
;;
-f)
if [ -e $2 ]; then
echo "Please specify diskgroup name after -f key"
else
sqlplus -S '/ as sysasm' << EOF
alter session set nls_date_format='dd.mm.yyyy hh24:mi:ss';
set linesize 200
set pagesize 50000
variable pindx number;
exec select group_number into :pindx from v\$asm_diskgroup where upper(name)=upper('$2');
col reference_index noprint
break on reference_index skip 1 on report
compute sum label "Total size of all files in MBytes on diskgroup $2" of mb on report
col type format a15
col files format a80
select decode(aa.alias_directory,'Y',sys_connect_by_path(aa.name,'/'),'N',lpad(' ',level)||aa.name) files, aa.REFERENCE_INDEX,
b.type, b.blocks, round(b.bytes/1024/1024,0) mb, b.creation_date, b.modification_date
from (select * from v\$asm_alias order by name) aa,
(select parent_index from v\$asm_alias where group_number = :pindx and alias_index=0) a,
(select * from v\$asm_file where group_number = :pindx) b
where aa.file_number=b.file_number(+)
start with aa.PARENT_INDEX=a.parent_index
connect by prior aa.REFERENCE_INDEX=aa.PARENT_INDEX;
EOF
dispinfo;
fi;
;;
-r)
sqlplus -S '/ as sysasm' << EOF
alter session set nls_date_format='dd.mm.yyyy hh24:mi:ss';
set linesize 200
set pagesize 5000
select dg.name,dg.allocation_unit_size/1024/1024 "AU(Mb)",min(d.free_mb) Min,
max(d.free_mb) Max, round(avg(d.free_mb),2) as Avg
from gv\$asm_disk d, gv\$asm_diskgroup dg
where d.group_number = dg.group_number
group by dg.name, dg.allocation_unit_size/1024/1024;
EOF
dispinfo;
;;
-h)
dispinfo;
;;
*)
sqlplus -S '/ as sysasm' << EOF
set linesize 200
set pagesize 50000
col free_pct format a8
select group_number,name,sector_size,block_size,allocation_unit_size,state,total_mb,free_mb,round(free_mb*100/total_mb)||'%' free_pct from v\$asm_diskgroup;
EOF
dispinfo;
esac

How to logoff RDP Connections in Windows

Please use below commands to log off remote Windows RDP connections.

C:\>query session /server:SERVERNAME
Or
C:\>qwinsta /server:SERVERIP

To Kill a session identified previously:


C:\>reset session 2 /server: SERVERIP
Or
C:\>rwinsta /server: SERVERIP SESSIONID



If you want to see additional information you can run the command above with [/v]
C:\>reset session 2 /server: SERVERIP  /v

Monday, June 10, 2013

RMAN backup details query



RMAN QUERY TO FIND BACKUP DETAILS


RMAN VIEWS (WHEN NO RECOVERY CATALOG AVAILABLE) . i have provide the example as per 11gR2.


To Display the backup details of the database (Full, Incremental & Archive log backup), when the DB is not connect with the recover catalog. (Work in Mount stage)


SQL> select session_key,
input_type,
status,
to_char(start_time,'yyyy-mm-dd hh24:mi') start_time,
to_char(end_time,'yyyy-mm-dd hh24:mi') end_time,
output_bytes_display,
time_taken_display
from v$rman_backup_job_details
order by session_key asc;

Below query will display the backup piece that hold the backup of archive log, datafile in the DISK or TAPE Drive.

Query to see Backed Up Archive Logs in the database (Work in Mount stage)





SQL> select recid,set_stamp,sequence#,first_change#,next_change#

from v$backup_redolog;





Query against the V$BACKUP_PIECE view to find backup details of a particular archive log (Work in Mount stage)





SQL> select r.sequence#, p.handle from v$backup_piece p, v$backup_redolog r

where r.set_stamp = p.set_stamp and r.set_count = p.set_count

and r.sequence# = 63





Note: 63 is the sequence number.

Query against the V$BACKUP_PIECE view to find backup details of a particular datafiles (Work in Mount stage)





SQL> select d.file#, p.handle from v$backup_piece p, v$backup_datafile d where d.set_stamp = p.set_stamp and d.set_count = p.set_count and d.file# = 3





Note: 3 is the datafile number.









SQL> select table_name from dict where table_name like 'V$%RMAN%';





TABLE_NAME

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

V$RMAN_BACKUP_JOB_DETAILS

V$RMAN_BACKUP_SUBJOB_DETAILS

V$RMAN_BACKUP_TYPE

V$RMAN_COMPRESSION_ALGORITHM

V$RMAN_CONFIGURATION

V$RMAN_ENCRYPTION_ALGORITHMS

V$RMAN_OUTPUT

V$RMAN_STATUS

8 rows selected.





V$RMAN_BACKUP_JOB_DETAILS è displays details about backup jobs.





V$RMAN_BACKUP_SUBJOB_DETAILS è merges similar operations within an RMAN session into a single row. For example, if there are four BACKUP DATAFILE commands, three RECOVERY COPY OF DATAFILE commands, and one BACKUP RECOVERY AREA command, this view will contain three rows - one each for BACKUP, ROLLFORWARD, and COPY_DISK_TO_TAPE operation.





V$RMAN_BACKUP_TYPEè displays information about RMAN backup types.

SQL> select * from V$RMAN_BACKUP_TYPE;





WEIGHT INPUT_TYPE

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

1 BACKUPSET

2 SPFILE

3 CONTROLFILE

4 ARCHIVELOG

5 DATAFILE INCR

6 DATAFILE FULL

7 DB INCR

8 RECVR AREA

9 DB FULL





V$RMAN_COMPRESSION_ALGORITHM è provides descriptions of supported compression algorithms. It is used by the RMAN client.





V$RMAN_CONFIGURATION è Information about RMAN persistent configuration settings.





V$RMAN_ENCRYPTION_ALGORITHMS è displays supported encryption algorithms. It is used by the RMAN client to validate user-requested algorithms. This view will list AES128, AES192, and AES256 encryption algorithms for the current release. The default algorithm is AES128.





V$RMAN_OUTPUT è displays messages reported by RMAN. This is an in-memory view and is not recorded in the controlfile. The view can hold 32768 rows.





V$RMAN_STATUS è displays the finished and on-going RMAN jobs. For on-going jobs, this view displays progress and status. The jobs which are in progress are stored only in memory while the finished jobs are stored in the controlfile