Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

Thursday, June 5, 2014

Sharing a script that logs all long running queries, kills them :) and sends out an email alert to my inbox. I generally modify it according to the production requirement. In my environment there are a couple of production servers where I would setup this script to only alert and Not kill any query.
Please double test before implementing in realtime production environment.Follow the general thumb rule to implement all changes/scripts from lower to higher env. :) this script comes with disclaimer that person using has complete ownership for it’s results.
Ensure postfix installed and configured for emails to work. The script works for postgre user since postgre has privs over all databases in the server
############################
if [ `whoami` != "postgres" ]; then
exit 0;
fi
# selecting non-idle queries which are running since at least 6 minutes.
psql -c "select pid, client_addr, query_start, current_query from pg_stat_activity
where current_query != '<IDLE>' and current_query != 'COPY' and current_query != 'VACUUM' and query_start + '6 min'::interval < now()
and substring(current_query, 1, 11) != 'autovacuum:'
order by query_start desc" > $LOGFILE
NUMBER_OF_STUCK_QUERIES=`cat $LOGFILE | grep "([0-9]* row[s]*)" | sed 's/(//' | awk '{ print $1}'`
if [ $NUMBER_OF_STUCK_QUERIES != 0 ]; then
# Getting the first column from the output discarding alphfanumeric values (table elements in psql's output).
STUCK_PIDS=`cat $LOGFILE | sed "s/([0-9]* row[s]*)//" | awk '{ print $1 }' | sed "s/[^0-9]//g"`
for PID in $STUCK_PIDS; do
echo -n "Cancelling PID $PID ... " >> $LOGFILE

# "t" means the query is successfully cancelled.
SUCCESS=`psql -c "SELECT pg_cancel_backend($PID);" | grep " t"`
if [ $SUCCESS ]; then
SUCCESS="OK.";
else
SUCCESS="Failed.";
fi
echo $SUCCESS >> $LOGFILE
done

cat $LOGFILE | mail -s "Stuck PLpgSQL processes detected and killed that were running over 6 minutes." youremail@whatever.com;

fi

rm $LOGFILE
#######################################


Wednesday, August 31, 2011

What is Oracle GoldenGate?


I was looking for a short & crisp answer to the question what is Oracle Golden Gate which could be called a defination of the product as well.

Oracle GoldenGate replication technology that’s now part of the Oracle framework, is a high-performance software application for real-time transactional change data capture, transformation, and delivery, offering log-based bidirectional data replication. The application enables you to ensure that your critical systems are operational 24/7, and the associated data is distributed across the enterprise to optimize decision-making.
Oracle GoldenGate filled a gap which we did not have - heterogeneous replication, replication from Oracle to different databases and vice versa.Oracle Goldengate can be used as a replication tool, ETL, and even as a DR solution.One can move data between similar or dissimilar supported Oracle versions, or one can move data between an Oracle database and a database of another type. GoldenGate supports the filtering, mapping, and transformation of data.

Sunday, June 26, 2011

Basic Properties of a Database Transaction ( Part 2)

Oracle enforces ACID by means of Undo Segments & Redo Logs.
Undo Segments help enforce-- atomicity and consistency .
Isolation requires undo segments & locks.
Durability is enforced with redo logs.

Oracle provides the following transaction isolation levels.
Read committed
Default transaction level is Read Committed.
Each query executed will only see the committed data. In other words an Oracle query will never read uncommitted data.
Serializable
Serializable transactions can only see those changes that were committed at the time the transaction began and those changes that are being made by the transaction itself.
Read-only
Read-only transactions see only those changes that were committed at the time the transaction began

Isolation levels can be set at the begining of the transaction and at session level.
Commands for transaction level setting of isolation.
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SET TRANSACTION READ ONLY;

Commands for session level setting;
ALTER SESSION SET ISOLATION_LEVEL SERIALIZABLE;
ALTER SESSION SET ISOLATION_LEVEL READ COMMITTED;

Thursday, June 23, 2011

Basic Properties of a database Transaction (Part 1)

Basic properties of any databse transaction should be Atomicity, Consistency, Isolation, and Durability.
In short referred to as ACID.
All Oracle database transactions are ACID complaint . However, I believe that Oracle's Berkeley DB database is not ACID-compliant.
I need to research more on this statement though.
In short ACID refers to:
Atomicity
The entire sequence of actions must be either completed or aborted. The transaction cannot be partially successful.
Consistency
The transaction takes the resources from one consistent state to another.
Isolation
A transaction's effect is not visible to other transactions until the transaction is committed.
Durability
Changes made by the committed transaction are permanent and must survive system failure.

