Thursday, December 26, 2013

Oracle TDE - Transparent Data Encryption

Oracle TDE feature goes an extra step to secure data while datafiles on disk get compromised... a curtain raiser to this cool security feature.... hopefully can bring out few additions down this DBA drive...

   Click on the below document: 
Oracle TDE Doc-1

Tuesday, August 20, 2013

Retaining User's password

Quite a few times application owners request to keep the passwords same after refreshes.
Also in 11g it is observed in the view dba_users password column is blank. There is another view called "SYS.USER$", where in you can find the password column which is populated with a alpha-numeric value. This column is handy as the values (if stored) can be used to reset the password.


Let's take a shot at this.
Example:
I have a user called Scott & its password as "abc123"







Let us first query the dba_users view to see what the password column is






On querying the SYS.USER$ view, we get that piece of information which can be later used to reset it to the same password.



Lets expire the password so that user changes & we see how a new alpha-numeric value is generated, indicating password has been changed.


At this stage scott has a new password & we are in similiar situation to after a refresh where the application user(scott in this case) wishes to have it reset to same password. Like above if we had noted down the string we can use it as below to set it as previous password.




Hopefully with a little bit of planning & know-how this blog can help get back the previous password.



Sunday, August 11, 2013

Thursday, May 9, 2013

Baseline reports AWR


** creating Baseline -- fixed Baseline **

    set serveroutput on
    begin
    dbms_workload_repository.create_baseline(
    start_time => to_date('09-MAY-2013 00:00:00','DD-MON-YYYY HH24:MI:SS'),
    END_TIME => to_date('09-MAY-2013 07:00:00','DD-MON-YYYY HH24:MI:SS'),
    BASELINE_NAME =>'BASEPW1_DLY_WKLD_9MAY13',
    EXPIRATION => NULL);
    END;
   /


Wednesday, May 8, 2013

Getting metadata of a table

Use the DBMS_METADATA package's GET_DDL procedure to get DDL of the object

Snap above shows the usage of DBMS_METADATA.GET_DDL to get definition of table

SELECT DBMS_METADATA.GET_DDL('OBJECT_TYPE','OBJECT_NAME','OWNER') FROM DUAL;


Where 
OBJECT_TYPE   ----> table in above case
OBJECT_NAME ----> name of table
OWNER              ----> Owner of table.

Similary for Views


Saturday, May 4, 2013

Creating database silently with dbca

For a change creating database with silent option.
Set the environment variables to reflect the correct ORACLE_HOME


dbca -silent -createDatabase -templateName General_Purpose.dbc \
-gdbname maze -sid maze -responseFile NO_VALUE -sysPassword xxxxxx -systemPassword xxxxx \
-emConfiguration none -redoLogFileSize 100 -datafileDestination /u01/app/oracle/oradata1/maze -characterSet AL32UTF8 \
-totalMemory 300


Displaying silent creation of database


You sure have few options to create database!!!!

Wednesday, May 1, 2013

Exporting stats of a Schema from one database to another

Another experience to share. Transferring statistics from a schema to schema(same or different) on another database.

Source Database on lnx133

INSTANCE_NAME    HOST_NAME
---------------- -------------------------
maze             lnx133

Login to the source database as the user for which we want to collect statistics & transport it to another database. In our example it is user "scott".

SQL> conn scott/xxxxx;
Connected.
SQL> sho user
USER is "SCOTT"

-- Create a table to store statistics  by executing following procedure:
SQL> exec dbms_stats.create_stat_table('SCOTT', 'STATS');
PL/SQL procedure successfully completed.

In above statement --> SCOTT refers to a schema & STATS is the tablename.
Now we  are ready to collect statistics in the above created table 'STATS', we can collect statistics as follows:

SQL>  begin
    dbms_stats.export_schema_stats(ownname=>'SCOTT', stattab=>'STATS');
    end;
    /
PL/SQL procedure successfully completed.

--Notice the table is populated.
SQL> select count(*) from stats;

  COUNT(*)
----------
       182


Statistics are now stored in table & we can go ahead and do a export of this table which will allow us to transport it between different databases.

