Total Pageviews

Showing posts with label oracle. Show all posts
Showing posts with label oracle. Show all posts

Friday, 6 February 2015

Oracle RECYCLEBIN

The recyclebin is a public synonym and it is based on the view user_recyclebin which in turn is based on sys.recyclebin$ table.

SQl> Select object_type,object_name from dba_objects where object_name='RECYCLEBIN';

OBJECT_TYPE     OBJECT_NAME
-----------------------------------------------
SYNONYM         RECYCLEBIN


SQL> desc recyclebin
 Name                                      Null?    Type
 ----------------------------------------- -------- ------------
 OBJECT_NAME                               NOT NULL VARCHAR2(30)
 ORIGINAL_NAME                                      VARCHAR2(32)
 OPERATION                                          VARCHAR2(9)
 TYPE                                               VARCHAR2(25)
 TS_NAME                                            VARCHAR2(30)
 CREATETIME                                         VARCHAR2(19)
 DROPTIME                                           VARCHAR2(19)
 DROPSCN                                            NUMBER
 PARTITION_NAME                                     VARCHAR2(32)
 CAN_UNDROP                                         VARCHAR2(3)
 CAN_PURGE                                          VARCHAR2(3)
 RELATED                                   NOT NULL NUMBER
 BASE_OBJECT                               NOT NULL NUMBER
 PURGE_OBJECT                              NOT NULL NUMBER
 SPACE                                              NUMBER


Related recyclebin objects:

SQL> SELECT SUBSTR(object_name,1,50),object_type,owner
FROM dba_objects
WHERE object_name LIKE '%RECYCLEBIN%';
/
SUBSTR(OBJECT_NAME,1,50)                           OBJECT_TYPE         OWNER
---------------------------      ------------------- ------------ ----------
RECYCLEBIN$                                        TABLE               SYS
RECYCLEBIN$_OBJ                                    INDEX               SYS
RECYCLEBIN$_TS                                     INDEX               SYS
RECYCLEBIN$_OWNER                                  INDEX               SYS
USER_RECYCLEBIN                                    VIEW                SYS
USER_RECYCLEBIN                                    SYNONYM             PUBLIC
RECYCLEBIN                                         SYNONYM             PUBLIC
DBA_RECYCLEBIN                                     VIEW                SYS
DBA_RECYCLEBIN                                     SYNONYM             PUBLIC

9 rows selected.


THE RECYCLE BIN

The Recycle Bin is a virtual container where all dropped objects reside. Underneath the covers, the objects are occupying the same space as when they were created. If table EMP was created in the USERS tablespace, the dropped table EMP remains in the USERS tablespace. Dropped tables and any associated objects such as indexes, constraints, nested tables, and other dependant objects are not moved, they are simply renamed with a prefix of BIN$$. You can continue to access the data in a
dropped table or even use Flashback Query against it. Each user has the same rights and privileges on Recycle Bin objects before it was dropped. You can view your dropped tables by querying the new RECYCLEBIN view. Objects in the Recycle Bin will remain in the database until the owner of the dropped objects decides to permanently remove them using the new PURGE command. The Recycle Bin objects are counted against a user's quota. But Flashback Drop is a non-intrusive feature. Objects in the Recycle Bin will be automatically purged by the space reclamation process if

o A user creates a new table or adds data that causes their quota to be exceeded.
o The tablespace needs to extend its file size to accommodate create/insert operations.

There are no issues with dropping the table, behaviour wise. It is the same as in 8i / 9i. The space is not released immediately and is accounted for within the same tablespace / schema after the drop.

When we drop a tablespace or a user there is NO recycling of the objects.

o Recyclebin does not work for SYS owned objects

EXAMPLE

SQL> SELECT * FROM v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bi
PL/SQL Release 10.1.0.2.0 - Production
CORE    10.1.0.2.0      Production
TNS for Solaris: Version 10.1.0.2.0 - Production
NLSRTL Version 10.1.0.2.0 - Production

SQL> sho user
USER is "BH"

SQL> SELECT object_name,original_name,operation,type,dropscn,droptime
  2  FROM user_recyclebin
  3  /
no rows selected

SQL> CREATE TABLE t1(a NUMBER);
Table created.

SQL> DROP TABLE t1;
Table dropped.

SQL> SELECT object_name,original_name,operation,type,dropscn,droptime
  2  FROM user_recyclebin
  3  /
OBJECT_NAME                    ORIGINAL_NAME                    OPERATION TYPE                         DROPSCN DROPTIME
------------------------------ -------------------------------- --------- ------------------------- ---------- -------------------
BIN$1Unhj5+DSHDgNAgAIKds8A==$0 T1                               DROP      TABLE                     8.1832E+12 2004-03-10:11:03:49

SQL> sho user
USER is "SYS"

SQL> SELECT owner,original_name,operation,type
  2  FROM dba_recyclebin
  3  /

OWNER                          ORIGINAL_NAME                    OPERATION TYPE
------------------------------ -------------------------------- --------- ------
BH                             T1                               DROP      TABLE

We can also create a new table with the same name at this point.



PURGING

In order to completely remove the table from the DB and to release the space the new PURGE command is used.

From BH user:
SQL> PURGE TABLE t1;
Table purged.

OR

SQL> PURGE TABLE "BIN$1UtrT/b1ScbgNAgAIKds8A==$0";
Table purged.

From SYSDBA user:
SQL> SELECT owner,original_name,operation,type
  2  FROM dba_recyclebin
  3  /
no rows selected

From BH user:
SQL> SHOW recyclebin
SQL>

 There are various ways to PURGE objects:

PURGE TABLE t1;
PURGE INDEX ind1;
PURGE recyclebin; (Purge all objects in Recyclebin)
PURGE dba_recyclebin; (Purge all objects / only SYSDBA can)
PURGE TABLESPACE users; (Purge all objects of the tablespace)
PURGE TABLESPACE users USER bh; (Purge all objects of the tablspace belonging to BH)

For an object, the owner or a user with SYSDBA privilege or a user with DROP ANY... system privilege for the type of object to be purged can PURGE it.

For more information on the PURGE command refer to the 10g SQL Reference

DISABLING RECYCLEBIN

We can DROP and PURGE a table with a single command

From BH user:
SQL> DROP TABLE t1 PURGE;
Table dropped.

SQL> SELECT *
  2  FROM recyclebin
  3  /
no rows selected

