Friday, 25 December 2015

Cloning by using cold backups:

Cloning by using cold backups:

ProdDB - amer
CloneDB - amercln

ProdDB Side (amer) :

1. Find datafiles/logfile and pfile locations by issuing the following queries.

select name from v$datafile;
select member from v$logfile;
sho parameter spfile;

2. Shut immediate the prod db and copy these datafiles/logfile and pfile to the other backup location.

Note: If you are using the spfile create the pfile from spfile and copy it to backup location.

3. startup the prod db.

4. Take backup of control file to the backup location by issuing the following command.

SQL> alter database backup controlfile to trace as '/u02/backup/control.ctl';

5. SCP the backup files to target database (amercln) backup location.

scp initamer.ora oracle@192.168.141.11:/u02/amercln/

6. Create password file for the prod db.

orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/orapwAMERCLN password=oracle entries=10

CloneDB Side (amercln):

1. Create required directories in corresponding path and placed the backup files in corresponding directories.

Such as : adump,bdump,cdump,udump,oradata,...

2. Change the initamer.ora name to initamercln.ora

$mv initamer.ora initamercln.ora

3. Change the initamercln.ora parameters such as db_name, contolfile path, instance name, audit file location path, ... so on.

[oracle@euro dbs]$ more initAMERCLN.ora 
amercln.__db_cache_size=276824064
amercln.__java_pool_size=4194304
amercln.__large_pool_size=4194304
amercln.__oracle_base='/u02/app/oracle'#ORACLE_BASE set from environment
amercln.__pga_aggregate_target=314572800
amercln.__sga_target=528482304
amercln.__shared_io_pool_size=0
amercln.__shared_pool_size=234881024
amercln.__streams_pool_size=0
*.audit_file_dest='/u02/app/oracle/admin/amercln/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u02/app/oracle/oradata/amercln/control01.ctl','/u02/app/oracle/oradata/amercln/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='AMERCLN'
*.db_writer_processes=2
*.diagnostic_dest='/u02/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=amerclnXDB)'
*.log_archive_dest='/u02/BackupArea/arch/'
*.log_archive_format='%t_amercln_%s_%r.ARC'
*.memory_target=843055104
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sec_case_sensitive_logon=FALSE
*.undo_tablespace='UNDOTBS1'
[oracle@euro dbs]$ 


4. create password file.

$orapwd file=$ORACLE_HOME/dbs/orapwdamercln password=oracle

Note: Source DB password and clone db password must be same.

5. Change control.sql file as per requirement.

Such as redolog file paths, datafile paths, ...

Change the below highlighted words from REUSE to SET and NORESETLOGS to RESETLOGS. 

FROM: CREATE CONTROLFILE REUSE DATABASE “olddbname” RESETLOGS …
TO: CREATE CONTROLFILE set DATABASE “newdbname” RESETLOGS …

$vi control.sql

STARTUP NOMOUNT
CREATE CONTROLFILE SET DATABASE "AMERCLN" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u02/app/oracle/oradata/amercln/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/u02/app/oracle/oradata/amercln/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/u02/app/oracle/oradata/amercln/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/u02/app/oracle/oradata/amercln/system01.dbf',
  '/u02/app/oracle/oradata/amercln/sysaux01.dbf',
  '/u02/app/oracle/oradata/amercln/undotbs01.dbf',
  '/u02/app/oracle/oradata/amercln/users01.dbf',
  '/u02/app/oracle/oradata/amercln/example01.dbf'
CHARACTER SET WE8MSWIN1252
;
[oracle@euro amercln]$ 

6. open the database amercln with STARTUP NOMOUNT to execute the control.sql file.

$export ORACLE_SID=amercln

$sqlplus "/as sysdba"

SQL> startup nomount pfile=''


SQL>@/u02/amercln/control.sql

control file created.

7. Open the database with resetlog files.

SQL>alter database open resetlogs;

8. Check the database and instance statues (READ WRITE), logfiles, datafiles and controlfiles.

Some work notes:

* TO check CP command progress:

    stat -c "%s" /bin/ls

* To replace the words in vi editor

   :%s/Findword/Replaceword/g

* MEMORY_TARGET Issue:

   #df-k


   #mount -t tmpfs shmfs -o size=10g /dev/shm

All the best...!!!



Wednesday, 23 December 2015

Golden-Gate - Misc


1. How can you see golden errors?

ggsci> VIEW GGSEVT

ggserr.log file

2. What is the default port number for OGG manager process?

7809

3.What are the important files in GG?

GLOBALS, ggserr.log, dirprm, dirrpt, dirtmp,..

Golden-Gate - Troubleshoot

Golden-Gate - Troubleshoot:

How can we report on long running transactions?

The WARNLONGTRANS parameter can be specified with a threshold time that a transaction can be open before Extract writes a warning message to the ggs error log.

Example: WARNLONGTRANS 1h, CHECKINTERVAL 10m


What command can be used to view the checkpoint information for the extract process?

Use the following command to view the extract checkpoint information:

GGSCI> info extract, showch

GGSCI> info extract ext_fin, showch