Use expdp utitlity to take a backup of SCOTT.STATS table
[oracle@lnx133 ~]$ expdp system/xxxx directory=TESTDIR dumpfile=stats.dmp logfile=stats.log tables=scott.stats
Export: Release 11.2.0.2.0 - Production on Wed May 1 17:50:49 2013

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLE_01":  system/******** directory=TESTDIR dumpfile=stats.dmp logfile=stats.log tables=scott.stats
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. . exported "SCOTT"."STATS"                              29.5 KB     182 rows
Master table "SYSTEM"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TABLE_01 is:
  /u01/app/oracle/backup/stats.dmp
Job "SYSTEM"."SYS_EXPORT_TABLE_01" successfully completed at 17:51:28


Export dump being ready let's transfer the dumpfile from source db server(lnx133) to destination db server (lnx144).
[oracle@lnx133 backup]$ scp stats.dmp lnx144:/u01/app/oracle/backup/.
oracle@lnx144's password:
stats.dmp                                                               100%  148KB 148.0KB/s   00:00
[oracle@lnx133 backup]$


Now on the destination database on lnx144 server, before we import the table using the dump file, lets delete the schema stats.

SQL> select instance_name, host_name from v$instance;
INSTANCE_NAME    HOST_NAME
---------------- -------------------------
demo             lnx144

SQL> conn scott
Enter password:
Connected.
SQL> sho user
USER is "SCOTT"

SQL> EXEC DBMS_STATS.delete_schema_stats('SCOTT');
PL/SQL procedure successfully completed.

Importing stats table in scott schema

oracle@lnx144 backup]$ impdp system/xxxx directory=testdir dumpfile=stats.dmp logfile=impstats.log tables=scott.stats

Import: Release 11.2.0.2.0 - Production on Wed May 1 18:09:14 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TABLE_01":  system/******** directory=testdir dump                                 file=stats.dmp logfile=impstats.log tables=scott.stats
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."STATS"                              29.5 KB     182 rows
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Job "SYSTEM"."SYS_IMPORT_TABLE_01" successfully completed at 18:09:26

Here we have 2 scenarios
A) If importing into a schema with same name then simply follow the next step.
SQL>  begin
    dbms_stats.import_schema_stats(OWNNAME=>'SCOTT', STATTAB=>'STATS');
    END;
    /
PL/SQL procedure successfully completed.


B) If importing into a schema that has a different name then, this is done as follows
Login as the user where the stats table was imported & issue the following sql
SQL> update stats set c5='NEW_SCHEMA_NAME';
SQL>commit;
Then import statistics.

SQL>  begin
    dbms_stats.import_schema_stats(OWNNAME=>'NEW_SCHEMA_NAME', STATTAB=>'STATS');
    END;
    /
PL/SQL procedure successfully completed.

I hope this post helps DBA folks to take care of one more thing.... .

Friday, April 26, 2013

RMAN DUPLICATE DATABASE

Source Server - lnx133
Source database name: maze
Destination Server -lnx144


Goal: to clone database 'maze' on lnx144.

On source side:
lnx133

Step 1:
Source database 'maze' is in archivelog mode, ready to take hot backup.
Take a full backup of source database
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;

SQL> Alter system switch logfile;



Step 2 : 
Ensure password file exists on the source database server (lnx133)

[oracle@lnx133 dbs]$ pwd
/u01/app/oracle/product/11g/11.2.0.2/dbhome_1/dbs
[oracle@lnx133 dbs]$ ls -ltr orapwmaze
-rw-r----- 1 oracle oinstall 1536 Apr 25 12:09 orapwmaze

Step3: 
Ensure service name is available in tnsnames.ora on target server (lnx144)

[oracle@lnx144 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11g/11.2.0.2/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

sourcemaze  =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.133)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = maze)
    )
  )


[oracle@lnx144 admin]$ tnsping sourcemaze
TNS Ping Utility for Linux: Version 11.2.0.2.0 - Production on 25-APR-2013 16:01:58
Copyright (c) 1997, 2010, Oracle.  All rights reserved.

Used parameter files:
/u01/app/oracle/product/11g/11.2.0.2/dbhome_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.133)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = maze)))
OK (0 msec)


Step4:

Create pfile, this step matters if we are dealing with different directory structure. In this run directory structure is identical, so simply copying the pfile from source to targe t(lnx144), will serve the purpose.

Based on this you can start instance in nomount. (env variables are to be set).


Step 5:

