Monday, December 19, 2011

What is High Water Mark in Oracle?

 

The high water mark level is just a line separate the used blocks and free blocks.

The blocks above the HWM level is free blocks, they are ready to use.
The blocks below the HWM level is used blocks, they are already used.

For example'

if you delete some huge records from the database, that data will delete but the blocks are not ready to used, because that blocks are still below HWM level, so delete command never reset the HWM level,

At the same time you truncate the date, then the data will delete and that used blocks will goto above the HWM level, now its ready to used. now they consider has free blocks.

with 10g there are two different HWM for a table


After deleting rows high water mark remain same, what will happen if i insert new rows now.where these new rows will be stored? above the HWM or below?
The space freed by deletions is available for new insertions, so it will be below, until this free space is filled.
Otherwise; Above the HWM when using the APPEND hint in the INSERT statement (or using DIRECT=Y in sql*loader)

They will remain under the HWM until the object is rebuilt, truncated, or shrunk (shrinking of a segment is a new Oracle 10g feature that is supported only if the segment is in an ASSM tablespace).

Thursday, December 08, 2011

How to find Primary Key of a table

 

SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
FROM all_constraints cons, all_cons_columns cols
WHERE cols.table_name = 'TABLENAME'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cols.owner = 'sivaora'
AND cons.owner = 'sivaora'
ORDER BY cols.table_name, cols.position


This can be useful when getting error
ORA-00001: unique constraint (constraint_name) violated

Wednesday, December 07, 2011

ORA-00955: name is already used by an existing object


Cause:
An attempt was made to create a database object (such as a table, view, cluster, index, or synonym) that already exists. A user's database objects must have distinct names.

Action: Enter a unique name for the database object or modify or drop the existing object so it can be reused.

Cross verify to find the existing object by the given name

SELECT   *
  FROM   ALL_OBJECTS
where Object_name like '%obj_name%'

Friday, October 28, 2011

HP-UX DOSKEY equivalent functionality

 

To use the DOSKEY functionality on the HP-UX, in your environment or execute on terminal

Code:

set -o vi

Then you hit escape then with 'k' and 'j' scroll commands (up and down ,like in vi editor).

Then you can use the keystroke sequence <esc>/k to present the last command typed for editing. Move backwards or forwards through the command history using the "-" or "+" keys respectively. If you find a command you want to edit, type "v" which will invoke "vi". Then after editing, use the usual ":wq!" to exit vi and the edited command will execute.

Tip: If you decide to not execute any command (edited or not), blank the command in vi (eg. the "dd" vi command) and then ":wq!".

Friday, October 14, 2011

Moving Data files Between ASM Disk Groups

 

Method 1: Using RMAN

Step 1: Start RMAN and connect to the target database.

$ rman target /

Step 2: Generate a report that shows the names of the datafiles.

RMAN> REPORT SCHEMA;

Step 3:  Back up the datafile to the new ASM disk group.

RMAN> BACKUP AS COPY DATAFILE '+DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421' FORMAT '+DG_DEVSYS_mydb1_DATA_01';

Step 4:  Bring the Datafile Offline
alter database datafile '+DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421' offline

Step 5: Point the control file to the newly created copy of the datafile

RMAN> SWITCH DATAFILE '+DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421' TO COPY;

Step 6:  Recover the renamed datafile
RMAN> recover datafile '+DG_DEVSYS_mydb1_DATA_01/mydb1/datafile/data01.272.764459767';

Step 7. Bring the datafile online.
alter database datafile '+DG_DEVSYS_mydb1_DATA_01/mydb1/datafile/data01.272.764459767' online

Step 8. Delete the old datafile
RMAN>DELETE DATAFILECOPY “DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421”

Reference: http://download.oracle.com/docs/cd/B28359_01/backup.111/b28270/rcmasmmi.htm

Method 2: Using ASMCMD CP ( Copy ) Command

Step 1: Start RMAN and connect to the target database.

$ rman target /

Step 2: Generate a report that shows the names of the datafiles.

RMAN> REPORT SCHEMA;

Step 3:  Bring the Datafile Offline
alter database datafile '+DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421' offline

Step 4:  Connect to ASMCMD and use CP to copy files
$ asmcmd –p

ASMCMD [+] > cp +DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421 +DG_DEVSYS_mydb1_DATA_01

Step 5:  After copied datafile, then rename file in database.  With ASM(OMF) this delete old datafile.

alter database rename file '+DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421'  to '+DG_DEVSYS_mydb1_DATA_01/mydb1/datafile/data01.272.764459767'

Step 6:  Recover the renamed datafile
RMAN> recover datafile '+DG_DEVSYS_mydb1_DATA_01/mydb1/datafile/data01.272.764459767';