How is the RESTARTCOLLISION parameter different from HANDLECOLLISIONS?

The RESTARTCOLLISION parameter is used to skip ONE transaction only in as situation when the GG process crashed and performed an operation (INSERT, UPDATE and DELETE) in the database but could not checkpoint the process information to the checkpoint file/table.On recovery it will skip the transaction and AUTOMATICALLY continue to the next operation in the trail file.

When using HANDLECOLLISIONS GG will continue to overwritten and process transactions until the parameter is removed from the parameter files and the processes restarted.

How do you view the data which has been extracted from the redo logs?

The logdump utility is used to open the trail files and look at the actual records that have been extracted from the redo or the archive log files.

What does the RMAN=08147 warning signify when your environment has a GG capture processes configured?

This occurs when the V$ARCHIVED_LOG.NEXT_CHANGE# is greater than the SCN required by the GG capture process and RMAN is trying to delete the archived logs. The RMAN-08147 error is raised when RMAN tries to delete these files.

When the database is open it uses the DBA_CAPTURE values to determine the log files required for mining. However if the database is in the mount state the V$ARCHIVED_LOG.NEXT_CHANGE# value is used.

See metaling note: 1581365.1

How would you look at a trail file using logdump, if the trail file is Encrypted?

You must use the DECRYPT option before viewing data in the trail data.

List few useful logdump commands to view and search data stored in OGG trail files.

Below are few logdump commands used on a daily basis for displaying or analysing data stored in a trail file.
 
$ ./logdump – to connect to the logdump prompt
logdump> open /u01/app/oracle/dirdat/et000001 – to open a trail file in logdump
logdump> fileheader on – to view the trail file header
logdump> ghdr on – to view the record header with data
logdump> detail on – to view column information
logdump> detail data – to display HEX and ASCII data values to the column list
logdump> reclen 200 – to control how much record data is displayed
logdump> pos 0 – To go to the first record
logdump> next (or simply n) – to move from one record to another in sequence
logdump> count – counting records in a trail

Golden-Gate - Performance

Golden Gate - Performance:

List a few parameters which may help improve the replicat performance?

The parameters below can be used to improve the replicat performance:

  • BATCHSQL
  • GROUPTRANSOPS
  • INSERTAPPEND
What are the areas to monitor in GG Replication?

The Lag and Checkpoint latency of the Extract, Pump and Replicat processes are normally monitored.

What is the PASSTHRU mode used for?

In Pass-through mode, the extract process does not look up the table definitions, either from the database or from a data definitions file. This increase the throughput of the data pump, as the object definition look-up is bypassed.


What are the most common reasons of an Extract process slowing down?

Some of the possible reasons are:
  • Long running batch transactions on a table.
  • Insufficient memory on the Extract side. Uncommited, long running transactions can cause writing of a transaction to a temporary area (dirtmp) on disk. Once the transaction is committed it is read from the temporary location on the file system and converted to trail files.
  • Slow or overburdened network.
What are the most common reasons of the Replicat process slowing down?

Some of the possible reasons are:
  • Large amount of transactions on a particular table.
  • Blocking sessions on the destination database where non-goldengate transactions are also taking place on the same table as the replicat processing.
  • If using DBFS, writing & reading of trail files may be slow if SGA parameters are not tuned.
  • For slow replicat's, latency may be due to missing indexes on target.
  • Replicat having to process update, delete of rows in very large tables.

My extract was running fine for a long time. All of a sudden it went down. I started the extract processes after 1 hour. What will happen to my committed transactions that occurred in the database during last 1 hour?

OGG checkpoint provides the fault tolerance and make sure that the transaction marked for committed is capture and captured only once. Even if the extract went down abnormally, when you start the process again it reads the checkpoint file to provide the read consistency and transaction recovery.

I have configured Oracle GoldenGate integrated capture process using the default values. As the data load increases I see that extract starts lagging behind by an hour (or more) and database performance degrades. How you will resolve this performance issue?
When operating in integrated capture mode, You must make sure that you have assigned sufficient memory to STREAMS_POOL_SIZE. An undersized STREAMS_POOL_SIZE or limiting the streams pool to use a specific amount of memory can cause troubles.
The best practice is to allocate STREAMS_POOL_SIZE at the instance level and allocate the MAX. SGA at GG Process level as below:
SQL> alter system set STREAMS_POOL_SIZE=3G;
TRANLOGOPTIONS INTEGRATEDPARAMS(MAX_SGA_SIZE 2048, PARALLELISM 4)
Why would you segregate the tables in a repllication configuration? How would you do it?
In OGG you can configure replicat at the data at the schema level or at the table level using TABLE parameter of extract and MAP parameter of replicat.
For replicating the entire database you can list all the schemas in the database in the extract/replicat parameter file.
Depending the amount of redo generation you can split the tables in a schema in multiple extracts and replicats to improve the performance of data replication. Alternatively youcan also group a set of tables in the confiuration by the application functionality.
Alternatively you may need to remove tables which have long running transactions in a seperate extract process to eliminte lag on the other tables.
Let’s say that you have a schema named SCOTT and it has 100 hundred tables.
Out of these hundred tables, 50 tables are heavily utilized by application.
To improve the overall replication performance you create 3 extract and 3 replicats as follows:
Ext_1/Rep_1 –> 25 tables
Ext_2/Rep_2 –> 25 tables
Ext_3/Rep_3 –> 50 tables
Ext_1/Rep_1 and Ext_2/Rep_2 contains 25 table each which are heavily utilized or generate more redo.
Ext_3/Rep_3 contains all the other 50 tables which are least used.