SQL> startup nomount;
ORACLE instance started.
Total System Global Area  422670336 bytes
Fixed Size                  1344616 bytes
Variable Size             327158680 bytes
Database Buffers           88080384 bytes
Redo Buffers                6086656 bytes

From source location copy the backup files (along with archivelog) to target server (at the same backup location on disk)



[oracle@lnx133 rman]$ scp H* 192.168.1.144:/u01/app/oracle/backup/rman/.
oracle@192.168.1.144's password:
Hotbkp_MAZE_4so7v8j8_1_1.bak                                                                           100%  264MB   8.8MB/s   00:30
Hotbkp_MAZE_4to7v8j9_1_1.bak                                                                           100%  251MB   6.8MB/s   00:37
Hotbkp_MAZE_4uo7v8j9_1_1.bak                                                                           100%  245MB   7.2MB/s   00:34
Hotbkp_MAZE_4vo7v8j9_1_1.bak                                                                           100%  217MB   7.5MB/s   00:29
Hotbkp_MAZE_50o7v94i_1_1.bak                                                                           100%  146MB   6.4MB/s   00:23
Hotbkp_MAZE_51o7v94j_1_1.bak                                                                           100%  197MB   6.2MB/s   00:32
Hotbkp_MAZE_52o7v94k_1_1.bak                                                                           100% 6656KB   6.5MB/s   00:01
Hotbkp_MAZE_53o7v94k_1_1.bak                                                                           100%   21MB   3.0MB/s   00:07
Hotbkp_MAZE_54o7v9ac_1_1.bak                                                                           100% 1168KB   1.1MB/s   00:00
Hotbkp_MAZE_55o7v9af_1_1.bak                                                                           100%  624KB 624.0KB/s   00:00
Hotbkp_MAZE_56o7v9em_1_1.bak                                                                           100% 6601KB   6.5MB/s   00:01
[oracle@lnx133 rman]$  scp ctl_n_spfile_c-1370075061-20130425-00 192.168.1.144:/u01/app/oracle/backup/rman/.
oracle@192.168.1.144's password:
ctl_n_spfile_c-1370075061-20130425-00                                                                  100% 9696KB   9.5MB/s   00:01