Monday, March 7, 2011

Logical Standby SQL apply not re-starting

Errors ORA-00604 & ORA-01425 while restarting SQL apply for logical standby.
When one starts the SQL apply on the database...
SQL>Alter database start logical standby apply immediate;  
Database altered 
Oracle starts the SQL apply but subsequently it fails. In the alert log one would find the following errors..
Errors detected in process 16, role LOGICAL STANDBY COORDINATOR.  
krvsqn2s: unhandled failure 604:  
ORA-00604: error occurred at recursive SQL level 1  
ORA-01425: escape character must be character string of length 1  
There would be an associated trace file, which would show...
*** SERVICE NAME:(SYS$BACKGROUND) 2011-03-08 12:21:04.572  
*** SESSION ID:(632.180) 2011-03-08 12:21:04.572  
ORA-00604: error occurred at recursive SQL level 1  
ORA-01425: escape character must be character string of length 1  
knahcapplymain: encountered error=604  
*** 2011-03-08 12:21:04.619  
ksedmp: internal or fatal error  
ORA-00604: error occurred at recursive SQL level 1  
ORA-01425: escape character must be character string of length 1  
This is due to a Bug: 5108158 which is fixed in Oracle11g. Well!! I have heard that this is when we set logical standby to skip some schemas. Anyhow, this was not the case in our standby database neither could I find this skip schemas reason documented by Oracle !! :)
There is a workaround which would get the SQL apply to re-start. The workaround is documented in metalink 748208.1
SQL>--Ensure SQL apply is stopped  
SQL> Alter database stop logical standby apply;  
SQL>set echo on   
SQL>set pagesize 100   
SQL>spool workaround.log   
SQL>select * from system.logstdby$skip;   
SQL>select distinct nvl(esc, 'NULL') from system.logstdby$skip;   
SQL>select * from system.logstdby$skip where esc is null;   
SQL>update system.logstdby$skip set esc = '\'  where esc is NULL;  
-- Following should return no rows (due to update above)   
SQL>select * from system.logstdby$skip where esc is null;   
-- should no longer see any NULL in output   
SQL>select distinct nvl(esc, 'NULL') from system.logstdby$skip;   
-- Capture a snapshot of the final results   
SQL>select * from system.logstdby$skip;   
-- commit changes   
SQL>commit;   
--Restart the SQL apply and check the alert log.  
SQL> Alter database start logical standby apply immediate;  
SQL>Spool Off;  
In case, still SQL apply does not start, then immediately contact oracle support.

Sunday, January 9, 2011

Oracle data guard – new additions in 10R2

Oracle Data Guard has improved functionality over last releases, which is hitting the point home that Oracle is serious about it’s view of making administration so easy that a child can handle it.
Hmm….. Mediocre DBA’s better start looking for another professional line.

In 10g release 2, Oracle data guard broker new features are:
·         Fast-Start Failover
DG broker can automatically fail over to a previously chosen standby database in the event of a loss of primary database. This would not require any manual steps. Moreover Oracle 10gR2 claims that the former primary database is automatically re-instated as a standby database in the new broker configuration when a connection to it is re-established.
I would test this rigorsly in my environment. Database is never a standalone in any production environment and lots of other connections and application requirements would be involved in case of an automatic failover. I would seek answers more towards the applications and environment requirements before using this feature.

·         Re-instatement of the primary database to a standby database after a failover

Oracle claims that the data guard observer can reinstate the former primary database as a standby database. Oracle documentation states “Reinstatement restores high availability to the broker configuration so that, in the event of a failure of the new primary database, another fast-start failover can occur….”

Currently, this feature has too many limitations making it highly unusable in actual production environment. In Oracle 11g this feature seems to have enhanced.

·         Data Guard enhancements in OEM grid control
Oracle 10g Data Guard broker features are only available in Enterprise Manager grid Control. So, one must install OEM grid control to ba able to access the data guard functionality.
Ø  Compression of backups during standby creation
Ø  Support for flash recovery area for physical standby databases
Ø  Support of standby databases in an Oracle Managed Files (OMF) or Automatic
Storage Management (ASM) configuration
Ø  New and improved apply statistics
Ø  Status alerts for non-broker configurations
Ø  Test redo generator

Monday, January 3, 2011

Oracle dynamic view -- more than 20 mins data lost!!

