Friday 9 September 2011

How to change SYSMAN user password in 11gr1 on linux (oracle enterprise respository)


Changing SYSMAN user password.

OS Linux
Oracle 11gr1


Steps:
1. stop oem services
2. check db control is stopped
3. connect to the database as a user with DBA privilege and change sysman password
4. connect with new password to check
5. go to $ORACLE_HOME/bin directory and execuate emctl setpasswd command

Details:
stop dbconsole services
[oracle@testorapd bin]$ ./emctl stop dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
https://testorapd.dummy.local:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 11g Database Control ...
 ...  Stopped.

check dbconsole services stopped properly
[oracle@testorapd bin]$ ./emctl status dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
https://testorapd.dummy.local:1158/em/console/aboutApplication
Oracle Enterprise Manager 11g is not running.

connect with DBA privilege user and change sysman password
[oracle@testorapd bin]$ ./sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Sep 8 13:37:07 2011

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


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

SQL> alter user sysman identified by oracle;

User altered.

SQL> --check new password to connect sysman with new password
SQL> conn sysman/oracle
Connected.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr                                                                             oduction
With the Partitioning, OLAP, Data Mining and Real Application Testing options

execute emctl setpasswd command to set new password in oem repository.

[oracle@testorapd bin]$ ./emctl setpasswd dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
https://testorapd.dummy.local:1158/em/console/aboutApplication
Please enter new repository password:
Repository password successfully updated.

start dbconsole services
[oracle@testorapd bin]$ ./emctl start dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
https://testorapd.dummy.local:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control ...... started.
------------------------------------------------------------------
Logs are generated in directory /db/product/11.2.0/dbhome_1/testorapd.dummy.                                                                             local_oramfe/sysman/log

NOTE: Same steps also applicable for WINDOWS platform.

How to Migrate From Database File system to ASM | Managing Database in ASM

TO Migrate the database files from disk
to asm disk is as follows,

1.configure flash recovery area.
2.Migrate datafiles to ASM.
3.Control file to ASM.
4.Create Temporary tablespace.
5.Migrate Redo logfiles
6.Migrate spfile to ASM.


step 1:Configure flash recovery area.

SQL> connect sys/sys@prod1 as sysdba
Connected.
SQL> alter database disable block change tracking;

Database altered.

SQL> alter system set db_recovery_file_dest_size=500m;

System altered.

SQL> alter system set db_recovery_file_dest=’+RECOVERYDEST’;

System altered


step 2 and 3: Migrate data files and control file
to ASM. 

use RMAN to migrate the data files to ASM disk groups.
All data files will be migrated to the newly created disk group, DATA

SQL> alter system set db_create_file_dest='+DATA';

System altered.

SQL> alter system set control_files='+DATA/ctf1.dbf' scope=spfile;

System altered.

SQL> shu immediate

[oracle@rac1 bin]$ ./rman target /


RMAN> startup nomount

Oracle instance started


RMAN> restore controlfile from '/u01/new/oracle/oradata/mydb/control01.ctl';

Starting restore at 08-DEC-09

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=146 device type=DISK

channel ORA_DISK_1: copied control file copy

output file name=+DATA/ctf1.dbf

Finished restore at 08-DEC-09

RMAN> alter database mount;

database mounted

released channel: ORA_DISK_1

RMAN> backup as copy database format '+DATA';
Starting backup at 08-DEC-09

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=146 device type=DISK

channel ORA_DISK_1: starting datafile copy

input datafile file number=00001 name=/u01/new/oracle/oradata/mydb/system01.dbf

output file name=+DATA/mydb/datafile/system.257.705063763 tag=TAG20091208T110241 RECID=1 STAMP=705064274

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:08:39

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002 name=/u01/new/oracle/oradata/mydb/sysaux01.dbf

output file name=+DATA/mydb/datafile/sysaux.258.705064283 tag=TAG20091208T110241 RECID=2 STAMP=705064812

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:08:56

channel ORA_DISK_1: starting datafile copy

input datafile file number=00003 name=/u01/new/oracle/oradata/mydb/undotbs01.dbf

output file name=+DATA/mydb/datafile/undotbs1.259.705064821 tag=TAG20091208T110241 RECID=3 STAMP=705064897

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:25