Step 6:
Required if you have a different directory structure 
(create same directories to have a consistent directory structure.

Step 7:
Environment is ready to start the duplicate database step.
[oracle@lnx144 dbs]$ rman target system/abc123@sourcemaze auxiliary /

Recovery Manager: Release 11.2.0.2.0 - Production on Thu Apr 25 16:54:32 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: MAZE (DBID=1370075061)
connected to auxiliary database: MAZE (not mounted)

RMAN> DUPLICATE TARGET DATABASE TO maze
  SPFILE
  NOFILENAMECHECK;2> 3>

Starting Duplicate Db at 25-APR-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=134 device type=DISK
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=10 device type=DISK
allocated channel: ORA_AUX_DISK_3
channel ORA_AUX_DISK_3: SID=135 device type=DISK
allocated channel: ORA_AUX_DISK_4
channel ORA_AUX_DISK_4: SID=11 device type=DISK

contents of Memory Script:
{
   set until scn  19416113;
   restore clone spfile to  '/u01/app/oracle/product/11g/11.2.0.2/dbhome_1/dbs/spfilemaze.ora';
   sql clone "alter system set spfile= ''/u01/app/oracle/product/11g/11.2.0.2/dbhome_1/dbs/spfilemaze.ora''";
}
executing Memory Script

executing command: SET until clause

Starting restore at 25-APR-13
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
using channel ORA_AUX_DISK_3
using channel ORA_AUX_DISK_4

WARNING: A restore time was estimated based on the supplied UNTIL SCN
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring SPFILE
output file name=/u01/app/oracle/product/11g/11.2.0.2/dbhome_1/dbs/spfilemaze.ora
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/rman/ctl_n_spfile_c-1370075061-20130425-00
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/backup/rman/ctl_n_spfile_c-1370075061-20130425-00 tag=TAG20130425T115818
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 25-APR-13

sql statement: alter system set spfile= ''/u01/app/oracle/product/11g/11.2.0.2/dbhome_1/dbs/spfilemaze.ora''

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''MAZE'' comment=
 ''duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''MAZE'' comment= ''duplicate'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     422670336 bytes

Fixed Size                     1344616 bytes
Variable Size                356518808 bytes
Database Buffers              58720256 bytes
Redo Buffers                   6086656 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''MAZE'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''MAZE'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile;
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''MAZE'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''MAZE'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     422670336 bytes

Fixed Size                     1344616 bytes
Variable Size                356518808 bytes
Database Buffers              58720256 bytes
Redo Buffers                   6086656 bytes

Starting restore at 25-APR-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=133 device type=DISK
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=10 device type=DISK
allocated channel: ORA_AUX_DISK_3
channel ORA_AUX_DISK_3: SID=134 device type=DISK
allocated channel: ORA_AUX_DISK_4
channel ORA_AUX_DISK_4: SID=11 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/rman/ctl_n_spfile_c-1370075061-20130425-00
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/backup/rman/ctl_n_spfile_c-1370075061-20130425-00 tag=TAG20130425T115818
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata1/maze/control01.ctl
output file name=/u01/app/oracle/oradata2/maze/control02.ctl
Finished restore at 25-APR-13

database mounted
RMAN-05538: WARNING: implicitly using DB_FILE_NAME_CONVERT
Using previous duplicated file /u01/app/oracle/oradata1/maze/system01.dbf for datafile 1 with checkpoint SCN of 19409868
Using previous duplicated file /u01/app/oracle/oradata1/maze/sysaux01.dbf for datafile 2 with checkpoint SCN of 19409867
Using previous duplicated file /u01/app/oracle/oradata1/maze/undotbs01.dbf for datafile 3 with checkpoint SCN of 19409869
Using previous duplicated file /u01/app/oracle/oradata2/maze/users01.dbf for datafile 4 with checkpoint SCN of 19409867
Using previous duplicated file /u01/app/oracle/oradata1/maze/example01.dbf for datafile 5 with checkpoint SCN of 19409870
Using previous duplicated file /u01/app/oracle/oradata1/maze/rcts01.dbf for datafile 6 with checkpoint SCN of 19410389
Using previous duplicated file /u01/app/oracle/oradata1/maze/undotbs02.dbf for datafile 7 with checkpoint SCN of 19410350
Using previous duplicated file /u01/app/oracle/oradata1/maze/appstbs_01.dbf for datafile 8 with checkpoint SCN of 19410350

contents of Memory Script:
{
   catalog clone datafilecopy  "/u01/app/oracle/oradata1/maze/system01.dbf",
 "/u01/app/oracle/oradata1/maze/sysaux01.dbf",
 "/u01/app/oracle/oradata1/maze/undotbs01.dbf",
 "/u01/app/oracle/oradata2/maze/users01.dbf",
 "/u01/app/oracle/oradata1/maze/example01.dbf",
 "/u01/app/oracle/oradata1/maze/rcts01.dbf",
 "/u01/app/oracle/oradata1/maze/undotbs02.dbf",
 "/u01/app/oracle/oradata1/maze/appstbs_01.dbf";
   switch clone datafile  1 to datafilecopy
 "/u01/app/oracle/oradata1/maze/system01.dbf";
   switch clone datafile  2 to datafilecopy
 "/u01/app/oracle/oradata1/maze/sysaux01.dbf";
   switch clone datafile  3 to datafilecopy
 "/u01/app/oracle/oradata1/maze/undotbs01.dbf";
   switch clone datafile  4 to datafilecopy
 "/u01/app/oracle/oradata2/maze/users01.dbf";
   switch clone datafile  5 to datafilecopy
 "/u01/app/oracle/oradata1/maze/example01.dbf";
   switch clone datafile  6 to datafilecopy
 "/u01/app/oracle/oradata1/maze/rcts01.dbf";
   switch clone datafile  7 to datafilecopy
 "/u01/app/oracle/oradata1/maze/undotbs02.dbf";
   switch clone datafile  8 to datafilecopy
 "/u01/app/oracle/oradata1/maze/appstbs_01.dbf";
}
executing Memory Script

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/system01.dbf RECID=11 STAMP=813689712
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/sysaux01.dbf RECID=12 STAMP=813689712
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/undotbs01.dbf RECID=13 STAMP=813689712
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata2/maze/users01.dbf RECID=14 STAMP=813689712
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/example01.dbf RECID=15 STAMP=813689712
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/rcts01.dbf RECID=16 STAMP=813689712
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/undotbs02.dbf RECID=17 STAMP=813689712
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/appstbs_01.dbf RECID=18 STAMP=813689712

datafile 1 switched to datafile copy
input datafile copy RECID=11 STAMP=813689712 file name=/u01/app/oracle/oradata1/maze/system01.dbf

datafile 2 switched to datafile copy
input datafile copy RECID=12 STAMP=813689712 file name=/u01/app/oracle/oradata1/maze/sysaux01.dbf

datafile 3 switched to datafile copy
input datafile copy RECID=13 STAMP=813689712 file name=/u01/app/oracle/oradata1/maze/undotbs01.dbf

datafile 4 switched to datafile copy
input datafile copy RECID=14 STAMP=813689712 file name=/u01/app/oracle/oradata2/maze/users01.dbf

datafile 5 switched to datafile copy
input datafile copy RECID=15 STAMP=813689712 file name=/u01/app/oracle/oradata1/maze/example01.dbf

datafile 6 switched to datafile copy
input datafile copy RECID=16 STAMP=813689712 file name=/u01/app/oracle/oradata1/maze/rcts01.dbf

datafile 7 switched to datafile copy
input datafile copy RECID=17 STAMP=813689712 file name=/u01/app/oracle/oradata1/maze/undotbs02.dbf

datafile 8 switched to datafile copy
input datafile copy RECID=18 STAMP=813689712 file name=/u01/app/oracle/oradata1/maze/appstbs_01.dbf

contents of Memory Script:
{
   set until scn  19416113;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 25-APR-13
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
using channel ORA_AUX_DISK_3
using channel ORA_AUX_DISK_4

starting media recovery

archived log for thread 1 with sequence 113 is already on disk as file /u01/archlogs/maze/1_113_811523932.arc
archived log for thread 1 with sequence 114 is already on disk as file /u01/archlogs/maze/1_114_811523932.arc
archived log file name=/u01/archlogs/maze/1_113_811523932.arc thread=1 sequence=113
archived log file name=/u01/archlogs/maze/1_114_811523932.arc thread=1 sequence=114
media recovery complete, elapsed time: 00:00:24
Finished recover at 25-APR-13
Oracle instance started

Total System Global Area     422670336 bytes

Fixed Size                     1344616 bytes
Variable Size                356518808 bytes
Database Buffers              58720256 bytes
Redo Buffers                   6086656 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''MAZE'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''MAZE'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     422670336 bytes

Fixed Size                     1344616 bytes
Variable Size                356518808 bytes
Database Buffers              58720256 bytes
Redo Buffers                   6086656 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "MAZE" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata1/maze/redo01.log', '/u01/app/oracle/oraredo2/maze/redo04.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oraredo2/maze/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oraredo2/maze/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata1/maze/system01.dbf'
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata1/maze/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata1/maze/sysaux01.dbf",
 "/u01/app/oracle/oradata1/maze/undotbs01.dbf",
 "/u01/app/oracle/oradata2/maze/users01.dbf",
 "/u01/app/oracle/oradata1/maze/example01.dbf",
 "/u01/app/oracle/oradata1/maze/rcts01.dbf",
 "/u01/app/oracle/oradata1/maze/undotbs02.dbf",
 "/u01/app/oracle/oradata1/maze/appstbs_01.dbf";
   switch clone datafile all;
   switch clone datafile  2 to datafilecopy
 "/u01/app/oracle/oradata1/maze/sysaux01.dbf";
   switch clone datafile  3 to datafilecopy
 "/u01/app/oracle/oradata1/maze/undotbs01.dbf";
   switch clone datafile  4 to datafilecopy
 "/u01/app/oracle/oradata2/maze/users01.dbf";
   switch clone datafile  5 to datafilecopy
 "/u01/app/oracle/oradata1/maze/example01.dbf";
   switch clone datafile  6 to datafilecopy
 "/u01/app/oracle/oradata1/maze/rcts01.dbf";
   switch clone datafile  7 to datafilecopy
 "/u01/app/oracle/oradata1/maze/undotbs02.dbf";
   switch clone datafile  8 to datafilecopy
 "/u01/app/oracle/oradata1/maze/appstbs_01.dbf";
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata1/maze/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/sysaux01.dbf RECID=1 STAMP=813689760
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/undotbs01.dbf RECID=2 STAMP=813689760
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata2/maze/users01.dbf RECID=3 STAMP=813689760
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/example01.dbf RECID=4 STAMP=813689760
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/rcts01.dbf RECID=5 STAMP=813689760
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/undotbs02.dbf RECID=6 STAMP=813689760
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata1/maze/appstbs_01.dbf RECID=7 STAMP=813689760


datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=813689760 file name=/u01/app/oracle/oradata1/maze/sysaux01.dbf

datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=813689760 file name=/u01/app/oracle/oradata1/maze/undotbs01.dbf

datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=813689760 file name=/u01/app/oracle/oradata2/maze/users01.dbf

datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=813689760 file name=/u01/app/oracle/oradata1/maze/example01.dbf

datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=813689760 file name=/u01/app/oracle/oradata1/maze/rcts01.dbf

datafile 7 switched to datafile copy
input datafile copy RECID=6 STAMP=813689760 file name=/u01/app/oracle/oradata1/maze/undotbs02.dbf

datafile 8 switched to datafile copy
input datafile copy RECID=7 STAMP=813689760 file name=/u01/app/oracle/oradata1/maze/appstbs_01.dbf
Reenabling controlfile options for auxiliary database
Executing: alter database add supplemental log data

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 25-APR-13
RMAN>exit


SQL> select instance_name, host_name, status from v$instance;

INSTANCE_NAME    HOST_NAME                 STATUS
---------------- ------------------------- ------------
maze             lnx144                    OPEN


Your cloned database is ready to  use!!!




Thursday, April 25, 2013

Remotely connecting to database with "sysdba" privilege

Remote login to a database with "sysdba" privileges.

I have two servers lnx133 & lnx144.
Goal is to be on server lnx144 & connect to database on lnx133 with a user having sysdba system privilege.
DB server lnx133 
Details:
lnx133 server has a database "maze"
lnx144 is remote server
password file --> found in $ORACLE_HOME/dbs needs to have an entry for the user with which we intend to remotely login.,

example "system"
On lnx133

SQL> grant sysdba to system;
Grant succeeded.


Below query gives confirmation
SQL> select * from v$pwfile_users;

USERNAME                       SYSDB SYSOP SYSAS
------------------------------                     ----- ----- -----
SYS                                     TRUE  TRUE  FALSE
SYSTEM                            TRUE  FALSE FALSE

You can also use strings command to read the binary file.
[oracle@lnx133 dbs]$ strings orapwmaze
]\[Z
ORACLE Remote Password file
INTERNAL
FB16A89DB241980E
c+'spTtN
F3A63E088B7E19ED
#fGF`B
SYSTEM
1A2A51E8BB0B485D

From any remote server ( in our case lnx144), I can use the following syntax to login to maze@lnx133 with "sysdba" privilege.
Note: we would need the entry in tnsnames.ora@lnx144 to be able to resolve to the database 'maze'@lnx133.

[oracle@lnx144 ~]$ tnsping maze
TNS Ping Utility for Linux: Version 11.2.0.2.0 - Production on 25-APR-2013 12:20:30
Copyright (c) 1997, 2010, Oracle.  All rights reserved.

Used parameter files:
/u01/app/oracle/product/11g/11.2.0.2/dbhome_1/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.133)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = maze)))
OK (0 msec)