There is no need to PURGE.

On 10gR1, in case we want to disable the behavior of recycling, there is an underscore parameter
"_recyclebin" which defaults to TRUE. We can disable recyclebin by setting it to FALSE.

From SYSDBA user:
SQL> SELECT a.ksppinm, b.ksppstvl, b.ksppstdf
FROM x$ksppi a, x$ksppcv b
WHERE a.indx = b.indx
AND a.ksppinm like '%recycle%'
ORDER BY a.ksppinm
/
         Parameter                            Value                   Default?
---------------------------- ---------------------------------------- --------
_recyclebin                  TRUE                                     TRUE

From BH user:
SQL> CREATE TABLE t1(a NUMBER);
Table created.

SQL> DROP TABLE t1;
Table dropped.

SQL> SELECT original_name
FROM user_recyclebin;
ORIGINAL_NAME
--------------
T1

From SYSDBA user:
SQL> ALTER SYSTEM SET "_recyclebin"=FALSE SCOPE = BOTH;
System altered.

SQL> SELECT a.ksppinm, b.ksppstvl, b.ksppstdf
FROM x$ksppi a, x$ksppcv b
WHERE a.indx = b.indx
AND a.ksppinm like '%recycle%'
ORDER BY a.ksppinm
/
         Parameter                            Value                   Default?
---------------------------- ---------------------------------------- --------
_recyclebin                  FALSE                                     TRUE

From BH user:
SQL> CREATE TABLE t1(a NUMBER);
Table created.

SQL> DROP TABLE t1;
Table dropped.

SQL> SELECT original_name
FROM user_recyclebin;
no rows selected

There is no need to PURGE.

As with anyother underscore parameter, setting this parameter is not recommended unless
advised by oracle support services.

On 10gR2 and higher; recyclebin is a initialization parameter and bydefault its ON.
We can disable recyclebin by using the following commands:

SQL> ALTER SESSION SET recyclebin = OFF;
SQL> ALTER SYSTEM SET recyclebin = OFF;

The dropped objects, when recyclebin was ON will remain in the recyclebin even if we set the recyclebin parameter to OFF.

To download oracle software or patch using Wget on Linux box

To download oracle software or patch directly on client’s Linux server you may use the below steps :

1. Add  Cookies.txt Extension in your crome browser. You can get is from crome web store  https://chrome.google.com/webstore/detail/cookiestxt/njabckikapfpffapmjgojcnbfjonfjfg?hl=en
2. One extension  will be added to google crome on top right side of browser .
3. Go to the oracle download page , login using the metalink id and Accept License Agreement .and click on the software binary to start download on your machine .
4. Now capture the cookies by Clicking on Cookies.txt extension . It will show you something like below :

# HTTP Cookie File for domains related to oracle.com.
# This content may be downloaded or pasted into a cookies.txt file and used by wget
# Example:  wget -x --load-cookies cookies.txt http://www.oracle.com/technetwork/database/enterprise-edition/downloads/database12c-linux-download-2240591.html
#
www.oracle.com FALSE   /technetwork/database/enterprise-edition/downloads      FALSE   0       testSessionCookie      Enabled
.oracle.com    TRUE    /       FALSE   1425008363     s_nr    1422416363929
.support.oracle.com    TRUE    /       FALSE   1580104749     mos.notifications        false
.oracle.com    TRUE    /       FALSE   1425097299.611 Order_MarketingInfluencer        WWOUSEOGOOGLECOIN
.oracle.com    TRUE    /       FALSE   1425097299.611054        Order_MarketingCampaignSuccess WWOUSEOGOOGLECOIN
.oracle.com    TRUE    /       FALSE   1425097299.611086      p_mcc        WWOUSEOGOOGLECOIN:NA:WWOUSEOGOOGLECOIN
.oracle.com    TRUE    /       FALSE   1737865303     optimizelyEndUserId        oeu1422505303647r0.8225775167811662


5. Just click on the “downloaded” link to download the cookies.txt file on your PC .
6. Copy the cookies.txt file to client’s linux server in the directory where you want to download the oracle software .
7. Issue the below command to download :


[root@linux12c grid_12c]# wget -x --load-cookies cookies.txt http://download.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_1of2.zip

--2015-02-05 13:39:44--  http://download.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_1of2.zip
Resolving download.oracle.com... 64.145.87.72, 64.145.87.11
Connecting to download.oracle.com|64.145.87.72|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/akam/otn/linux/oracle12c/121020/linuxamd64_12102_grid_1of2.zip [following]
--2015-02-05 13:39:44--  https://edelivery.oracle.com/akam/otn/linux/oracle12c/121020/linuxamd64_12102_grid_1of2.zip
Resolving edelivery.oracle.com... 23.76.230.140
Connecting to edelivery.oracle.com|23.76.230.140|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_1of2.zip?AuthParam=1423161704_f18babafa52442c5aec7ead56289003a [following]
--2015-02-05 13:39:44--  http://download.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_1of2.zip?AuthParam=1423161704_f18babafa52442c5aec7ead56289003a
Reusing existing connection to download.oracle.com:80.
HTTP request sent, awaiting response... 200 OK
Length: 1747043545 (1.6G) [application/zip]
Saving to: âdownload.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_1of2.zipâ

100%[=========================================================================================================================================================>] 1,747,043,545 11.0M/s   in 2m 43s

2015-02-05 13:42:35 (10.2 MB/s) - âdownload.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_1of2.zipâ

[root@linux12c grid_12c]# wget -x --load-cookies cookies.txt http://download.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_2of2.zip
--2015-02-05 13:45:11--  http://download.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_2of2.zip
Resolving download.oracle.com... 64.145.87.72, 64.145.87.11
Connecting to download.oracle.com|64.145.87.72|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/akam/otn/linux/oracle12c/121020/linuxamd64_12102_grid_2of2.zip [following]
--2015-02-05 13:45:11--  https://edelivery.oracle.com/akam/otn/linux/oracle12c/121020/linuxamd64_12102_grid_2of2.zip
Resolving edelivery.oracle.com... 23.76.230.140
Connecting to edelivery.oracle.com|23.76.230.140|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_2of2.zip?AuthParam=1423162031_de94d7ea4c7ca02b6a1986593b23227a [following]
--2015-02-05 13:45:11--  http://download.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_2of2.zip?AuthParam=1423162031_de94d7ea4c7ca02b6a1986593b23227a
Reusing existing connection to download.oracle.com:80.
HTTP request sent, awaiting response... 200 OK
Length: 646972897 (617M) [application/zip]
Saving to: âdownload.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_2of2.zipâ