Golden-Gate - Basics

Golden-Gate: Basics

What type of topologies golden gate support?

a. Unidirectional
b. Bi-Directional
c. peer-to-peer
d. Broadcast
E. Consolidation
F. Cascading

What are the main components of the Oracle Golden Gate?

The replication configuration consists of the following process.


  • Manager
  • Extract
  • Replicate
  • Data pump


What database does golden gate support for replication?


  • MS SQL Server
  • My SQL
  • IBM DB2
  • Oracle Server
  • Sybase
  • Teradata
  • Informix 
  • SQL/MX
  • Enscribe
  • Timesten


What transaction types does golden gate support for replication?

Golden gate supports both the DDL and DML Replications from source to target.

What are the supplemental logging pre-requisites?

The following supplemental logging is required.


  • Database supplemental logging.
  • Object level logging.


Why is supplemental logging is required for replication?

When a transaction is committed on the source database, only new data is written to the redo log. However for oracle to apply these transactions on the destination database, the before image key values are required to the destination database, the before image key values are required to identify the effected rows. This data is also placed in the trail file and used to identify the rows on the destination , using the key value the transactions are executed against them.

Are OGG binaries supported on ASM Cluster File System (ACFS)?

Yes, you can install and configure OGG on ACFS.

Are OGG binaries supported on the Database File System (DBFS)? What files can be stored in DBFS?

No, OGG binaries are not supported on DBFS. You can however store parameter files, datafiles (Trail files), and checkpoint files on DBFS.

What is the default location of the GLOBALS file?

A GLOBALS file is located under Oracle GoldenGate installation directory (OGG_HOME).

Where can filtering of data for a column be configured?

Filtering of the columns of a table can be set at the Extract, Pump or Replicat level.

Is it a requirement to configure a PUMP extract process in OGG replication?

A PUMP extract is an optional, but it is highly recommended to use this to safe guard against network failures. Normally it is configured when you are setting up OGG replication across the network.

List the minimum parameters that can be used to create the extract process?

The following are the minimum required parameters which must be defined in the extract parameter file.


  • Extract Name
  • UserID
  • Exttrail
  • Table
I want to configure multiple extracts to write to the same exttrail file? Is this possible?

Only one extract process can write to one exttrail at a time So you can't configure multiple extracts to write to the same exttrail.

What type of Encryption is supported in Goldengate?

Oracle Goldengate provides 3 types of encryption.
  • Data Encryption using blow fish.
  • Password Encryption.
  • Network Encryption.
What are the different password encryption options available with OGG?

you can encrypt a password in OGG using.
  • Blowfish algorithm and
  • Advance Encryption Standard (AES) algorithm.
What are the different encryption levels in AES?

you can encrypt password/data using the AES in three different keys.
  • 128 bit
  • 192 bit
  • 256 bit
Is there a way tot check the syntax of the commands in the parameter file without actually running the Golden Gate process.

yes, you can place the SHOWSYNTAX parameter in the parameter file and try starting. if there is any error you will see it.

What are the differences between the classic and integrated capture?

Classic Capture:

The classic capture mode is the traditional extract process that accesses the database redo logs (Optionally archive logs) to capture the DML changes occurring on the objects specified in the parameter files.
  • At the OS level, the GG user must be a part of the same database group which owns the database redo logs.
  • This capture mode is available for other RDBMS as well.
  • There are some data types that are not supported in classic capture mode.
  • Classic capture can't read data from the compressed tables/tablespaces.
Integrated Capture (IC):

  • In the IC mode, GG works directly with the database log mining server to receive the data changes in the form of logical change records (LCRs).
  • IC Mode does not require any special setup for the databases using ASM, transparent data encryption, or Oracle RAC.
  • This feature is only available for oracle databases in version 11.2.0.3 or higher.
  • It also supports various object types which were previously not supported by classic capture.
  • This capture mode supports extracting data from source databases using compression.
  • IC can be configured in an online or downstream mode.

List important considerations for bi-directional replication?

The customer should consider the following points in an active-active replication environment.
Primary Key: Helps to identify conflicts and Resolve them.
  • Sequences: Are not supported. The work around is use to use odd/even, range or concatenate sequences.
  • Triggers: These should be disabled or suppressed to avoid using uniqueness issue
  • Data Looping: This can easy avoided using OGG itself
  • LAG: This should be minimized. If a customer says that there will not be any LAG due to network or huge load, then we don’t need to deploy CRDs. But this is not the case always as there would be some LAG and these can cause Conflicts.
  • CDR (Conflict Detection & Resolution): OGG has built in CDRs for all kind of DMLs that can be used to detect and resolve them.
  • Packaged Application: These are not supported as it may contain data types which are not support by OGG or it might not allow the application modification to work with OGG.