Now we are ready to connect to remote database 'maze' on lnx133.

[oracle@lnx144 ~]$ sqlplus system/abc123@maze as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Thu Apr 25 12:21:02 2013
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select instance_name, host_name, status from v$instance;

INSTANCE_NAME    HOST_NAME                 STATUS
----------------                  -------------------------          ------------
maze                       lnx133                                OPEN


So why would we need a user to login with sysdba system privilege? 
Well sysdba system privilege gives user privileges to startup, shutdown, create, drop, alter database (mount, open,  recover, backup, archivelog, restrict session..... )

To test with another user scott who doesn't have "sysdba" system privilege.
[oracle@lnx144 ~]$ sqlplus scott/abc123@maze
SQL*Plus: Release 11.2.0.2.0 Production on Thu Apr 25 12:24:09 2013
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shut immediate;
ORA-01031: insufficient privileges
SQL> exit

Now lets try the same with a user "system" which has "sysdba" privilge.
[oracle@lnx144 ~]$ sqlplus system/abc123@maze as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Thu Apr 25 12:29:51 2013

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

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

Another important thing to be able to start up database by remote connection is only possible if you have a static entry in listener.ora (lnx133 in our case)... if you don't then you will be greeted by this error.
[oracle@lnx144 ~]$ sqlplus system/abc123@maze as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Thu Apr 25 13:03:21 2013
Copyright (c) 1982, 2010, Oracle.  All rights reserved.