channel ORA_DISK_1: starting datafile copy

copying current control file

output file name=+DATA/mydb/controlfile/backup.260.705064907 tag=TAG20091208T110241 RECID=4 STAMP=705064912

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004 name=/u01/new/oracle/oradata/mydb/users01.dbf

output file name=+DATA/mydb/datafile/users.261.705064915 tag=TAG20091208T110241 RECID=5 STAMP=705064915

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 08-DEC-09

channel ORA_DISK_1: finished piece 1 at 08-DEC-09

piece handle=+DATA/mydb/backupset/2009_12_08/nnsnf0_tag20091208t110241_0.262.705064919 tag=TAG20091208T110241 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 08-DEC-09

RMAN> switch database to copy;

datafile 1 switched to datafile copy "+DATA/mydb/datafile/system.257.705063763"

datafile 2 switched to datafile copy "+DATA/mydb/datafile/sysaux.258.705064283"

datafile 3 switched to datafile copy "+DATA/mydb/datafile/undotbs1.259.705064821"

datafile 4 switched to datafile copy "+DATA/mydb/datafile/users.261.705064915"

RMAN> alter database open;
database opened

RMAN> exit

Recovery Manager complete.


SQL> conn sys/oracle as sysdba

Connected.

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME

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

USERS                          +DATA/mydb/datafile/users.261.705064915

UNDOTBS1                       +DATA/mydb/datafile/undotbs1.259.705064821

SYSAUX                         +DATA/mydb/datafile/sysaux.258.705064283

SYSTEM                         +DATA/mydb/datafile/system.257.705063763



SQL> select name from v$controlfile;


NAME
----

+DATA/ctf1.dbf

NO       16384            594

step 4:Migrate temp tablespace to ASM.

SQL> alter tablespace temp add tempfile size 100m;

Tablespace altered.

SQL> select file_name from dba_temp_files;

FILE_NAME

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

+DATA/mydb/tempfile/temp.263.705065455

otherwise,
Create temporary tablespace in ASM disk group.

SQL> CREATE TABLESPACE temp1 TEMPFILE ‘+diskgroup1’;

SQL> alter database default temporary tablespace temp1;

Database altered.


step 5:Migrate redo logs to ASM.

SQL> select member,group# from v$logfile;

MEMBER                                                 GROUP#

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

/u01/new/oracle/oradata/mydb/redo03.log                     3

/u01/new/oracle/oradata/mydb/redo02.log                     2

/u01/new/oracle/oradata/mydb/redo01.log                     1

SQL> alter database add logfile group 4 size 5m;

Database altered.

SQL> alter database add logfile group 5 size 5m;

Database altered.

SQL> alter database add logfile group 6 size 5m;

Database altered.

SQL> select member,group# from v$logfile;

MEMBER                                                 GROUP#

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

/u01/new/oracle/oradata/mydb/redo03.log                     3

/u01/new/oracle/oradata/mydb/redo02.log                     2

/u01/new/oracle/oradata/mydb/redo01.log                     1

+DATA/mydb/onlinelog/group_4.264.705065691                  4

+DATA/mydb/onlinelog/group_5.265.705065703                  5

+DATA/mydb/onlinelog/group_6.266.705065719                  6

SQL> alter system switch logfile;

System altered.

SQL> alter database drop logfile group 2;

Database altered.

SQL> alter database drop logfile group 3;

Database altered.

SQL> alter database drop logfile group 4;

Database altered.

SQL> alter database drop logfile group 1;

Database altered.
Add additional control file.
If an additional control file is required for redundancy,
you can create it in ASM as you would on any other filesystem.
SQL> connect sys/sys@prod1 as sysdba
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.

SQL> alter database backup controlfile to '+DATA/cf2.dbf';

Database altered.

SQL> alter system set control_files='+DATA/cf1.dbf '
,'+DATA/cf2.dbf' scope=spfile;

System altered.

SQL> shutdown immediate;
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

SQL> select name from v$controlfile;

NAME
---------------------------------------
+DATA/cf1.dbf
+DATA/cf2.dbf

step 6:Migrate spfile to ASM:

Create a copy of the SPFILE in the ASM disk group.
In this example, the SPFILE for the migrated database will be stored as +DISK/spfile.