Oracle 12c New Features

Oracle 12c new features

1. New background processes - LREG (Listener Registration), SA (SGA Allocator), RM.


Listener Registration Process (LREG)

The listener registration process (LREG) registers information about the database instance and dispatcher processes with the Oracle Net listener (see "The Oracle Net Listener"). When an instance starts, LREG polls the listener to determine whether it is running. If the listener is running, then LREG passes it relevant parameters. If it is not running, then LREG periodically attempts to contact it.

Note:

In releases before Oracle Database 12c, PMON performed the listener registration.”

2. Like sysdba, sysoper & sysasm, we have new privileges, in Oracle 12.1.0.


sysbackup for Backup operations
sysdg for Data Guard operations
syskm for Key management

3. Running SQL commands and executing PLSQL procedures in RMAN without SQL keyword.


RMAN> select * from v$session;

4. No need to shutdown database for changing archive log mode.


5. Table level restoration i.e object level.


6. Oracle Database 12c introduces a new redo transportation method which omits the acknowledgement (to primary) of the transaction on the standby. This feature is called "Fast Sync" redo transport.


7. Data Guard Broker commands have been extended. The "validate database" command to checks whether the database is ready for role transition or not.


8. In 12c it is possible to cascade a Standby Database in Real Time, that is, the first Standby Database can send Redo from the Standby RedoLogs to the cascaded Standby Database.


9. Pluggable Database:


In Oracle 12c, in a pluggable database environment, we can create a single database container, and plug multiple databases into this container. All these databases then share the exact same oracle server/background processes and memory, unlike the previous versions where each database has its own background processes and shared memory. This helps in database consolidation and reduces the overhead of managing multiple desperate databases.


Container Database (CDB): Are the core data dictionary objects that come after an Oracle database installation.

Pluggable Database (PDB): Data dictionary objects and data related to the application. We can have many PDB plugged into a single CDB.

10. New Views in Oracle 12c Release1


dba_pdbs
v$pdbs
cdb_data_files 

********************************************************************

http://allthingsoracle.com/oracle-database-12c-new-features-part-i/


https://nitishanandsrivastava.wordpress.com/oracle-12c-miscellaneous/12c-new-features-global-temporary-table-undo/

********************************************************************
1. Online rename and relocation of an active data file:

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

Unlike in the previous releases, a data file migration or renaming in Oracle database 12c R1 no longer requires a number of steps i.e. putting the tablespace in READ ONLY mode, followed by data file offline action. In 12c R1, a data file can be renamed or moved online simply using the ALTER DATABASE MOVE DATAFILE SQL statement. While the data file is being transferred, the end user can perform queries, DML and DDL tasks. Additionally, data files can be migrated between storages e.g. from non-ASM to ASM and vice versa.


Rename a data file:


ALTER DATABASE MOVE DATAFILE '/u01/app/oracle/oradata/cora12c/test.dbf' TO '/u01/app/oracle/oradata/cora12c/test_01.dbf';


Migrate a data file from non-ASM to ASM:


ALTER DATABASE MOVE DATAFILE '/u00/data/users_01.dbf' TO '+DG_DATA';


Migrate a data file from one ASM disk group to another:


ALTER DATABASE MOVE DATAFILE '+DG_DATA/DBNAME/DATAFILE/users_01.dbf ' TO '+DG_DATA_02';


Overwrite the data file with the same name, if it exists at the new location:


ALTER DATABASE MOVE DATAFILE '/u00/data/users_01.dbf' TO '/u00/data_new/users_01.dbf' REUSE;


Copy the file to a new location whilst retaining the old copy in the old location:


ALTER DATABASE MOVE DATAFILE '/u00/data/users_01.dbf' TO '/u00/data_new/users_01.dbf' KEEP;


You can monitor the progress while a data file being moved by querying the v$session_longops dynamic view. Additionally, you can also refer the alert.log of the database where Oracle writes the details about action being taken place.


By default, Oracle automatically deletes old data file after moving them and prevents the user from overwriting
an existing file.

When we move a datafile, Oracle first makes a copy of the datafile.
Then, when the file is successfully copied, pointers to the datafile are updated and the old file is removed from the file system.
This is why the operation requires twice the size of the files to be copied as free space.

we can use KEEP clause to keep the old datafile used to make a copy of the file. Also REUSE clause
can be used to overwrite an existing file.

  * From file system to file system
  * From file system to ASM
  * From ASM to ASM

  * From ASM to ASM

********************************************************************
2. Multiple indexes on the same column:

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

Pre Oracle 12c, you can’t create multiple indexes either on the same column or set of columns in any form. For example, if you have an index on column {a} or columns {a,b}, you can’t create another index on the same column or set of columns in the same order. In 12c, you can have multiple indexes on the same column or set of columns as long as the index type is different. However, only one type of index is usable/visible at a given time. In order to test the invisible indexes, you need to set the optimizer_use_use_invisible_indexes=true.