Step 7. Bring the datafile online.
alter database datafile '+DG_DEVSYS_mydb1_DATA_01/mydb1/datafile/data01.272.764459767' online

Step 8: Verify the file name
RMAN> REPORT SCHEMA


Method 3:  Using RMAN Copy

Step 1:  Restrict the Session
ALTER SYSTEM enable restricted session;

Step 2:   Bring the Datafile Offline

alter database datafile '+DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421' offline

Step 3: Start RMAN and connect to the target database.

$ rman target /

Step 4:  RMAN Copy datafile
RMAN> copy datafile '+DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421' to '+DG_DEVSYS_mydb1_DATA_01';

Step 5:  After copied datafile, then rename file in database.  With ASM(OMF) this delete old datafile.

alter database rename file '+DG_DEVSYS_mydb1_FLASH_01/mydb1/datafile/data01.290.709985421'  to '+DG_DEVSYS_mydb1_DATA_01/mydb1/datafile/data01.272.764459767'

Step 6:  Recover the renamed datafile
RMAN> recover datafile '+DG_DEVSYS_mydb1_DATA_01/mydb1/datafile/data01.272.764459767';

Step 7. Bring the datafile online.
alter database datafile '+DG_DEVSYS_mydb1_DATA_01/mydb1/datafile/data01.272.764459767' online


Step 8: Verify the file name
RMAN> REPORT SCHEMA

Step 9: Disable the Restricted Session

ALTER SYSTEM disable restricted session;

Thursday, October 06, 2011

ORA-38729: Not enough flashback database log data to do FLASHBACK.

Just check the oldest flashback time available>

select oldest_flashback_time from v$flashback_database_log;

Cause:

We need to have the required archive logs in the archive destination at the time of flashback.

Like, there could be a  backup script is archiving all the archivelogs and purging it from the ASM, hence, we cannot flashback with the error that it cannot locate the log files.
 
Resolution:
 
That is, if the flashback database command does not work in SQLPlus because a needed archive log was deleted after an RMAN backup, execute the flashback database command from RMAN. RMAN will flashback the database, restore the missing archive log(s) and apply the logs as needed.

Then 'alter database open resetlogs ;' is executed after the flashback database as normal.

 

Ref: https://support.oracle.com Document ID 560686.1.

Wednesday, October 05, 2011

OEM Collection Status : Disabled by Upload Manager

 

oracle@DBSRVR1:/app/oracle/product/11g/db_1/network/admin $ oemagent status
Oracle Enterprise Manager 11g Release 1 Grid Control 11.1.0.1.0
Copyright (c) 1996, 2010 Oracle Corporation.  All rights reserved.
---------------------------------------------------------------
Agent Version     : 11.1.0.1.0
OMS Version       : 11.1.0.1.0
Protocol Version  : 11.1.0.0.0
Agent Home        : /app/oracle/product/em/agent11g/DBSRVR1.production.siva.com
Agent binaries    : /app/oracle/product/em/agent11g
Agent Process ID  : 16164
Parent Process ID : 18735
Agent URL         : https://DBSRVR1.production.siva.com:3872/emd/main
Repository URL    : https://GRIDCTLSRVR.siva.com:1159/em/upload
Started at        : 2011-10-03 12:25:14
Started by user   : oracle
Last Reload       : 2011-10-03 12:25:14
Last successful upload                       : 2011-10-05 18:32:35
Total Megabytes of XML files uploaded so far :  1400.06
Number of XML files pending upload           :      390
Size of XML files pending upload(MB)         :    51.97
Available disk space on upload filesystem    :    26.53%
Collection Status                            : Disabled by Upload Manager
Last attempted heartbeat to OMS              : 2011-10-05 20:44:10
Last successful heartbeat to OMS             : 2011-10-05 18:32:15
---------------------------------------------------------------
Agent is Running and Ready

Causes:

  1. There are too many files backlogged
  2. There is not enough free space on the directory
  3. The size of the files backlogged is too large.
  4. It could be of network issue between OEM Agent and OMS Server

Please check the emd.properties file to override the defaults that automatically disable collection

Friday, September 30, 2011

How to monitor ASM Disk group usage on OEM Grid

  1. Connect to OEM
  2. Connect to the Host
  3. From the Host –> Go to Target Tab
    image
  4. From the listed target, select ASM by looking at type as  “Automatic Storage Management
    image

  5. Now select type ASM, then we will be landed at ASM on OEM Grid Control.
  6. On the Home Page of ASM, we can find the Disk group usage
    image
  7. Also from the Home, go to tab Disk Group

    image

Disk group has used % of safely usable free space

OEM Alert Message looks like;