If the database is using an SPFILE already, then run these commands:

run {
BACKUP AS BACKUPSET SPFILE;
RESTORE SPFILE TO "+DISK/spfile";
}


If you are not using an SPFILE, then use CREATE SPFILE
from SQL*Plus to create the new SPFILE in ASM.
For example, if your parameter file is called /private/init.ora,
use the following command:

SQL> create spfile='+DISK/spfile' from pfile='/private/init.ora';


After successfully migrating all the data files
over to ASM, the old data files are no longer
needed and can be removed. Your single-instance
database is now running on ASM!

Converting Single instance to RAC instance Database Using DBCA

There are different ways to convert a single instance database to RAC.
1) Manual Method
2) Using rconfig
3) Using DBCA
4) Using grid control
In this post we will see step by step method to convert a single instance database to RAC Using DBCA(Database Configuration Assitant).

In this example, I already configured two node oracle asm, clusterware homes. also i already converted the file system from non-asm to asm
For converting filesystem to ASM click the link above.

follow steps for creating a template to convert a single instance to rac instance.

[oracle@rac1 ~]$ dbca &
 
Screen NameResponse
Welcome ScreenSelect Single Instance database.
OperationsSelect Manage Templates.
Template management operationSelect From an existing database(structure as well as data).
Choose the databaseSelect Database instance: testing
Specify the name and descriptionexample: testing and descriptiontesting_database_convert_from_single_to_rac_instance_database
specify whether you want to convert
all database
 related file locations to OFA,
or You want to main the file
locations in the template.
Select Maintain the file locations.  and click FINISH.
The following operations
will be performed:
create a clone template from
the source database.
click ok
Do you want to perform
another operation
Click No to EXIT


Templates for existing single instance database has been created.

Go to $ORACLE_HOME/assistants/dbca/templates and check generated backup of single instance.

[oracle@rac1 templates]$ pwd
/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates
[oracle@rac1 templates]$ ls -ltr
total 213584
-rw-r-----  1 oracle oinstall    12050 May 16  2005 New_Database.dbt
-rw-r-----  1 oracle oinstall     5728 Jun 30  2005 Data_Warehouse.dbc
-rw-r-----  1 oracle oinstall     5665 Jun 30  2005 Transaction_Processing.dbc
-rw-r-----  1 oracle oinstall     5608 Jun 30  2005 General_Purpose.dbc
-rwxr-xr-x  1 oracle oinstall  7061504 Jul  2  2005 Seed_Database.ctl
-rwxr-xr-x  1 oracle oinstall 93569024 Jul  2  2005 Seed_Database.dfb
-rwxr-xr-x  1 oracle oinstall   991232 Jul  2  2005 example.dmp
-rwxr-xr-x  1 oracle oinstall 13017088 Jul  2  2005 example01.dfb
-rw-r-----  1 oracle oinstall 96714752 Jul 27 13:47 testing.dfb
-rw-r-----  1 oracle oinstall  7061504 Jul 27 13:47 testing.ctl
-rw-r-----  1 oracle oinstall     5349 Jul 27 13:49 testing.dbc

Copy the pre-configured database image from rac1 machine $ORACLE_HOME/assistants/ dbca/ templates/ testing.dbf & testing.dbc    to  host rac2 environment  $ORACLE_HOME/assistants/dbca/templates/ folder

[oracle@rac1 templates]$ scp testing.dfb oracle@rac2:/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates/
testing.dfb                                   100%   92MB   2.5MB/s   00:37
[oracle@rac1 templates]$ scp testing.dbc oracle@rac2:/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates/
testing.dbc                                   100% 5349     5.2KB/s   00:00
[oracle@rac1 templates]$ scp testing.ctl oracle@rac2:/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates/
testing.ctl                                   100% 6896KB   2.2MB/s   00:03
[oracle@rac2 templates]$ pwd
/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates
[oracle@rac2 templates]$ ls -ltr
-rw-r-----  1 oracle oinstall 96714752 Jul 27 14:24 testing.dfb
-rw-r-----  1 oracle oinstall     5349 Jul 27 14:26 testing.dbc
-rw-r-----  1 oracle oinstall  7061504 Jul 27 14:26 testing.ctl
Start the dbca to convert the single instance to rac single database.
[oracle@rac2 templates]$ dbca &