100%[===========================================================================================================================================================>] 646,972,897 4.57M/s   in 2m 5s

2015-02-05 13:47:19 (4.93 MB/s) - âdownload.oracle.com/otn/linux/oracle12c/121020/linuxamd64_12102_grid_2of2.zipâ

8. Verify the size of files downloaded and checksum : match the cksum with value from oracle website
 
Oracle Database 12c Release 1 Grid Infrastructure (12.1.0.2.0) for Linux x86-64
 
linuxamd64_12c_grid_1of2.zip (1,747,043,545 bytes) (cksum - 1194876808)
 
linuxamd64_12c_grid_2of2.zip (646,972,897 bytes) (cksum - 2519919927)


wget executes under directory /staging/grid_12c/ and Files will be downloaded under : /staging/grid_12c/download.oracle.com/otn/linux/oracle12c/121020

[root@linux12c 121020]# ls -lrth
total 2.3G
-rw-r--r--. 1 root root 1.7G Jul 11  2014 linuxamd64_12102_grid_1of2.zip
-rw-r--r--. 1 root root 618M Jul 11  2014 linuxamd64_12102_grid_2of2.zip
[root@linux12c 121020]#
[root@linux12c 121020]# cksum linuxamd64_12102_grid_1of2.zip
1194876808 1747043545 linuxamd64_12102_grid_1of2.zip
[root@linux12c 121020]# cksum linuxamd64_12102_grid_2of2.zip
2519919927 646972897 linuxamd64_12102_grid_2of2.zip
[root@linux12c 121020]# pwd
/staging/grid_12c/download.oracle.com/otn/linux/oracle12c/121020

Or we can use directly as below :

wget --http-user="myMetalinkID@xyz.com" --http-password="MyPassword" --output-document="p21419221_121020_Linux-x86-64_1of10.zip" "https://updates.oracle.com/Orion/Download/process_form/p21419221_121020_Linux-x86-64_1of10.zip?file_id=81606884&aru=19220015&userid=o-myMetalinkID@xyz.com&email=myMetalinkID@xyz.com&patch_password=&patch_file=p21419221_121020_Linux-x86-64_1of10.zip"


wget --http-user="myMetalinkID@xyz.com" --http-password="MyPassword" --output-document="p21419221_121020_Linux-x86-64_2of10.zip" "https://updates.oracle.com/Orion/Download/process_form/p21419221_121020_Linux-x86-64_2of10.zip?file_id=81606884&aru=19220015&userid=o-myMetalinkID@xyz.com&email=myMetalinkID@xyz.com&patch_password=&patch_file=p21419221_121020_Linux-x86-64_2of10.zip"

Thursday, 29 January 2015

Change the DB name without nid .

Problem: To change DB name from db11g to db11gnew without using nid utility ,

SQl>   show parameter db_name ;

NAME     TYPE VALUE
------------------------------------ ----------- -----
db_name     string db11g


SQL> ARCHIVE LOG LIST ;
Database log mode       Archive Mode
Automatic archival       Enabled
Archive destination       USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     2
Next log sequence to archive   4
Current log sequence       4

SQL> alter system switch logfile;

System altered.

SQL> alter database backup controlfile to trace as '/home/oracle/control_trace.sql' ; 

SQL> SELECT DECODE(value, NULL, 'PFILE', 'SPFILE') "Init File Type" FROM sys.v_$parameter WHERE name = 'spfile';

Init File Type
----------------

SPFILE


SQL>create pfile=' /home/oracle/initdb11gnew.ora' from spfile ; 


Database altered.
[oracle@oracle11g dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jan 29 18:04:37 2015

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> shu immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.


Edit to control file trace /home/oracle/control_trace.sql . Remove everything above Set#2 : Resetlog case and edit the create statement as : 

CREATE CREATE CONTROLFILE SET  DATABASE "db11gnew"

[oracle@oracle11g ~]$ cat control_trace.sql

--     Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.

-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT
CREATE CONTROLFILE SET  DATABASE "db11gnew" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 (
    '+DATA2/db11g/onlinelog/group_1.261.868740309',
    '+RMAN_DISK/db11g/onlinelog/group_1.257.868740313'
  ) SIZE 50M BLOCKSIZE 512,
  GROUP 2 (
    '+DATA2/db11g/onlinelog/group_2.262.868740319',
    '+RMAN_DISK/db11g/onlinelog/group_2.258.868740323'
  ) SIZE 50M BLOCKSIZE 512,
  GROUP 3 (
    '+DATA2/db11g/onlinelog/group_3.263.868740329',
    '+RMAN_DISK/db11g/onlinelog/group_3.259.868740333'
  ) SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '+DATA2/db11g/datafile/system.256.868740081',
  '+DATA2/db11g/datafile/sysaux.257.868740081',
  '+DATA2/db11g/datafile/undotbs1.258.868740081',
  '+DATA2/db11g/datafile/users.259.868740081'
CHARACTER SET WE8MSWIN1252
;
ALTER DATABASE OPEN RESETLOGS;
ALTER TABLESPACE TEMP ADD TEMPFILE '+DATA2'  SIZE 20971520  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;


Rename  the current init file and spfile as Bkp files . 

Copy the init file create above in $ORACLE_HOME/dbs and change the db_name to db11gnew .

[oracle@oracle11g dbs]$ cp /home/oracle/initdb11gnew.ora $ORACLE_HOME/dbs
[oracle@oracle11g dbs]$ ls


[oracle@oracle11g dbs]$ cat initdb11gnew.ora


*.audit_file_dest='/u01/app/oracle/admin/db11g/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
#*.control_files='+DATA2/db11g/controlfile/','+RMAN_DISK/db11g/controlfile/'
*.db_block_size=8192
*.db_create_file_dest='+DATA2'
*.db_domain=''
*.db_name='db11gnew'
*.db_recovery_file_dest='+RMAN_DISK'
*.db_recovery_file_dest_size=4322230272
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=db11gXDB)'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=807403520
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'

