Saturday, March 7, 2015

Difference Between Delete,Truncate & Drop


DELETE
1. DELETE is a DML Command.
2. DELETE statement is executed using a row lock, each row in the table is locked for deletion.
3. We can specify filters in where clause
4. It deletes specified data if where condition exists.
5. Delete activates a trigger because the operation are logged individually.
6. Slower than truncate because, it keeps logs.
7. Rollback is possible.
8. Delete command does not resets the High Water Mark for the table.

For Example:

SQL> SELECT COUNT(*) FROM emp;

  COUNT(*)
----------
        14

SQL> DELETE FROM emp WHERE job = 'CLERK';

4 rows deleted.

SQL> COMMIT;

Commit complete.

SQL> SELECT COUNT(*) FROM emp;

  COUNT(*)
----------
        10

TRUNCATE
1. TRUNCATE is a DDL command.
2. TRUNCATE TABLE always locks the table and page but not each row.
3. Cannot use Where Condition.
4. It Removes all the data.
5. TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions.
6. Faster in performance wise, because it doesn't keep any logs.
7. Rollback is not possible.
8. TRUNCATE command resets the High Water Mark for the table.

For Example

SQL> TRUNCATE TABLE emp;

Table truncated.

SQL> SELECT COUNT(*) FROM emp;

  COUNT(*)
----------
         0

DROP

1.DROP command is a DDL command.
2.It removes the information along with structure.
3.It also removes all information about the table from data dictionary.
4.All the tables' rows, indexes and privileges will also be removed.
5.No DML triggers will be fired.
6.rolled back is not possible.

For Example:

SQL> DROP TABLE emp;

Table dropped.

SQL> SELECT * FROM emp;
SELECT * FROM emp
              *
ERROR at line 1:
ORA-00942: table or view does not exist



Wednesday, March 4, 2015

Difference between Traditional Exp/Imp and Datapump(Expdp/Impdp)

Difference between Traditional Exp/Imp and Datapump(Expdp/Impdp).

There are a lots of different between old traditional utlity and expdp. Below are main difference----

1-Datapump operates on a group of files called dump file sets. However, normal export operates on a single file.

2-Datapump access files in the server (using ORACLE directories). Traditional export can access files in client and server both
(not using ORACLE directories).

3-Exports (exp/imp) represent database metadata information as DDLs in the dump file, but in datapump, it represents in XML document format.

4-Datapump has parallel execution but in exp/imp single stream execution.

5-Datapump does not support sequential media like tapes, but traditional export supports.

6-Impdp/Expdp use parallel execution rather than a single stream of execution, for improved performance.

7-Data Pump will recreate the user, whereas the old imp utility required the DBA to create the user ID before importing.

8-In Data Pump, we can stop and restart the jobs.

9-Expdp/Impdp consume more undo tablespace than original Export and Import.

10.Data Pump does not use the BUFFERS parameter.

Tuesday, March 3, 2015

Oracle Background Processes



Oracle Background Processes

Here are some of the most important Oracle background processes:
 Not all background processes are mandatory for an instance.
 Some are mandatory and some are optional. Mandatory background processes are DBWn, LGWR, CKPT, SMON, PMON.


1.Database Writer (DBWR)  

Database Writer or Dirty Buffer Writer process is responsible for writing dirty buffers from the database block cache to the database data files.
Oracle Database allows a maximum of 20 database writer processes.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.

2. Log Writer (LGWR)  
 
The Log Writer process (LGWR) writes the redo log buffer to a redo log file on disk. LGWR is an Oracle background process responsible for redo log
buffer management.
LGWR writes all redo entries that have been copied into the buffer since the last time it wrote.In RAC, each RAC instance has its own LGWR process
that maintains that instances thread of redo logs.

3. Checkpoint (CKPT) 

Checkpoint is an internal mechanism of oracle. When a checkpoint occurs the latest SCN is written to the control file and to all datafile headers.
This operation is performed by the checkpoint process.

Main Purposes--
1- To establish a data consistency.
2- Enable faster database recovery.

4.System Monitor (SMON)

The System Monitor process (SMON)performs instance recovery at instance start up. SMON is also responsible for cleaning up temporary segments that
are no longer in use; it also coalesces contiguous free extents to make larger blocks of free space available .It is also responsible for
roll back and roll forward.