An interesting question was asked in an interview for DBA and the person started this discussion about V$ views as they are popularly called.
I still prefer to call them by their actual name i.e. Oracle’s dynamic performance views. The behavior and the data expected gets more clear through it's name. These views ONLY have data or information about the instance and hence on reboot or restart of an instance the data would be refreshed and old information would be lost.
The question was rephrased in an interview and asked as a scenario... " In oracle database the information in oracle dynamic view (not dba_ view) more than 20 minutes got lost, what is the reason to result in this? How do you get the information in dynamic view more than 20 minutes?"
I saw people give the answer as recover the database to to the point in time required OR refresh the view, totally way off the mark!!
The dynamic performance views show statistics for the entire instance since the time it was started. So, if the info older than 20 mins is gone, would it would mean that the instance had been restarted 20 mins earlier. 
Dynamic performance views have only the current instance statistics. and recovering a database from backup is not going to recover this statistics. Many of these statistics are tied to the internal implementation of Oracle and therefore are subject to change or deletion without notice, even between patch releases. Application developers should be aware of this and write their code to tolerate missing or extra statistics.
Oracle documentation states...
 "V$SYSSTAT stores instance-wide statistics on resource usage, cumulative since the instance was started."

Monday, November 1, 2010

Oracle, SAP Copyright Infringement Case

There is no doubt that the copyright laws are for our benefit.
Having said that this SAP-Oracle battle over how much SAP should pay Oracle for copyright infringement committed does leave a lot unsaid.
8-Person Jury has been choosen which includes an auto mechanic and an accountant who doesn't speak english.
We can expect this trial, as reported by Online Wall Street Journal, to go on for several weeks.
Details: Online Wall Street Journal News

Oracle RAC Background Processes!!

The following are the additional processes spawned for supporting the multi-instance coordination and can be thus called Oracle Real Application cluster background processes(RAC).
DIAG - (Diagnosability Daemon) this process would be responsible for Monitoring the health of the instance and capture the data for instance process failures.
LCKx - This process manages the global enqueue requests and the cross-instance broadcast.  In case of multiple Global Cache Service Processes (LMSx) , one would find that the Workload is automatically shared and balanced.
LMON - provided services are also known as cluster group services (CGS) and LMON particularly handles the recovery associated with globl resources.LMON called as Global Enqueue Service Monitor, monitors the entire cluster to manage the global enqueues and the resources. It is responsible to manage instance and process failures and the associated recovery for the Global Cache Service (GCS) and Global Enqueue Service (GES).
LMDx - Full form is Global Enqueue Service Daemon.It is the lock agent process that manages enqueue manager service requests for Global Cache Service enqueues to control access to global enqueues and resources. The LMD process also handles deadlock detection and remote enqueue requests.These requests are originating from another instance.
LMSx - The Global Cache Service Processes are the processes that handle remote Global Cache Service (GCS) messages. Up to 10 Global Cache Service Processes can be there. The number of the processes varies depending on the amount of messaging traffic among nodes in the cluster. The LMSx handles the acquisition interrupt and blocking interrupt requests from the remote instances for Global Cache Service resources. For cross-instance consistent read requests, the LMSx will create a consistent read version of the block and send it to the requesting instance. The LMSx also controls the flow of messages to remote instances.
It handles the blocking interrupts from the remote instance for the global cache service resources by managing the resource requests & cross-instance call operations for the shared resources.
It is also responsible for building a list of invalid lock elements and validating the lock elements during recovery. It does the Handling of the  global lock deadlock detection and Monitoring for the lock conversion timeouts
To read in bullet form refer:
 http://vibhork.blogspot.com/2010/10/understanding-real-application-cluster.html

Oracle Background Processes!!

Oracle Background Processes can be seen from the view V$SESSION.
I find the below query very informative:

Select SERVER,PROCESS,PROGRAM,STATUS
from v$session
where type ='BACKGROUND';

Listing some of the most important Oracle background processes:

ARCH -Archive process writes filled redo logs to the archive log location(s).
In RAC, the various ARCH processes are utilized to ensure that copies of the archived redo logs for each instance
are available to the other instances in the RAC in case required for recovery.
CJQ - Job Queue Process is Used for the job scheduler.
The job scheduler a coordinator and slave programs that the coordinator executes.
The parameter job_queue_processes controls how many parallel job scheduler jobs can be executed at one time.
CKPT - Checkpoint process writes checkpoint information to control files and data file headers.
CQJ0 - Job queue controller process wakes up periodically  to check the job log for any job's due and accordingly spawns Jnnnn processes to handle jobs.
DBWR - Database Writer or Dirty Buffer Writer process is responsible for writing dirty buffers from the database block cache
to the database data files. Generally, DBWR only writes blocks back to the data files on commit, or when the cache is full and space has to be made for more blocks.  In RAC multiple DBWR processes must be coordinated through the locking and global cache processes to ensure efficient processing.
FMON -  Is a process which spawns external non-Oracle Database process to have the database communicates with the mapping libraries provided by storage vendors. FMON is responsible for managing the mapping information.
The initialization parameter FILE_MAPPING is used for mapping the data files to physical devices on a storage subsystem and would spawn the FMON process.
LGWR - Log Writer process is responsible for writing the log buffers out to the redo logs. Each RAC instance would have its own LGWR process maintaining that instance’s thread of redo logs.
LMON - is the Lock Manager process
MMON - In Oracle 10g MMON is the background process responsible for collecting the statistics for the Automatic Workload Repository.
MMNL - This process performs frequent and lightweight manageability-related tasks, such as session history capture and metrics computation.
MMAN - is used for internal database tasks that manage the automatic shared memory. MMAN serves as the SGA Memory Broker and coordinates the sizing of the memory components.
PMON - is background process responsible for recovering the failed process resources. In a Shared Server Architecture, PMON monitors and restarts any failed dispatcher or server processes. In RAC, PMON also holds the role as service registration agent.
Pnnn - This is an optional process which is used in parallel query operations. Parallel Query Slaves are started and stopped as needed.
RBAL - This process coordinates rebalance activity for disk groups in an Automatic Storage Management instance.
SMON - System Monitor process recovers after instance failure and monitors temporary segments and extents.
In RAC,this process would in a non-failed instance, perform failed instance recovery for other failed RAC instances.
WMON - The "wakeup" monitor process

The following background processes are basically Data Guard/Streams/replication Background processes.

DMON - The Data Guard Broker process.
SNP - The snapshot process.
MRP - is Managed recovery process, which in Data Guard would apply the archived redo log to the standby database.
ORBn - performs the actual rebalance data extent movements in an Automatic Storage Management instance. Multiple number of these can be spawned at a time called ORB0, ORB1...
OSMB - is present in a database instance using an Automatic Storage Management disk group. It communicates with the Automatic Storage Management instance.
RFS -  is Remote File Server process - In Data Guard, this process ( running on the standby database ) would be receiving the archived redo logs from the primary database.
QMN - Queue Monitor Process (QMNn) - Used to manage Oracle Streams Advanced Queuing.

Monday, October 18, 2010

What is Oracle?

This question sent me in a frenzy of searches to try and get the prefect answer.

Oracle , derived from a latin verb, was considered to be a person of wise counsel or prophetic opinion and can be as such referred to as a form of divination.
Refer: http://en.wikipedia.org/wiki/Oracle

Larry Ellison, it says took inspiration from E.F.Codd's 1970 paper written on RDBMS and as we all know, history was created in 1977 in Santa Clara, California by Larry Ellison, Bob Miner and Ed Oates, when they started SDL which is today known as Oracle Corporation.
"Optional Reception of Announcements by Coded Line Electronics"= ORACLE, was a commercial teletext service first broadcast on ITV in 1974.
An early computer built by Oak Ridge National Laboratory, was based on the IAS architecture developed by John von Neumann. This computer was called ORACLE=Oak Ridge Automatic Computer and Logical Engine.
Oracle is an alias used in comics by DC comice character Barbara Gordon. Also name of a model rocket with built-in digital camera.
In 2001, singer Kittie named her second album Oracle.  :-))
          

Monday, September 27, 2010

Oracle's Vision of 21st Century DataCenter

Oracle has made a move into private cloud computing systems. The Exalogic Elastic Cloud was announced at Oracle OpenWorld 2010.
Exalogic is a giant step taken by Oracle for realizing it's 21st Century DataCenter Vision. Oracle has smartly moved forward and strategized it's product portfolio. Both Hardware and Software components have been combined together into an Engineered system called Exalogic.
Oracle is claiming that Oracle Exalogic Elastic Cloud, the world’s first and only integrated middleware machine, dramatically surpasses alternatives and provides enterprises the best possible foundation for running applications.
All are watching what new efficiencies lie ahead!

Title Changed -- reflects my journey

  The title "Evolving Architect: Combining Data, Design, and Project Management" captures my journey as I grow from data-centric e...