SQL> CREATE INDEX emp_ind1 ON EMP(ENO,ENAME);

SQL> CREATE BITMAP INDEX emp_ind2 ON EMP(ENO,ENAME) INVISIBLE;

********************************************************************
3. DDL logging:

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

There was no direction option available to log the DDL action in the previous releases. In 12cR1, you can now log the DDL action into xml and log files. This will be very useful to know when the drop or create command was executed and by who. The ENABLE_DDL_LOGGING initiation parameter must be configured in order to turn on this feature. The parameter can be set at the database or session levels. When this parameter is enabled, all DDL commands are logged in an xml and a log file under the $ORACLE_BASE/diag/rdbms/DBNAME/log|ddl location. An xml file contains information, such as DDL command, IP address, timestamp etc. This helps to identify when a user or table dropped or when a DDL statement is triggered.


To enable DDL logging


SQL> ALTER SYSTEM|SESSION SET ENABLE_DDL_LOGGING=TRUE;


The following DDL statements are likely to be recorded in the xml/log file:


CREATE|ALTER|DROP|TRUNCATE TABLE

DROP USER
CREATE|ALTER|DROP PACKAGE|FUNCTION|VIEW|SYNONYM|SEQUENCE

********************************************************************
4. Backup specific user privilege:

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

In 11g R2, SYSASM privilege was introduced to perform ASM specific operations. Similarly, backup and recovery tasks specific privilege SYSBACKUP has been introduced in 12c to execute backup and recovery commands in Recovery Manager (RMAN). Therefore, you can create a local user in the database and grant the SYSBACKUP privilege to perform any backup and recovery related tasks in RMAN without being granting the SYSDBA privilege.


$ ./rman target "username/password as SYSBACKUP"


********************************************************************
5. How to execute SQL statement in RMAN:

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

In 12c, you can now execute any SQL and PL/SQL commands in RMAN without the need of a SQL prefix: you can execute any SQL and PLS/SQL commands directly from RMAN. How you can execute SQL statements in RMAN:


RMAN> SELECT username,machine FROM v$session;

RMAN> ALTER TABLESPACE users ADD DATAFILE SIZE 121m;

********************************************************************
6. Table or partition recovery in RMAN:
---------------------------------------
Oracle database backups are mainly categorized into two types: logical and physical. Each backup type has its own pros and cons. In previous editions, it was not feasible to restore a table or partition using existing physical backups. In order to restore a particular object, you must have logical backup. With 12c R1, you can recover a particular table or partition to a point-in-time or SCN from RMAN backups in the event of a table drop or truncate.

When a table or partition recovery is initiated via RMAN, the following action is performed:


Required backup sets are identified to recover the table/partition

An auxiliary database will be configured to a point-in-time temporarily in the process of recovering the table/partition
Required table/partitions will be then exported to a dumpfile using the data pumps
Optionally, you can import the table/partitions in the source database
Rename option while recovery
An example of a table point-in-time recovery via RMAN (ensure you already have a full database backup from earlier):

RMAN> connect target "username/password as SYSBACKUP";

RMAN> RECOVER TABLE username.tablename UNTIL TIME 'TIMESTAMP…'
AUXILIARY DESTINATION '/u01/tablerecovery'
DATAPUMP DESTINATION '/u01/dpump'
DUMP FILE 'tablename.dmp'
NOTABLEIMPORT    -- this option avoids importing the table automatically.
REMAP TABLE 'username.tablename': 'username.new_table_name';    -- can rename table with this option.

Important notes:



Ensure sufficient free space available under /u01 filesystem for auxiliary database and also to keep the data pump file

A full database backup must be exists, or at least the SYSTEM related tablespaces
The following limitations/restrictions are applied on table/partition recovery in RMAN:

SYS user table/partition can’t be recovered

Tables/partitions stored under SYSAUX and SYSTEM tablespaces can’t be recovered
Recovery of a table is not possible when REMAP option used to recovery a table that contains NOT NULL constraints

********************************************************************
7. Restricting PGA size:

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

Pre Oracle 12c R1, there was no option to limit and control the PGA size. Although, you set a certain size to PGA_AGGREGATE_TARGET initialization parameter, Oracle could increase/reduce the size of the PGA dynamically based on the workload and requirements. In 12c, you can set a hard limit on PGA by enabling the automatic PGA management, which requires PGA_AGGREGATE_LIMIT parameter settings. Therefore, you can now set the hard limit on PGA by setting the new parameter to avoid excessive PGA usage.


SQL> ALTER SYSTEM SET PGA_AGGREGATE_LIMIT=2G;

SQL> ALTER SYSTEM SET PGA_AGGREGATE_LIMIT=0; --disables the hard limit

Important notes:


When the current PGA limits exceeds, Oracle will automatically terminates/abort the session/process that holds the most untenable PGA memory.


*******************************************************************
8. Data Pump enhancements:

--------------------------
This part of the section will focus on the important enhancements introduced in data pumps. There are quite a few useful additions, such as converting view into a table while exporting and turning off logging while import.