5.Process Monitor (PMON)

The Process Monitor (PMON) performs process recovery when a user process fails. PMON is responsible for cleaning up the cache and freeing resources
that the process was using.
For example, it resets the status of the active transaction table, releases locks, and removes the process ID from the list of active processes.

Optional Background Processes

6. Archiver (ARCn)
The optional Archive process writes filled redo logs to the archive log locations. ARCn is present only if the database is running  in archive log mode and automatic archiving is enabled.





Monday, March 2, 2015

How to drop database


Simple Step-

In 10g onwards dropping a database is very easy. Earlier in order to drop a database it was required to manually
remove all the datafiles, control files,redo logfiles and init,password file etc but with oracle 10g dropping a database is a single command.

In order to drop the database start the database in restrict mode and bring it in mount state as shown:

1. Logging into db
sqlplus / as sysdba

2.SQL> shutdown immediate;
oracle database closed
oracle database dismounted
oracle instance shutdown

3.SQL> startup restrict mount;

4.SQL> drop database;

Database dropped

5.SQL> exit

Thus we will find all files are deleted.

Sunday, March 1, 2015

What is difference between physical and Logical Standby

What is difference between physical and Logical Standby

Physical Standby:
============

1. Physical standby schema matches exactly the source database.

2-Provides a physically identical copy of the primary database, with on disk database structures that are identical to the primary database
on a block-for-block basis.

3- The database schema, including indexes, are the same.

4-A physical standby database is kept synchronized with the primary database by recovering
 the redo data received from the primary database.

5-High availability solutions Or disaster recovery Solution.

6-It is open Mount Stage.

Logical Standby:
===========

1 Logical standby database does not have to match the schema structure of the source database.

2 Logical standby database can be used concurrently for data protection, reporting, and database upgrades.

3 This Kind Of Configuration can be Opened in Read Only Mode .

4 Can have additional materialized views and indexes added for faster performance

5 Logical standby tables can be open for SQL queries (read only), and all other standby tables can be open for updates.

6 This allows users to access a logical standby database for queries and reporting purposes at any time.



How to change the protection mode

Protection modes in Data Guard
  There are three protection modes in Data Guard: Maximum protection, maximum availability and Maximum performance .
  The protection mode can be determined by the protection_mode (and protection_level) column in v$database. 


Changing the protection mode
alter database set standby database to maximize [protection|availability|performance]

Oracle Data Guard - Protection Modes

Introduction
When using an Oracle standby database for Business Continuity purposes there are 3 possible modes of
 operation for determining how the data is sent from the primary (the database currently being used to
 support the business queries) database to the standby (fail over database to be used upon invocation of business continuity) database.

1-Maximum Performance
2-Maximum Protection
3-Maximum Availability


1-Maximum Performance Mode---

This performance mode provides the highest level of data protection that is possible without affecting the performance of a primary database.
This is accomplished by allowing transactions to commit as soon as all redo data generated by those transactions has been written to the on line log.
Redo data is also written to one or more standby databases, but this is done asynchronously with respect to transaction commitment,
 so primary database performance is unaffected by delays in writing redo data to the standby database(s).
This protection mode offers slightly less data protection than maximum availability mode and has minimal impact on primary database performance.
This is the default protection mode.

2-Maximum Protection
This protection mode guarantees that no data loss will occur if the primary database fails.
 To provide this level of protection, the redo data needed to recover each transaction must be written to both the local online redo log and
 to the standby redo log on at least one standby database before the transaction commits. To ensure data loss cannot occur, the primary database
 shuts down if a fault prevents it from writing its redo stream to at least one remote standby redo log.

3- Maximum Availability
This protection mode provides the highest level of data protection that is possible without compromising the availability of a primary database.
Transactions do not commit until all redo data needed to recover those transactions has been written to the online redo log and to at least one
synchronized standby database.

This mode ensures that no data loss will occur if the primary database fails, but only if a second fault does not prevent a complete set of redo data from being sent from the primary database to at least one standby database

How to create user in MY SQL

Create  a new MySQL user Account mysql > CREATE USER ' newuser '@'localhost' IDENTIFIED BY ' password '...