[oracle@oracle11g ~]$ export ORACLE_SID=db11gnew
[oracle@oracle11g ~]$ ls
control_trace.sql  db_11g_single_with_asm.rsp  db_info.log  Desktop  initdb11gnew.ora
[oracle@oracle11g ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jan 29 18:06:39 2015

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> @control_trace.sql ; 
ORACLE instance started.

Total System Global Area  805875712 bytes
Fixed Size    2232680 bytes
Variable Size  478154392 bytes
Database Buffers  322961408 bytes
Redo Buffers    2527232 bytes

Control file created.


Database altered.

Tablespace altered.


SQL> select NAME,LOG_MODE,CONTROLFILE_TYPE,OPEN_MODE from V$DATABASE ;

NAME  LOG_MODE     CONTROL OPEN_MODE
--------- ------------ ------- -------------------------------------
DB11GNEW  ARCHIVELOG   CURRENT READ WRITE

SQL> Show parameter control_file ;

control_files      string  +DATA2/db11gnew/controlfile/current.266.870286263,                                                                        +RMAN_DISK/db11gnew/controlfile/current .262.870286265

Shu immediate and Edit the init file with the new control_file values . Again start the DB using pfile and create spfile .



[oracle@oracle11g ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 29-JAN-2015 18:18:07

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER2
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                29-JAN-2015 17:27:48
Uptime                    0 days 0 hr. 50 min. 19 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/11.2.0/grid_11203/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/oracle11g/listener2/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle11g.localdomain)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM", status READY, has 1 handler(s) for this service...
Service "db11gXDB" has 1 instance(s).
  Instance "db11gnew", status READY, has 1 handler(s) for this service...
Service "db11gnew" has 1 instance(s).
  Instance "db11gnew", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@oracle11g ~]$

Check for the new path of control files created in ASM using asmcmd you can check that .
Shutdown the DB and change the new path of control_file in initdb11gnew.ora .

Start the db using initdb11gnew.ora and recreate the spfile , shutdown again and startup DB using spfile .

SQL> create spfile='+DATA2' from pfile ;

File created.

SQL> shu immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

After this modify the initdb11gnew.ora to point to new spfile created .

ASMCMD> ls -l +DATA2/DB11GNEW/PARAMETERFILE/

Type           Redund  Striped  Time             Sys  Name
PARAMETERFILE  UNPROT  COARSE   JAN 29 18:00:00  Y    spfile.268.870289035

ASMCMD> +DATA2/DB11GNEW/PARAMETERFILE/spfile.268.870289035
ASMCMD>

Edit the init file to point to the spfile :

[oracle@oracle11g dbs]$ cat initdb11gnew.ora

SPFILE='+DATA2/DB11GNEW/PARAMETERFILE/spfile.268.870289035'

Now start the Db using spfile :

SQL> startup ;
ORACLE instance started.

Total System Global Area  805875712 bytes
Fixed Size    2232680 bytes
Variable Size  478154392 bytes
Database Buffers  322961408 bytes
Redo Buffers    2527232 bytes
Database mounted.
Database opened.

SQL> show parameter pfile ;

NAME     TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile     string +DATA2/db11gnew/parameterfile/
spfile.268.870289035

 SQL> show parameter control_file;

NAME     TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time     integer 7
control_files     string +DATA2/db11gnew/controlfile/current.266.870286263,                                                                        +RMAN_DISK/db11gnew/controlfile/current .262.870286265

change the settings in oratab , tns file etc . 

Monday, 19 January 2015

Changing the DBID & DBNAME of a database using nid

Follow the below steps to change only the dbid :
====================================
1. Backup the database
2. Shutdown all instances in the cluster make sure that this is a consistent shutdown done using shutdown immediate or shutdown normal command.
3. Make the parameter cluster_database=false
4. Startup mount only on one of the instances
5. Invoke the DBNEWID utility (nid) from the command line using a user with SYSDBA privilege.Do not specify a new DBNAME:

 $ORACLE_HOME/bin/nid TARGET=SYS/password@DB11G

6. Shutdown IMMEDIATE of the database (Note: This step is not required in 10g)
7. Open the database with resetlogs
8 . Make the parameter cluster_database=true and shutdown the current instance and startup all the instances
9. Take full backup of the database .

Follow the below steps to change only the DBNAME :
=========================================

1. Backup the database
2. Shutdown all instances in the cluster make sure that this is a consistent shutdown done using shutdown immediate or shutdown normal command.
3. Set the parameter CLUSTER_DATABASE=false
4. Startup mount only on one of the instances
5. Invoke the utility on the command line, specifying a valid user with the SYSDBA privilege.You must specify both the DBNAME and SETNAME parameters.
The SETNAME parameter tells the DBNEWID utility to only alter the database name.

$ORACLE_HOME/bin/nid TARGET=SYS/password@DB11G DBNAME=DB_NEW SETNAME=YES

6. Shutdown IMMEDIATE of the database
7. Set the DB_NAME initialization parameter in the initialization parameter file (PFILE) to the new database name
8. Create a new password file.
9. Open the database. When opening the database the RESETLOGS option is not needed so the database can be started using the STARTUP command.
11. Make the parameter CLUSTER_DATABASE=true and shutdown the current instance and startup all the instances.

Follow the below steps to Change Both DBID and DBNAME :
===============================================
1. Backup the database
2. Shutdown all instances in the cluster make sure that this is a consistent shutdown done using shutdown immediate or shutdown normal command.
3. Make the parameter CLUSTER_DATABASE=false
4. Startup mount only on one of the instances
5. Invoke the DBNEWID utility on the command line, specifying a valid user with the SYSDBA privilege

$ORACLE_HOME/bin/nid  TARGET=SYS/password@DB11G DBNAME=DB_NEW

6. Shutdown IMMEDIATE of the database
7. Set the DB_NAME initialization parameter in the initialization parameter file (PFILE) to the new database name
8. Create a new password file.
10. Mount and Open the database with resetlogs
11. Make the parameter CLUSTER_DATABASE=true and shutdown the current instance and startup all the instances

Some points to consider :
===================

1. The DBNEWID utility does not change the server parameter file (SPFILE). Therefore, if you use SPFILE to start your Oracle database, you must recreate the initialization parameter file from the server parameter file, remove the server parameter file, change the DB_NAME in the initialization parameter file, and then recreate the server parameter file.

2. DBNEWID utility makes the changes in the controlfile and datafile headers. This utility is not RAC aware. So it will not update the OCR when the database is renamed. Hence, the user needs to invoke SRVCTL to remove and again add the database information to OCR


Example Below is for changing just the DBID:

$ORACLE_HOME/bin/nid TARGET=SYS/password@DB11G

DBNEWID: Release 11.2.0.4.0 - Production on Mon Jan 19 03:53:54 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to database DB11G (DBID=338404813)

Connected to server version 11.2.0

Control Files in database:
    +DATA/db11g/controlfile/current.261.868735245
    +DATA/db11g/controlfile/current.260.868735247

Change database ID of database DB11G? (Y/[N]) => Y

Proceeding with operation
Changing database ID from 338404813 to 339029651
    Control File +DATA/db11g/controlfile/current.261.868735245 - modified
    Control File +DATA/db11g/controlfile/current.260.868735247 - modified
    Datafile +DATA/db11g/datafile/system.256.86873510 - dbid changed
    Datafile +DATA/db11g/datafile/sysaux.257.86873510 - dbid changed
    Datafile +DATA/db11g/datafile/undotbs1.258.86873510 - dbid changed
    Datafile +DATA/db11g/datafile/users.259.86873510 - dbid changed
    Datafile +DATA/db11g/tempfile/temp.268.86873527 - dbid changed
    Control File +DATA/db11g/controlfile/current.261.868735245 - dbid changed
    Control File +DATA/db11g/controlfile/current.260.868735247 - dbid changed
    Instance shut down

Database ID for database DB11G changed to 339029651.
All previous backups and archived redo logs for this database are unusable.
Database is not aware of previous backups and archived logs in Recovery Area.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database ID.
DBNEWID - Completed succesfully.


Troubleshooting a DBID Change Operation
=================================

If the DBNEWID utility succeeds in its validation stage but detects an error while changing the DBID, then the utility stops and leaves the database in the middle of the change. In this case, you cannot open the database until the DBNEWID operation is either completed or reverted. DBNEWID displays messages indicating the status of the operation.

Before continuing or reverting, fix the underlying cause of the error. Sometimes the only solution is to restore the whole database from a recent backup and perform recovery to the point in time before DBNEWID was started. This underscores the importance of having a recent backup available before running DBNEWID.

If you choose to continue the DBID change operation rather than revert it, reexecute your original command. The DBNEWID utility resumes and attempts to continue the change until all datafiles and control files have the new DBID. At this point, the database is left mounted. You should shut it down and then mount it again prior to opening it with the RESETLOGS option.

If you choose to revert a DBNEWID operation, and if the reversion succeeds, then DBNEWID reverts all performed changes and leaves the database in a mounted state.

To revert a stalled DBID change operation, run the DBNEWID utility again, specifying the REVERT keyword. For example:

% nid TARGET=SYS/oracle REVERT=YES LOGFILE=$HOME/nid.log


Troubleshooting a Database Name Change Operation
=========================================

If you specify that only the database name should be changed (and not the DBID), then the validation process is the same as for a DBID change except that DBNEWID checks only the control files. It does not read the datafiles. If the validation encounters a problem, then the database is left mounted.

It is possible for validation to succeed, but for the actual database name change to fail. The possible failure scenarios depend on how many control files are in the database, as follows:

If you have one or more control files and DBNEWID fails on the first control file, then the database name is not changed in the control file. You can either try the operation again or open the database and resume normal database use.
If you have more than one control file and DBNEWID fails on the second control file or on any one thereafter, then some control files will have the old DBNAME and some will have the new DBNAME. In this case, you must either manually copy the first changed control file to all CONTROL_FILES locations, or revert by copying the unchanged control files to all CONTROL_FILES locations.

Thursday, 25 December 2014

What is the workaround if you missed the "SWITCH DATAFILE ALL" after the RMAN command "RESTORE DATABASE"?

The following are the 2 solutions to rename the datafiles to the restored pathname :


problem script : 

run {
allocate channel c1 type disk;
allocate channel c2 type disk;

allocate channel c3 type disk;
set newname FOR DATAFILE 1 to '/some_path/datafile_name_1.dbf'
set newname FOR DATAFILE 2 to '/some_path/datafile_name_2.dbf'
set newname FOR DATAFILE 3 to '/some_path/datafile_name_3.dbf'
set newname FOR DATAFILE 4 to '/some_path/datafile_name_4.dbf'
set newname FOR DATAFILE 5  to '/some_path/datafile_name_5.dbf'
restore database;
switch datafile all;  --- You missed this step , your recovery will fail . How to solve the prob
recover database;
release channel c1;
release channel c2;

release channel c3;
}

Problem is that if you missed "Switch datafile all" in your recovery script , you cannot run this command manually from some  session other than your SET NEWNAME script session .


Solution#1. Issue the following command to rename the all datafiles to their restored pathname.

SQL> alter database rename file '{OLD_PATHNAME}' to '{NEW_PATHNAME}';

Solution#2. Catalog the restored datafiles as datafilecopies.

a. Catalog the datafilecopies. Make sure to replace the '{DIRECTORY}' with the location of the restored datafiles.

RMAN> catalog start with '{DIRECTORY}';

b. Afterward, switch to datafilecopies.

RMAN> switch database to copy;

Tuesday, 23 December 2014

Rename or move ASM datafile to different Diskgroup


Aim: To move datafile 4 to +USER_DATA asm diskgroup:


SQL> select file_id,file_name from dba_data_files;

   FILE_ID FILE_NAME
---------- -------------------------------------------
4 +DATA/racdb/datafile/users.259.866896399
3 +DATA/racdb/datafile/undotbs1.258.866896399
2 +DATA/racdb/datafile/sysaux.257.866896399
1 +DATA/racdb/datafile/system.256.866896397
5 +DATA/racdb/datafile/undotbs2.264.866897005

SQL> select name,free_mb,group_number from v$asm_diskgroup ;

NAME  FREE_MB GROUP_NUMBER
------------------------------ ---------- ------------
DATA      225     1
USER_DATA     4101     2
FRA         3999     3

SQL> ALTER DATABASE DATAFILE '+DATA/racdb/datafile/users.259.866896399' OFFLINE ;

Database altered.

RMAN> COPY DATAFILE '+DATA/racdb/datafile/users.259.866896399' TO '+USER_DATA' ;

Starting backup at 23-DEC-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=57 instance=racdb1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=+DATA/racdb/datafile/users.259.866896399
output file name=+USER_DATA/racdb/datafile/users.256.867064887 tag=TAG20141223T112114 RECID=1 STAMP=867064896
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:26
Finished backup at 23-DEC-14