Turn off redo log generation

The new TRANSFORM option introduced in data pumps import provides the flexibility to turn off the redo generation for the objects during the course of import. When DISABLE_ARCHIVE_LOGGING values is specified with the TRANSFORM option, redo generation for the objects in the context will be turned off during the entire import duration. This feature provides a great relief when importing large tables, and reduces the excessive redo generation, which results in quicker imports. This attribute applies to tables and indexes.

This example demonstrates this feature:


$ ./impdp directory=dpump dumpfile=abcd.dmp logfile=abcd.log TRANSFORM=DISABLE_ARCHIVE_LOGGING


******************************************************************
9. Gathering  statistics concurrently on multiple tables:

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

In previous Oracle database editions, whenever you execute a DBMS_STATS procedure to gather table, index, schema or database level statistics, Oracle used to collect stats one table at a time. If the table is big enough, then increasing the parallelism was recommended. With 12c R1, you can now collect stats on multiple tables, partitions and sub partitions concurrently.  Before you start using it, you must set the following at the database level to enable the feature:


SQL> ALTER SYSTEM SET RESOURCE_MANAGER_PLAN='DEFAULT_MAIN';

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=4;

SQL> EXEC DBMS_STATS.SET_GLOBAL_PREFS('CONCURRENT', 'ALL');


SQL> EXEC DBMS_STATS.GATHER_SCHEMA_STATS('SCOTT');


******************************************************************

GLOBAL TEMPORARY TABLE UNDO:
----------------------------

We all know that the operations such as INSERT, UPDATE, MERGE, and DELETE on global temporary tables generated redo. Just to clarify this for newbies:-

A Global Temporary Table stores its data in a Temporary Tablespace where the data is retained for the duration of either a single transaction or the lifetime of a session. Performing DML on a Global Temporary Table doesn’t generate redo, because the data is stored in a temporary tablespace, but it does generate undo which in turn will generate redo since the undo is stored in a permanent tablespace.

Now the question is that as this REDO isn’t required for recovery purposes whats the point of writing all that stuff to redo logs i.e. why does the changes in temporary tablespace generate undo ? If Oracle wrote a huge code to log these changes there would be some reason, right ? Any guesses ?

The reason is that the undo for global temporary tablespace is required as Oracle needs it in cases an application issues a roll back and Oracle has to provide a read consistent image. For situations in which a developer inserts some information into a global temporary table and then issues a SELECT statement against it, followed by an UPDATE or a DELETE, the rules of read consistency state that the SELECT statement cannot see the effects of the UPDATE or DELETE. To make that possible, the database needs that undo.

So a modification of a global temporary table needs to generate undo, and the undo tablespace must be protected by redo.

From 12c onwards, temporary undo can be stored in the temporary tablespace and undo for permanent objects can be stored in the undo tablespace. What this effectively means is that operations on temporary tables will no longer generate redo. If you have large batch operations that utilize global temporary tables, you may well discover that the amount of redo you generate decreases by a large amount. Furthermore, you’ll be generating less undo in your undo tablespace. And that means you’ll be able to support a longer undo_retention time with a smaller undo tablespace.

Now as we understood the benefits behind having separate undo for changes in global temporary tables, lets dig in to see how we could use this feature:-

How undo is generated in Oracle Database 12c for global temporary tables is controlled by a new init.ora parameter: temp_undo_enabled. It has two settings: TRUE and FALSE. By default, this parameter is set to FALSE and undo will be generated in the same fashion it was in the past. For example:-

SQL> alter session set temp_undo_enabled = false;

Session altered.

SQL> insert into gtt select * from all_objects;
87310 rows created.

Statistics
———————————————————————————

     566304  redo size


SQ> update gtt set object_name = lower(object_name);
87310 rows updated.

Statistics
————————————————————————————
… 
    8243680  redo size

As you can see, the INSERT generates about half a megabyte of redo (566,304 bytes) while the UPDATE generates upwards of 8 MB of redo (8,243,680 bytes).

Now if I enable temporary undo, :-

SQL> alter session set temp_undo_enabled = true;

Session altered.

SQL> insert into gtt select * from all_objects;

87310 rows created.

Statistics
———————————————————————————————

        280  redo size


SQL> update gtt set object_name = lower(object_name);
87310 rows updated.
Statistics
———————————————————————————————

          0  redo size

the redo is either trivial or nonexistent.

Hence you can see that we can have significant improvements using this feature especially in case of UPDATEs and DELETEs.

*******************************************************************

Oracle DBA - Performance Tuning

Oracle DBA Interview Questions and Answers - Performance Tuning


Application user is complaining the database is slow.How would you find the performance issue of SQL queries?

High performance is common expectation for end user, in fact the database is never slow or fast in most of the case session connected to the database slow down when they receives unexpected hit. Thus to solve this issue you need to find those unexpected hit. 
To know exactly what the session is doing join your query v$session with v$session_wait. 

SELECT NVL(s.username,'(oracle)') as username,s.sid,s.serial#,sw.event,sw.wait_time, sw.seconds_in_wait, sw.state FROM v$session_wait sw,v$session s
WHERE s.sid=sw.sid and s.username= '&username'ORDER BY sw.seconds_in_wait DESC;