ERROR:
ORA-28547: connection to server failed, probable Oracle Net admin error

Update the static entry & reloaded listener, listener.ora now looks as follows
[oracle@lnx133 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11g/11.2.0.2/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
     (SID_DESC =
        (ORACLE_HOME = /u01/app/oracle/product/11g/11.2.0.2/dbhome_1)
          (SID_NAME = maze)
     )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = lnx133)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

Ready to start database remotely
[oracle@lnx144 ~]$ sqlplus system/abc123@maze as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Thu Apr 25 13:10:25 2013
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
Connected to an idle instance.

SQL> startup;
ORACLE instance started.

Total System Global Area  422670336 bytes
Fixed Size                  1344616 bytes
Variable Size             335547288 bytes
Database Buffers           79691776 bytes
Redo Buffers                6086656 bytes
Database mounted.
Database opened.

SQL> select instance_name, host_name, status from v$instance;

INSTANCE_NAME    HOST_NAME                 STATUS
----------------                 -------------------------          ------------
maze                              lnx133                      OPEN

SQL> sho user
USER is "SYS"


I hope it helps.....administering remote databases!!!!








Thursday, April 18, 2013

Using Datapump to move a table from Production to Development Database

Yeah nothing special but good to have it in here, hopefully beginners could get some help.