SQL> ALTER DATABASE RENAME FILE '+DATA/racdb/datafile/users.259.866896399' TO '+USER_DATA/racdb/datafile/users.256.867064887' ;

Database altered.

SQL> RECOVER DATAFILE '+USER_DATA/racdb/datafile/users.256.867064887' ;

Media recovery complete.

SQL> ALTER DATABASE DATAFILE '+USER_DATA/racdb/datafile/users.256.867064887' online ;

Database altered.

 FILE_ID FILE_NAME STATUS
---------- ---------------------------------------------------------------------------------------------------------------
4    +USER_DATA/racdb/datafile/users.256.867064887 AVAILABLE
3 +DATA/racdb/datafile/undotbs1.258.866896399         AVAILABLE
2 +DATA/racdb/datafile/sysaux.257.866896399           AVAILABLE
1 +DATA/racdb/datafile/system.256.866896397 AVAILABLE
5 +DATA/racdb/datafile/undotbs2.264.866897005         AVAILABLE

Note:

 The steps provided above assume that the database is open and in Archivelog mode.
Besides these steps are not appropriated for system or sysaux datafiles. For System and Sysaux an approach similar to the one given below can be used
as per oracle support metalink :

1. Create a Copy of datafile in target Diskgroup:
RMAN> backup as copy tablespace system format '<New DG>';
RMAN> backup as copy tablespace sysaux format '<New DG>';
2. Then shutdown the database and restart to a mounted state
RMAN> shutdown immediate;
RMAN> startup mount;
3. switch the datafiles to the copy
RMAN> switch tablespace system to copy;
RMAN> switch tablespace sysaux to copy;
4. Recover the changes made to these tablespaces;
RMAN> recover database;

Also
make sure you run RMAN crosscheck copy and delete expired copy to update the controlfile and catalog for
your backups to run without issues.

Monday, 22 December 2014

Convert RAC DB to archive log mode

1. The following steps need to be taken to enable archive logging in a RAC database environment:
[oracle@node1 ~]$ srvctl stop database -d racdp

[oracle@node1 ~]$ srvctl status  database -d racdp

Instance racdp1 is not running on node node1
Instance racdp2 is not running on node node2

-- startup database in mount mode

[oracle@node1 ~]$ srvctl start database -d racdp  -o mount

[oracle@node1 ~]$ srvctl status  database -d racdp
Instance racdp1 is running on node node1
Instance racdp2 is running on node node2

SQl> select distinct name, instance_name ,host_name , log_mode,open_mode,version from gv$database,gv$instance;

NAME   INSTANCE_NAME    HOST_NAME  LOG_MODE   OPEN_MODE    VERSION
--------- ---------------- ----------------------------------- ---------- --------------- ---------- --------------- -----
RACDP   racdp1    node1.localdomain NOARCHIVELOG   MOUNTED          11.2.0.4.0
RACDP   racdp2    node2.localdomain NOARCHIVELOG   MOUNTED       11.2.0.4.0


-- enable archive logging

$ sqlplus / as sysdba
sql> alter database archivelog;

SQL> select distinct name, instance_name ,host_name , log_mode,open_mode,version from gv$database,gv$instance;

NAME   INSTANCE_NAME    HOST_NAME       LOG_MODE        OPEN_MODE       VERSION
--------- ---------------- ----------------------------------- --------------- --------------- -----------------
RACDP   racdp1    node1.localdomain         ARCHIVELOG      MOUNTED        11.2.0.4.0
RACDP   racdp2    node2.localdomain         ARCHIVELOG      MOUNTED        11.2.0.4.0


oracle@node1 ~]$ srvctl stop database -d  racdp

[oracle@node1 ~]$ srvctl status  database -d racdp

Instance racdp1 is not running on node node1
Instance racdp2 is not running on node node2

$ srvctl start database -d  racdp

[oracle@node1 ~]$ srvctl status  database -d racdp
Instance racdp1 is running on node node1
Instance racdp2 is running on node node2

NAME   INSTANCE_NAME    HOST_NAME            LOG_MODE        OPEN_MODE       VERSION
--------- ---------------- ----------------------------------- --------------- --------------- -----------------
RACDP   racdp1    node1.localdomain         ARCHIVELOG      READ WRITE       11.2.0.4.0
RACDP   racdp2    node2.localdomain         ARCHIVELOG      READ WRITE       11.2.0.4.0



SQL> Archive log list;

Database log mode        Archive Mode
Automatic archival        Enabled
Archive destination        USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     2
Next log sequence to archive   3
Current log sequence        3


You might need to set your log_archive_dest(_n) parameters to a shared location in each spfile, but the log_archive_start parameter does not need to be set anymore as of 10g

2. To disable archive logging, follow the same steps but use the NOARCHIVELOG clause of the ALTER DATABASE statement.

From 10.2 onwards, it is no longer required to modify cluster_database parameter to change archive log mode.
You no longer need to modify the CLUSTER_DATABASE parameter setting to change the archiving mode in Oracle RAC. You can change archive log mode as long as the database is mounted in the local instance and not open in any instances."

Saturday, 15 November 2014

How to check if your DB is open using spfile or pfile

If your DB is open using pfile:
-----------------------------------------

SELECT DECODE(value, NULL, 'PFILE', 'SPFILE') "Init File Type" 
   FROM sys.v_$parameter WHERE name = 'spfile';
--- PFILE

If your DB is open using SPFILE:
--------------------------------------------

SELECT DECODE(value, NULL, 'PFILE', 'SPFILE') "Init File Type" 
   FROM sys.v_$parameter WHERE name = 'spfile';
--SPFILE

Wednesday, 18 September 2013

Moving data (table and index) across tablespace

There are 2 methods we can use to do this.  One is to use a combination of "alter table X move tablespace Y" and "alter index X rebuild tablespace Y"  -- this works in Oracle8i release 8.1 and up ONLY.  Attached is a script called moveall.sql. 

Moveall.sql
set echo off

column order_col1 noprint
column order_col2 noprint

set heading off
set verify off
set feedback off
set echo off

spool tmp.sql