Message=Disk group DISGKGROUP_FLASH_01 has used 75.08% of safely usable free space.
Metric=Disk Group Used % of Safely Usable
Metric value=75.08
Disk Group Name=DISGKGROUP_FLASH_01
Severity=Warning
Target Name=+ASM1_DBSRVR.siva.com
Target type=Automatic Storage Management
Host=dbsrvr.siva.com
Occurred At=Sep 29, 2011 11:14:52 PM IST
Acknowledged=No
Notification Rule Name=DBSrvr ASM Health Check
Notification Rule Owner=DBA

 

By default:
This metric will generate a warning alert if the Disk Group is using 90% of the Safely usable space and
Critical warning for 100 %. Threshold limit can be changed to generate alert at different values.

This metric is collected at a time interval of 15 minutes.

Metric Collection:
This metric is collected from the view V$ASM_DISKGROUP_STAT

Used % of Safely Usable = 100 - (usable_file_mb/usable_total_mb)*100

Where usable_total_mb = total_mb - required_mirror_free_mb)/redundancy_factor

total_mb and required_mirror_free_mb will come from the V$ASM_DISKGROUP_STAT  view column and

Redundancy Factor Disk Group Type
1 External
2 Normal
3 High

Query:

 select 100-(FREE_MB/TOTAL_MB)*100 as "Used % Safely Usable Area",  Name from v$asm_diskgroup_stat

Alternatively connect to ASM and check the free space;

ASMCMD> lsdg


Workaround:
If the Archive Log file occupies the ASM Disk group, move the files or delete files to free up Disk group.

Permanent Resolution:
New disks can be added in a disk group to avoid the alerts.
Go to the Disk Group general page ---> and click on add button to add a new disk to a disk group.

Friday, September 23, 2011

find: missing conjunction

$  find . -type d –name siva*

Resolution:  Use single quote on the string in –name clause

Ex:   $  find . -type d –name ‘siva*’

How to find the open mode status of database?

Option 1:

select status from v$instance;

Option 2:

select open_mode from v$database;


Option 3:

Search Alert Log for string of “Database” or “alter database”.

How to generate AWR Report?

Method 1:  By Querying

1. Query dba_hist_snapshot to find the snap id for the interval you are looking for.

SELECT dbid, snap_id, begin_interval_time, end_interval_time from dba_hist_snapshot
order by begin_interval_time;

2.

spool siv_awr_201109.lst
SELECT output
FROM TABLE (dbms_workload_repository.awr_report_text(3463084831, 1, 18048, 18050));
spool off

Method 2:

@?/rdbms/admin/awrrpt.sql

It is an interactive script that can be used to generate HTML or text reports. The script prompts for type of report
requested and prompts for number of days of snapshots to choose from so based on that it displays snap ids to
choose the start and end snapshot it.

@?/rdbms/admin/awrrpti.sql

Script can be used for the specified database and instance so the script in addition will prompt for dbid and instance number.
@?/rdbms/admin/awrddrpt.sql Script can be used to generate a combine report of 2 different snapshots for comparison of performance in one report so it will prompt for two pairs of snapshot snapshots to compare against.
@?/rdbms/admin/awrinfo.sql Script print AWR information like space usage by AWR, subset of AWR snap ids, Automatic Database Diagnostic Monitor (ADDM), Active Session History (ASH) information.

Saturday, September 17, 2011

Sequence of steps performed when opening up a database

After issuing of SHUTDOWN ABORT command, when opening up database following step are performed

1. SPFile / PFile:             Server Parameter file ( SP File ) or the initialization parameter (initSID.ora / PFILE ) file is read
2. Memory :                      SGA is allocated
3. Background Process: Background process are started
4. Control File :                Control file is read
5. Redo Log File:              Redo Log file is read
6. Data File:                       Data files are checked for consistency
7. Instance Recovery:   Instance Recovery is started

Friday, August 26, 2011

ksh: =: is not an identifier

 

Error:  ksh: =: is not an identifier
-------------------------------------------------------------------------------------------
Cause:  Space between VariableName, = and Value

Resolution: Remove the space betwen Variablename, = and Value

Example

oracle@myDBSrvr1: export ORACLE_HOME = /app/oracle/product/11g/db_1
ksh: =: is not an identifier
oracle@myDBSrvr1: export ORACLE_HOME=/app/oracle/product/11g/db_1

ORA-00235 controlfile fixed table inconsistent due to concurrent update


Error: controlfile fixed table inconsistent due to concurrent update


Cause: Concurrent update activity on a controlfile caused a query on a controlfile fixed table to read inconsistent information.

Action: Retry the operation.


Reference:  Oracle Support [ID 48816.1]

OEM Grid Agent command to list it’s targets


Here is the command to find the target of an OEM Agent.

./emctl config agent listtargets

Here is the example of the command