1.Check the events that are waiting for something.
2.Try to find out objects locks for that particulate session.
3.Locking is not only the cause to effect the performance. 
Disk I/O is contention is another case. When session retrieves data from the database datafiles on disk to the buffer cache, it has to wait until the disk sends the data.
The wait event shows up for the session as "db file sequential read" (for index scan) or "db file scattered read" (for full table scan).

When you see the event, you know that the session is waiting for I/O from the disk to complete. 
To improve session performance, you have to reduce that waiting period. 
The exact step depends on specific situation, but the first technique “reducing the number of blocks retrieved by a SQL statement” almost always works.Reduce the number of blocks retrieved by the SQL statement. 
Examine the SQL statement to see if it is doing a full-table scan when it should be using an index, if it is using a wrong index, or if it can be rewritten to reduce the amount of data it retrieves.

4.Run SQL Tuning Advisor (@$ORACLE_HOME/rdbms/admin/sqltrpt.sql) by providing SQL_ID as the input for generating the findings and recommendations.
SQL Tuning Advisor seems to be doing logical optimization mainly by checking your SQL structure and statistics.
SQL Tuning Advisor suggests indexes that might be very useful.
SQL Tuning Advisor suggests query rewrites.
SQL Tuning Advisor  suggests SQL profile.

More:
1.Run TOP command in Linux to check CPU usage.
2.Run VMSTAT, SAR, PRSTAT command to get more information on CPU, memory usage and possible blocking.
3.Enable the trace file before running your queries,then check the trace file using tkprof create output file.
According to explain plan check the elapsed time for each query,then tune them respectively.

What is the use of iostat/vmstat/netstat command in Linux?
Iostat – reports on terminal, disk and tape I/O activity.
Vmstat – reports on virtual memory statistics for processes, disk, tape and CPU activity.
Netstat – reports on the contents of network data structures.

If you are getting high “Busy Buffer waits”, how can you find the reason behind it?
Buffer busy wait means that the queries are waiting for the blocks to be read into the db cache. There could be the reason when the block may be busy in the cache and session is waiting for it. It could be undo/data block or segment header wait.
Run the below two query to find out the P1, P2 and P3 of a session causing buffer busy wait
then after another query by putting the above P1, P2 and P3 values.
SQL> Select p1 "File #",p2 "Block #",p3 "Reason Code" from v$session_wait Where event = 'buffer busy waits';
SQL> Select owner, segment_name, segment_type from dba_extents
Where file_id = &P1 and &P2 between block_id and block_id + blocks -1;

What to Look for in AWR Report and STATSPACK Report?
Many DBAs already know how to use STATSPACK but are not always sure what to check regularly.
Remember to separate OLTP and Batch activity when you run STATSPACK, since they usually
generate different types of waits. The SQL script “spauto.sql” can be used to run STATSPACK
every hour on the hour. See the script in $ORACLE_HOME/rdbms/admin/spauto.sql for more
information (note that JOB_QUEUE_PROCESSES must be set > 0). Since every system is different,
this is only a general list of things you should regularly check in your STATSPACK output:
¦ Top 5 wait events (timed events)
¦ Load profile
¦ Instance efficiency hit ratios
¦ Wait events

¦ Latch waits
¦ Top SQL
¦ Instance activity
¦ File I/O and segment statistics
¦ Memory allocation
¦ Buffer waits

What is the difference between DB file sequential read and DB File Scattered Read?
DB file sequential read is associated with index read where as DB File Scattered Read has to do with full table scan. 
The DB file sequential read, reads block into contiguous memory and DB File scattered read gets from multiple block and scattered them into buffer cache. 

Which factors are to be considered for creating index on Table? How to select column for index?
Creation of index on table depends on size of table, volume of data. If size of table is large and we need only few data for selecting or in report then we need to create index. There are some basic reason of selecting column for indexing like cardinality and frequent usage in where condition of select query. Business rule is also forcing to create index like primary key, because configuring primary key or unique key automatically create unique index. 
It is important to note that creation of so many indexes would affect the performance of DML on table because in single transaction should need to perform on various index segments and table simultaneously.

Is creating index online possible?
YES. You can create and rebuild indexes online. This enables you to update base tables at the same time you are building or rebuilding indexes on that table. You can perform DML operations while the index building is taking place, but DDL operations are not allowed. Parallel execution is not supported when creating or rebuilding an index online.
CREATE INDEX emp_name ON emp (mgr, emp1, emp2, emp3) ONLINE;

How to recover password in oracle 10g?
You can query with the table user_history$. The password history is store in this table.