select decode( segment_type, 'TABLE',  segment_name, table_name ) order_col1,
             decode( segment_type, 'TABLE', 1, 2 ) order_col2,
      'alter ' || segment_type || ' ' || segment_name ||decode( segment_type, 'TABLE', ' move ', ' rebuild ' ) ||  chr(10) || ' tablespace &1 ' || chr(10) || ' storage ( initial ' || initial_extent || ' next ' ||
        next_extent || chr(10) || ' minextents ' || min_extents || ' maxextents ' || max_extents || chr(10) ||' pctincrease ' || pct_increase || ' freelists ' || freelists || ');'
from user_segments,

       (select table_name, index_name from user_indexes )
where segment_type in ( 'TABLE', 'INDEX' )
   and segment_name = index_name (+)
order by 1, 2
/

spool off

set heading on
set verify on
set feedback on
set echo on

REM UNCOMMENT TO AUTO RUN the generated commands
REM ELSE edit tmp.sql, modify as needed and run it
REM @tmp

--- eof ----


It uses the user_segments table to generate all of the needed "alter table move" and "alter index rebuild" statements to move a table/index into another tablespace preserving the storage characteristics currently assigned to the object.  For example, when we run moveall.sql in the SCOTT schema, we might see:

scott@ORACLE> @moveall
scott@ORACLE> set echo off

alter INDEX PK_DEPT rebuild
tablespace users
storage ( initial 10240 next 10240
minextents 1 maxextents 121
pctincrease 50 freelists 1);

....

It begins by moving a table and then rebuilding each of the indexes on that table.  Since the indexes on the tables being moved will become unusable after the table, this script rebuilds them right after moving a table -- before moving the next table (to reduce downtime).

Running the moveall.sql script is harmless as it is written.  It generates the SQL you need to run and saves the sql into yet another script file "tmp.sql".  You should edit tmp.sql, review it, modify it if you want (eg: if you have a multi-cpu system, you could modify the index rebuilds to be "parallel N", "unrecoverable" and add other options to make them go faster on your system), and then run it.

Another method would be to use EXPort and IMPort.  You would

o EXP the user account.
o drop all of the objects this user owns.  You can 'select' the drop statements you need
(script attached) in much the same way we 'select' the alter table/index statements
o revoke UNLIMITED TABLESPACE from the user
o alter the users default tablespace to the target tablespace
o give the user an unlimited quota on this new tablespace and their temporary tablespace
o IMP this users data.

So, the process to move SCOTT's objects from their current tablespace to a NEW_TABLESPACE
would be:

1) do an export of all of scott's objects.  Make sure no one modifies them after you begin this process.  You will lose these changes if they do.

   $ exp userid=scott/tiger owner=scott

2) you would drop all of scotts tables.  This will get the indexes as well.  I don't suggest dropping the user SCOTT but rather dropping scott's objects.  Dropping scott would cause any system priveleges SCOTT has to disappear and the import would not restore them.  This script can be used to drop someones tables:

--------------------------------------
set heading off
set feedback off
set verify off
set echo off

spool tmp.sql
select 'drop table &1..' || table_name || ' cascade constraints;'
  from dba_tables
where owner = upper('&1')
/
spool off
@tmp.sql
--------------------------------------



3) You would modify the user to *not* have unlimited tablespace (else the IMP will just put the objects right back into the tablespace they came from) and then give them unlimited quota's on the new tablespace you want the objects to go into and on their temporary tablespace (for the sorts the index creates will do)

alter user SCOTT default tablespace NEW_TABLESPACE
/
revoke unlimited tablespace from SCOTT
/
alter user SCOTT quota unlimited on NEW_TABLESPACE
/
alter user SCOTT quota unlimited on SCOTTS_TEMPORARY_TABLESPACE
/

4) you will IMP the data back in for that user.  IMP will rewrite the create statements to use the users default tablespace when it discovers that it cannot create the objects in their original tablespace.  Please make sure to review the file imp.log after you do this for any and all errors after you import.

imp userid=scott/tiger full=y ignore=y log=imp.log


5) you can optionally restore 'unlimited tablespace' to this user (or not).  If you do not, this user can only create objects in this new tablespace and temp (which in itselfis not a bad thing)...



As with any operation of this magnitude -- please test these procedures on a small test
account (such as SCOTT) to become familar with them.


A couple of side notes:

o the alter table move/alter index rebuild is more flexible and faster the exp/imp (and less error prone -- you never actually drop the objects).  Additionally, it would be easy to modify the script to move TABLES to one tablespace and INDEXES to a different tablespace.  The drawback to using this method is the you cannot move a table with a LONG or LONG RAW.  You must exp that table and imp it into a table.  You can do this easily  by exporting the table with the LONG/LONG RAW, dropping that table -- creating an empty version of this table in the new tablespace and importing just that table.

o if you use the exp/imp, it is upto you to ensure that no modifications happen to the tables after you begin the export.  There are no mechanisms in place to ensure this -- you must do this (else you will lose changes)



How the above code works:

select decode( segment_type, 'TABLE',
                       segment_name, table_name ) order_col1,
       decode( segment_type, 'TABLE', 1, 2 ) order_col2,
     
If the segment_type is a table, return the SEGMENT_NAME (which is actually the table
name).  Else, if the segment type is not a table (it is an index) return the TABLE_NAME
that the index is on.  This'll group a table and all of its indexes together. 

The second column just makes sure that tables are done PRIOR to their indexes.


Thursday, 7 March 2013

Identify Trace file related to an oracle process -The Easy Way

To find the trace file location/name assosiated with a particular PID use the below query:

select PID,spid,username,program,background,tracefile from v$process;

tracefile column will give you the required location.

Wednesday, 19 December 2012

SWITCH LOGFILE vs ARCHIVELOG CURRENT

 Oracle has two ways to force a logfile switch, ALTER SYSTEM SWITCH LOGFILE and ALTER SYSTEM ARCHIVELOG CURRENT. 
What is the difference between ALTER SYSTEM SWITCH LOGFILE and ALTER SYSTEM ARCHIVELOG CURRENT, and when do I use each?

Yes, both ALTER SYSTEM SWITCH LOGFILE and ALTER SYSTEM ARCHIVELOG CURRENT will force a log switch, but they do it in different ways!   
Both the SWITCH LOGFILE and ARCHIVELOG CURRENT write a quiesce checkpoint, a firm place whereby that last redo log is a part of the hot backup, but ARCHIVELOG CURRENT waits for the writing to complete.  This can take several minutes for multi-gigabyte redo logs.  
Conversely, the ALTER SYSTEM SWITCH LOGFILE command is very fast and returns control to the caller in less than a second while ALTER SYSTEM ARCHIVELOG CURRENT pauses.  
As we see below, the ALTER SYSTEM SWITCH LOGFILE is fast because it does not wait for the archiver process (ARCH) to complete writing the online redo log to the archivelog log filesystem:
  1. It issues database checkpoint
  2.  It immediately starts writing to the next redo log
  3.  In the background, the “switch logfile” command tells the ARCH background process to copy the “old” redo log file to the redo log filesystem.  