Screen NameResponse
Welcome to the Database
configuration assitant
Select Oracle Real Application Database
Select the operationselect : create a database
Select the nodes on which you
want to create the cluster
database
Select select all.
Select a template from the
following list to create
the database:
Select the template: testing(template name created by you)
  
Select the
Global database name
and SID:
  Type name as you want, eg: raj.
Each oracle database may be managed
centrally using the Oracle Enterprise
Manager Grid Control or locally using
the Enterprise Manager Database Control.
Choose the management option that you
would like to use to manage this
database.

   Select:  configure the database with enterprise manager
   
For security reasons, you must specify
password for the following user
accounts in the new database.
select: Use the same password for ALL accounts password:yourpassword confirm password: yourpassword
Select the ListenersSelect:Register this database with all listeners
Select the storage mechanismSelect: Automatic Storage Management(ASM)
select the disk groups to be used as
storage for the database.
Select the disk group names: eg: DATA
Specify locations for the database
files to be created.
Select:  use Oracle-Managed Files
Choose the recovery options uncheck all
Custom ScriptsSelect: No scripts to run
Oracle Database Services DetailsClick: Next
Initialization ParametersClick: Next
Database storageClick: Next
creation optionsclick: Finish

[oracle@rac2 templates]$ vi /etc/oratab
edit the oratab file for instances raj as raj1 and raj2 on both nodes
[oracle@rac2 templates]$ . oraenv
ORACLE_SID = [oracle] ? raj2
[oracle@rac2 templates]$ sqlplus '/as sysdba'
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jul 27 19:37:27 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options
SQL> select instance_name from gv$instance;
INSTANCE_NAME
----------------
raj2
raj1

hope, this helps you.

Tuesday 2 August 2011

SQL Loader



SQL LOADER utility is used to load data from other data source into Oracle. For example, if you have a table in FOXPRO, ACCESS or SYBASE or any other third party database, you can use SQL Loader to load the data into Oracle Tables. SQL Loader will only read the data from Flat files. So If you want to load the data from Foxpro or any other database, you have to first convert that data into Delimited Format flat file or Fixed length format flat file, and then use SQL loader to load the data into Oracle.
Following is procedure to load the data from Third Party Database into Oracle using SQL Loader.
  1. Convert the Data into Flat file using third party database command.
  2. Create the Table Structure in Oracle Database using appropriate datatypes
  3. Write a Control File, describing how to interpret the flat file and options to load the data.
  4. Execute SQL Loader utility specifying the control file in the command line argument
To understand it better let us see the following case study.
Suppose you have a table in MS-ACCESS by name EMP, running under Windows O/S, with the following structure
     EMPNO     INTEGER
     NAME       TEXT(50)
     SAL        CURRENCY
     JDATE      DATE
This table contains some 10,000 rows. Now you want to load the data from this table into an Oracle Table. Oracle Database is running in LINUX O/S.
Solution
Steps
Start MS-Access and convert the table into comma delimited flat (popularly known as csv) , by clicking on File/Save As menu. Let the delimited file name be emp.csv
  1. Now transfer this file to Linux Server using FTP command
    1. Go to Command Prompt in windows
    2. At the command prompt type FTP followed by IP address of the server running Oracle.
FTP will then prompt you for username and password to connect to the Linux Server. Supply a valid username and password of Oracle User in Linux
For example:-C:\>ftp 200.200.100.111
Name: oracle
Password:oracle
FTP>
    1. Now give PUT command to transfer file from current Windows machine to Linux machine.
FTP>put
Local file:C:\>emp.csv
remote-file:/u01/oracle/emp.csv
File transferred in 0.29 Seconds
FTP>
    1. Now after the file is transferred quit the FTP utility by typing bye command.
FTP>bye
Good-Bye
  1. Now come the Linux Machine and create a table in Oracle with the same structure as in MS-ACCESS by taking appropriate datatypes. For example,  create a table like this
$sqlplus scott/tiger
SQL>CREATE TABLE emp (empno number(5),
                name varchar2(50),
                sal  number(10,2),
                jdate date);
  1. After creating the table, you have to write a control file describing the actions which SQL Loader should do. You can use any text editor to write the control file. Now let us write a controlfile for our case study