oracle@dbsrvr1:/app/oracle/product/em/agent11g/bin $ ./emctl config agent listtargets
Oracle Enterprise Manager 11g Release 1 Grid Control 11.1.0.1.0
Copyright (c) 1996, 2010 Oracle Corporation.  All rights reserved.
[dbsrvr1.production.dorvin.org:3872, oracle_emd]
[usrncwd, cluster]
[LIS_RCATP_01_dbsrvr1.production.dorvin.org, oracle_listener]
[LISTENER_dbsrvr1_dbsrvr1.production.dorvin.org, oracle_listener]
[pla31p.dorvin_pla31p1, oracle_database]
[son49p.dorvin, rac_database]
[+ASM1_dbsrvr1.production.dorvin.org, osm_instance]
[dbsrvr1.production.dorvin.org, host]
[rcatp.dorvin, oracle_database]

Sunday, August 21, 2011

ORA-16037: user requested cancel of managed recovery operation

 

Cause:
The managed standby database recovery operation has been canceled per user request.

Option 1:

When the command alter database recover managed standby database cancel issued

Option 2:

When the Primary database of Dataguard got shutdown.

Resolution:
           No action needed

Monday, August 08, 2011

How to find the Master node in RAC

 

The command is oracle@DB_Node2:/home/oracle $ ocrconfig –showbackup
Since, the OCR Automatic backups are taken only by master node. We can verify with following command.


DB_Node1     2011/08/07 22:50:25     /app/crs/product/11g/cdata/PRDDB_cluster/backup00.ocr
DB_Node1     2011/08/07 18:50:24     /app/crs/product/11g/cdata/PRDDB_cluster/backup01.ocr
DB_Node1     2011/08/07 14:50:24     /app/crs/product/11g/cdata/PRDDB_cluster/backup02.ocr
DB_Node1     2011/08/06 06:50:16     /app/crs/product/11g/cdata/PRDDB_cluster/day.ocr
DB_Node1     2011/07/26 06:48:45     /app/crs/product/11g/cdata/PRDDB_cluster/week.ocr

Here the Master node is DB_Node1

Monday, August 01, 2011

EM Alert: target is broken, Suspended on Agent Unreachable


Error: EM Alert:Suspended on Agent Unreachable

Diagnosis
/app/oracle/product/em/agent11g/sysman/log/emagent.log

2011-07-27 16:12:34,737 Thread-4083678112 target {CLUSTERNAME, cluster} is broken: cannot compute dynamic properties in time. (00155)
2011-07-27 16:12:37,342 Thread-4099427232 target {+ASM1_nodename02.domain.com, osm_instance} is broken: cannot compute dynamic properties in time. (00155)
2011-07-27 16:14:04,597 Thread-4093127584 target {RACDB.DOMAIN.COM, rac_database} is broken: cannot compute dynamic properties in time. (00155)

/app/oracle/product/em/agent11g/sysman/log/emagent.trc

2011-07-29 12:03:35,253 Thread-3985230752 ERROR upload: 1 Failure(s) in a row or XML error for C0002000.xml, retcode = -2, we give up
2011-07-29 12:03:48,271 Thread-4035967904 ERROR pingManager: Did not receive valid response to ping "ERROR-Loader/Receiver disabled on this OMS"
2011-07-29 12:03:48,359 Thread-4035967904 ERROR pingManager: Did not receive valid response to ping "ERROR-Loader/Receiver disabled on this OMS"
2011-07-29 12:05:18,641 Thread-3994700704 ERROR pingManager: Did not receive valid response to ping "ERROR-Loader/Receiver disabled on this OMS"
2011-07-29 12:06:18,875 Thread-3985230752 ERROR pingManager: Did not receive valid response to ping "ERROR-Loader/Receiver disabled on this OMS"
2011-07-29 12:08:36,023 Thread-3985230752 WARN upload: FxferSend: received http error in header from repository: https://em.domain.com:1159/em/upload
ERROR-300|Loader/Receiver disabled on this OMS
2011-07-29 12:08:36,024 Thread-3985230752 ERROR upload: Failed to upload file C0002002.xml: HTTP error.
Response received: ERROR-300|Loader/Receiver disabled on this OMS
2011-07-29 12:08:36,175 Thread-3985230752 WARN upload: FxferSend: received http error in header from repository: https://em.domain.com:1159/em/upload
ERROR-300|Loader/Receiver disabled on this OMS


Solution:

Click the configure button and go through the steps without making any changes.

Target {database instance, oracle_database} is broken: cannot compute dynamic properties in time [ID 739993.1] which advised to change the dynamicPropsComputeTimeout property in the emd.properties

Thursday, July 28, 2011

How to find what Shell being used on the server

 

siva@mydbsrvr1:/home/oracle $ echo $SHELL
/usr/bin/ksh


You can find out what shell you are using by the command: echo $SHELL

Environment Variables in Unix
By prefixing $ to the variable name, you can evaluate it in any command