Here are the important differences between ALTER SYSTEM SWITCH LOGFILE and ALTER SYSTEM ARCHIVELOG CURRENT:
  •  RAC:  If you are running RAC, the ALTER SYSTEM ARCHIVELOG CURRENTwill switch the logs on all RAC nodes (instances), whereas ALTER SYSTEM SWITCH LOGFILE will only switch he logfile on the instance where you issue the switch command.  Hence, ALTER SYSTEM ARCHIVELOG CURRENT is a best practice for RAC systems.
  • ALTER SYSTEM  SWITCH LOGFILE is asynchronous:  This command is fast to return to the invoking program because the writing of the redo log to the OS filesystem is done in the background.  There is a very small risk in cases where the ARCH process cannot complete writing the redo log, such as cases where the OS archivelog file directory is out of space.  It is also risky because the calling script may move on to a subsequent step, assuming that the redo has been written.  Some scripts will place a SLEEP 60 command in their backup script to allow time for the redo to complete writing, but this is not a best practice.  
  • ALTER SYSTEM ARCHIVELOG CURRENT is synchronous:  This is faster to return because this command waits until the online redo log has completed the writing of the redo log file to the filesystem.  This command is safer because it waits for the OS to acknowledge (ACK) that the redo log has been successfully written.  Hence, ALTER SYSTEM ARCHIVELOG CURRENT is the best practice for production backup scripts with RMAN.
  • Argument required:  The ALTER SYSTEM ARCHIVELOG CURRENTallows you to specify the thread to archive while the ALTER SYSTEM SWITCH LOGFILE archives only the current thread.  If you do not pass the thread parameter, Oracle will archive all full online redo logs.   

Tuesday, 18 December 2012

Convert MSSM to automatic segment space management (ASSM)?


The segment space management that you specify at tablespace creation time applies to all segments subsequently created in the tablespace.

You cannot change the segment space management mode of a existing tablespace.

You cannot alter a locally managed tablespace to a locally managed temporary tablespace, nor can you change its method of segment space management.

To Convert the segment space management mode of a tablespace , you have to re-create the tablespace :
  1. Export the contents of the tablespace
  2. Drop the Tablespace which needed to be converted
  3. Create tablespace with the desired segment space management mode
  4. Import the contents of the the dump file to the newly created tablespace

Friday, 7 December 2012

ORA-01102: cannot mount database in EXCLUSIVE mode

SQL> Alter database mount;
Alter database mount
*
ERROR at line 1:
ORA-01102: cannot mount database in EXCLUSIVE mode
SQL>


Cause: An instance tried to mount the database in exclusive mode, but some other instance has already mounted the database in exclusive or parallel mode. 

Action: Either mount the database in parallel mode or shut down all other instances before mounting the database in exclusive mode. 
database is started in EXCLUSIVE mode by default. Therefore, the 
ORA-01102 error is misleading and may have occurred due to one of the 
following reasons: 
  • - there is still an "sgadef<sid>.dbf" file in the "ORACLE_HOME/dbs" directory 
  • - the processes for Oracle (pmon, smon, lgwr and dbwr) still exist 
  • - shared memory segments and semaphores still exist even though the database has been shutdown 
  • - there is a "ORACLE_HOME/dbs/lk<sid>" file 
The "lk<sid>" and "sgadef<sid>.dbf" files are used for locking shared memory.  It seems that even though no memory is allocated, Oracle thinks memory is  still locked. By removing the "sgadef" and "lk" files you remove any knowledge oracle has of shared memory that is in use. Now the database can start.

Solution:

SQL> shu immediate;
ORA-01507: database not mounted

ORACLE instance shut down.
SQL> exit;
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

[oracle@DBA-RHEL4-10G ~]$ ps -ef | grep ora_ | grep $ORACLE_SID

oracle 13123 1 0 02:29 ? 00:00:00 ora_pmon_test85
oracle 13125 1 0 02:29 ? 00:00:01 ora_psp0_test85
oracle 13127 1 0 02:29 ? 00:00:00 ora_mman_test85
oracle 13129 1 0 02:29 ? 00:00:22 ora_dbw0_test85
oracle 13131 1 0 02:29 ? 00:00:19 ora_lgwr_test85
oracle 13133 1 0 02:29 ? 00:02:07 ora_ckpt_test85
oracle 13135 1 0 02:29 ? 00:00:02 ora_smon_test85
oracle 13137 1 0 02:29 ? 00:00:00 ora_reco_test85
oracle 13139 1 0 02:29 ? 00:00:00 ora_cjq0_test85
oracle 13141 1 0 02:29 ? 00:00:01 ora_mmon_test85
oracle 13143 1 0 02:29 ? 00:00:02 ora_mmnl_test85
oracle 13145 1 0 02:29 ? 00:00:00 ora_d000_test85
oracle 13147 1 0 02:29 ? 00:00:00 ora_s000_test85
oracle 13151 1 0 02:29 ? 00:00:00 ora_qmnc_test85
oracle 13218 1 0 02:29 ? 00:00:00 ora_q001_test85
oracle 13220 1 0 02:29 ? 00:00:00 ora_q002_test85
oracle 18163 1 0 21:29 ? 00:00:00 ora_j000_test85
[oracle@DBA-RHEL4-10G ~]$
[oracle@DBA-RHEL4-10G ~]$ kill -9 <process-list>
[oracle@DBA-RHEL4-10G ~]$

Verify that the "$ORACLE_HOME/dbs/lk<sid>" file does not exist .If it is present copy it to some temp location for safety and delete it from the location  $ORACLE_HOME/dbs/

Now start the instance.

[oracle@DBA-RHEL4-11G dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Dec 6 21:32:46 2012

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 587202560 bytes
Fixed Size 2022504 bytes
Variable Size 163578776 bytes
Database Buffers 415236096 bytes
Redo Buffers 6365184 bytes
Database mounted.
SQL> Alter database open;

Database altered.

SQL>