$vi emp.ctl
1        LOAD DATA
2        INFILE     ‘/u01/oracle/emp.csv’
3        BADFILE         ‘/u01/oracle/emp.bad
4        DISCARDFILE     ‘/u01/oracle/emp.dsc’
5        INSERT INTO TABLE emp
6        FIELDS TERMINATED BY “,” OPTIONALLY ENCLOSED BY ‘”’ TRAILING NULLCOLS
7        (empno,name,sal,jdate date ‘mm/dd/yyyy’)
Notes: (Do not write the line numbers, they are meant for explanation purpose)
1.       The LOAD DATA statement is required at the beginning of the control file.
2.       The INFILE option specifies where the input file is located
3.       Specifying BADFILE is optional. If you specify,  then bad records found during loading will be stored in this file.
4.       Specifying DISCARDFILE is optional. If you specify, then records which do not meet a WHEN condition will be written to this file.
5.       You can use any of the following loading option
1.       INSERT : Loads rows only if the target table is empty
2.       APPEND: Load rows if the target table is empty or not.
3.       REPLACE: First deletes all the rows in the existing table and then, load rows.
4.       TRUNCATE: First truncates the table and then load rows.
6.       This line indicates how the fields are separated in input file. Since in our case the fields are separated by “,” so we have specified “,” as the terminating char for fields. You can replace this by any char which is used to terminate fields. Some of the popularly use terminating characters are semicolon “;”, colon “:”, pipe “|” etc. TRAILING NULLCOLS means if the last column is null then treat this as null value, otherwise,  SQL LOADER will treat the record as bad if the last column is null.
7.        In this line specify the columns of the target table. Note how do you specify format for Date columns
  1. After you have wrote the control file save it and then, call SQL Loader utility by typing the following command
$sqlldr userid=scott/tiger control=emp.ctl log=emp.log
After you have executed the above command SQL Loader will shows you the output describing how many rows it has loaded.
The LOG option of sqlldr specifies where the log file of this sql loader session should be created.  The log file contains all actions which SQL loader has performed i.e. how many rows were loaded, how many were rejected and how much time is taken to load the rows and etc. You have to view this file for any errors encountered while running SQL Loader.

Monday 4 July 2011

How to find out oracle databases present in system|how to log in as DBA in any database by command prompt


Hello friends,This is out first tutorial on basic oracle. Here we will study how to find out which oracle databses are present in out system,and how to login in any one of them as SYSDBA without even opening the Oracle EM or isqlplus software.
Before going to the steps ,I would like to tell the beginners that SYSDBA or SYSTEM are the users which operate the database,They have all the administrative privileges of the database.
Now coming to the steps:-
Steps:
Find out the oracle databases present:
1)Got to Start\Control Panel\All Control Panel Items\Administrative Tools\Services
2) Under services search for OracleService prefix followed by the database name files.
3)Each such file corrosponds to one Oracle Database.
Note:- When you will install Oracle 10g, The DBCA(Database Configuration Assistant) will automatically create a default database named ORCL.
4)The snapshot below shows that there is only one file named-“OracleServiceOrcl”,this conclude that there is only one default database named Orcl.

                                                                             [click to enlarge the snapshot]

This was how to find out the oracle databases in system with easy steps.


Now coming to How to login in any Database as DBA(sys or system)
Steps:-
1)The SYSDBA always login through Command Prompt.
2)So open Cmd by pressing Win_button+R soft key in the keyboard  and typing cmd in run window.
3) Now in Cmd type the following code :-
C:\>set oracle_sid=orcl
C:\>sqlplus /nolog
Sql>conn /as sysdba
4) after this the user will be connected to oracle database as SYSDBA.and it will show connectes status as shown in snapshot below:-

                                                                              [click to enlarge the snapshot]

5) Now, if you want to cross check which user is logged in.
Just type as below:-
Sql> show user
6)It will return the current username as  user is “SYS”
As shown in the snapshot.

                                                                             [click to enlarge the snapshot]

So, now you have been logged in as sysdba to the ORCL database.Now do whatever as DBA.

This is the complete easy steps introduction to oracle in our first tutorial.Hope you will find it interesting and useful.Show your thoughts and doubts in the commenting section.
Thank you.