Prod -->
Take a backup at source database (in this case Production)
expdp username/password directory=dumpdir dumpfile=somefilename.dmp logfile=somefilename.log tables=schema.table_name

successful execution of the expdp command will create dump files in the directory "dmpdir" pointing to a location on disk(server).
scp those files from source to target (development database in our case).
$scp *dmp targetserver:/location_on_server

use the above dumps to import the tables in an existing same schema with a new name

impdp username/password directory=dmpdir dumpfile=abovedumpfilename.dmp logfile=somefilename.log
tables=earlier_username.table_name remap_table=earlier_username.table_name:new_table_name

Also if there are multiple dumpfiles you could use the following syntax

impdp username/password directory=dmpdir dumpfile=abovedumpfilename%U.dmp logfile=somefilename.log tables=earlier_username.table_name remap_table=earlier_username.table_name:new_table_name






Sunday, April 14, 2013

Grid Installation on standalone Server



I hope this will help people with Grid Installation on standalone server, please leave in your comments to make this better.



Wednesday, April 10, 2013

Auto-start/stop of Oracle databases on RHEL 5

To configure Oracle databases to auto-start/stop by having the entry in /etc/oratab set to Y, requires some details to be worked on linux side. Following would require "root" privileges or co-ordination with system administrator.

Here are the steps to enable that configuration.
Step 1) Set the 3rd field in /etc/oratab to "Y" >>> this enables to oracle databases to auto-start

Step 2) As "root" user create a script dbora at following location >>> /etc/init.d
script name --> dbora
contents are as below

#!/bin/bash
# chkconfig: 35 99 10  
# Script to start and stops Oracle processes
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
#
ORA_HOME= /app/oracle/product/11.2/dbhome_1
ORA_OWNER=oracle

case "$1" in
   'start')
      # Start the TNS Listener
      su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
      # Start the Oracle databases:
      # The following command assumes that the oracle login
      # will not prompt the user for any values
      su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
      touch /var/lock/subsys/dbora
      ;;

   'stop')
       # Stop the TNS Listener
      su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
      # Stop the Oracle databases:
      # The following command assumes that the oracle login
      # will not prompt the user for any values
      su - $ORA_OWNER -c $ORA_HOME/bin/dbshut
      rm -f /var/lock/subsys/dbora
      ;;
esac
# End of script dbora


The above script can include other components which might be called upon to start/stop in appropriate order. Here they only start/stop listener & database.

Step 3) Set script permissions:
chmod 755 /etc/init.d/dbora

Step 4) Register the Service /sbin/chkconfig --add dbora
This deals with just a simple set up, some variations may be encountered while you are dealing with different release of Oracle databases on same server & if databases are using ASM.