How can you track the password change for a user in oracle?
Oracle only tracks the date that the password will expire based on when it was latest changed. Thus listing the view DBA_USERS.EXPIRY_DATE and subtracting PASSWORD_LIFE_TIME you can determine when password was last changed. You can also check the last password change time directly from the PTIME column in USER$ table (on which DBA_USERS view is based). But If you have PASSWORD_REUSE_TIME and/or PASSWORD_REUSE_MAX set in a profile assigned to a user account then you can reference dictionary table USER_HISTORY$ for when the password was changed for this account.
SELECT user$.NAME, user$.PASSWORD, user$.ptime, user_history$.password_date
FROM SYS.user_history$, SYS.user$
WHERE user_history$.user# = user$.user#;

What is Secure External password Store (SEPS)?
Through the use of SEPS you can store password credentials for connecting to database by using a client side oracle wallet, this wallet stores signing credentials. This feature introduced since oracle 10g. Thus the application code, scheduled job, scripts no longer needed embedded username and passwords. This reduces risk because the passwords are no longer exposed and password management policies are more easily enforced without changing application code whenever username and password change.

Why we need CASCADE option with DROP USER command whenever dropping a user and why "DROP USER" commands fails when we don't use it?
If a user having any object then ‘YES’ in that case you are not able to drop that user without using CASCADE option. The DROP USER with CASCADE option command drops user along with its all associated objects. Remember it is a DDL command after the execution of this command rollback cannot be performed.

What is the difference between Redo,Rollback and Undo?
I find there is always some confusion when talking about Redo, Rollback and Undo. They all sound like pretty much the same thing or at least pretty close.
Redo: Every Oracle database has a set of (two or more) redo log files. The redo log records all changes made to data, including both uncommitted and committed changes. In addition to the online redo logs Oracle also stores archive redo logs. All redo logs are used in recovery situations.
Rollback: More specifically rollback segments. Rollback segments store the data as it was before changes were made. This is in contrast to the redo log which is a record of the insert/update/deletes.
Undo: Rollback segments. They both are really one in the same. Undo data is stored in the undo tablespace. Undo is helpful in building a read consistent view of data.

You have more than 3 instances running on the Linux server? How can you determine which shared memory and semaphores are associated with which instance?
Oradebug is undocumented oracle supplied utility by oracle. The oradebug help command list the command available with oracle.
SQL>oradebug setmypid
SQL>oradebug ipc
SQL>oradebug tracfile_name

Why drop table is not going into Recycle bin?
If you are using SYS user to drop any table then user’s object will not go to the recyclebin as there is no recyclebin for SYSTEM tablespace, even we have already SET recycle bin parameter TRUE.
Select * from v$parameter where name = 'recyclebin';
Show parameter recyclebin; 

Temp Tablespace is 100% FULL and there is no space available to add datafiles to increase temp tablespace. What can you do in that case to free up TEMP tablespace?
Try to close some of the idle sessions connected to the database will help you to free some TEMP space. Otherwise you can also use ‘Alter Tablespace PCTINCREASE 1’ followed by ‘Alter Tablespace PCTINCREASE 0’

When a Tablespace reaches 90%, what action you will take? How you decide whether to go for Resize or Add datafile?

What is the max possible size of a SMALL and BIG datafiles?

SUPPOSE A QUERY IS RUNNING SLOW OR HUNG STATE, What will you do?

SUPPOSE DATAABSE IS RUNNING SLOW, What will you do?

As a DBA what Pro active steps do you take for a Highly utilized Undo?

AWR Vs. ASH?

AWR Contents?How to interpret AWR?

Wait Events? 

Difference between DB File Sequential Read and DB file Scattered Reads?

how to cache a table or pin a table?

What is explain plan?

What is Database Replay?

What is Fragmentaion?

What are MATERIALIZED VIEWS?

What are Trace files?

What is ORA-600?

What is OLTP AND DATAWAREHOUSING?

How to change character set of database?

What are unused indexes?How to reuse unused indexes?

What is Row Chaning and Row Migration? **
Row Migration:
A row migrates when an update to that row would cause it to not fit on the block anymore (with all of the other data that exists there currently).  A migration means that the entire row will move and we just leave behind the «forwarding address». So, the original block just has the rowid of the new block and the entire row is moved.


Row Chaining:
A row is too large to fit into a single database block. For example, if you use a 4KB blocksize for your database, and you need to insert a row of 8KB into it, Oracle will use 3 blocks and store the row in pieces. 
Some conditions that will cause row chaining are: Tables whose rowsize exceeds the blocksize. Tables with LONG and LONG RAW columns are prone to having chained rows. Tables with more then 255 columns will have chained rows as Oracle break wide tables up into pieces. 
So, instead of just having a forwarding address on one block and the data on another we have data on two or more blocks.

How to find out background processes ?
SQL> select SID,PROGRAM from v$session where TYPE='BACKGROUND';
SQL> select name,description from V$bgprocess;

How to findout background processes from OS:
$ ps -ef|grep ora_|grep SID
To Find and Delete bigger size and older files in Linux
--To find out files size more than 5MB
find . -size +5000  -exec ls -ltr {} \;  
-- To **Remove** files size more than 5MB
find . -size +5000k  -exec rm -rf {} \;
--To find out files older than 30days 
find . -mtime +30 -exec ls -ltr {} \;
--To find **Remove** files older than 30days 
find . -mtime +30  -exec rm -rf {} \;