Monday, September 2, 2013

HOW TO CHANGE CHARACTER SET IN ORACLE

Install CSSCAN


login with SYS user

@?/rdbms/admin/csminst.sql

###############

csscan \"sys as sysdba\" full=y

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production

With the Partitioning, OLAP and Data Mining options


Current database character set is AL32UTF8.


Enter new database character set name: > WE8ISO8859P1


Enter array fetch buffer size: 1024000 >


Enter number of scan processes to utilize(1..32): 1 > 4


Enumerating tables to scan...


The output goes into 3 files: scan.err, scan.out, scan.txt

Detailed description can be found in Oracle Support document "Csscan output explained [ID 444701.1]".


3. Backup database if it has not been done yet.


4. Dealing with Truncation and Lossy data

Check file scan.txt

With some lossy data, I had the following summary:

[Scan Summary]

All character type data in the data dictionary are convertible to the new character set

Some character type application data are not convertible to the new character set


There was no Truncation data in this DB.

Lossy data were found in one table (TOAD_PLAN_TABLE) and I’ve just dropped it.

More info about dealing with Lossy and Transaction data can be found in Oracle document " Changing the NLS_CHARACTERSET to AL32UTF8 / UTF8 (Unicode) [ID 260192.1]"


5. Dealing with Convertible data

"Convertible" Data Dictionary CLOB data is handled by CSALTER. No action required.

"Convertible" Application Data has to be exported and deleted!

When there are application Convertible data without Truncation/Lossy data, scan summary in scan.txt looks like:

[Scan Summary]

All character type data in the data dictionary are convertible to the new character set

All character type application data are convertible to the new character set


In this case there were two application tables with convertible data.

[Application Data Conversion Summary]

Datatype         Changeless  Convertible   Truncation  Lossy

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

VARCHAR2     15,045,735,123          280            0      0

CHAR                      0            0            0      0

LONG                      0            0            0      0

CLOB                      0            0            0      0

VARRAY                    0            0            0      0

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


[Distribution of Convertible, Truncated and Lossy Data by Table]

USER.TABLE                Convertible  Truncation  Lossy

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

EDWSTG_HM.JOBS                     21           0      0

EDWSTG_HM.TRANSACTIONS            259           0      0


Export and truncate

expdp \"/ as sysdba\" DUMPFILE=t01_%u.dmp LOGFILE=t01.log tables=EDWSTG_HM.JOBS,EDWSTG_HM.TRANSACTIONS parallel=4


SQL> truncate table EDWSTG_HM.JOBS;

SQL> truncate table EDWSTG_HM.TRANSACTIONS;


6. Run CSSCAN again.

csscan \"sys as sysdba\" full=y


To run CSALTER the following output of CSSCAN (scan.txt) is required:


[Scan Summary]

All character type data in the data dictionary are convertible to the new character set

All character type application data remain the same in the new character set


[Data Dictionary Conversion Summary]



The data dictionary can be safely migrated using the CSALTER script


7. Conversion

Shutdown listener and make sure nothing else connects to the database.


sqlplus / as sysdba

show parameter job_queue_processes

show parameter aq_tm_processes

-- assuming spfile is in use

alter system set job_queue_processes=0;

alter system set aq_tm_processes=0;

shutdown immediate;


startup restrict

spool convert.log

@?/rdbms/admin/csalter.plb


Restart the database and listener.


8. Post conversion steps

Restore altered parameters

alter system set job_queue_processes=10;

alter system set aq_tm_processes=1;



###############







-------------------------Change Oracle DB Character Set---------------------------------------------





If you want to change from WE8MSWIN1252 to AL32UTF8. Check the NLS parameters first.



SQL> SELECT PARAMETER, VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER IN ('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET');

---------------------------------------Changing Commands------------------------------------------------

The syntax of the ALTER DATABASE CHARACTER SET statement is as follows:



SQL> ALTER DATABASE [db_name] CHARACTER SET new_character_set;



(db_name is an optional)



For Example :



SQL> ALTER DATABASE CHARACTER SET AL32UTF8;



--------------------------------Steps to change the database character set------------------------------------------

To change the database character set, perform the following steps:



1. Shut down the database, using either a SHUTDOWN IMMEDIATE or a SHUTDOWN NORMAL statement.



2. Do a full backup of the database because the ALTER DATABASE CHARACTER SET statement cannot be rolled back.



3. Startup Oracle database



SQL> startup mount;

SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;

SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;

SQL> ALTER DATABASE OPEN;

SQL> ALTER DATABASE CHARACTER SET AL32UTF8;

If you get the error ORA-12712, please update the following table.



"ORA-12712: new character set must be a superset of old character set"



SQL> update sys.props$ set VALUE$='AL32UTF8' where NAME='NLS_CHARACTERSET';

SQL> commit;

If you get the error ORA-12721, please login as DBA user.



"ORA-12721: operation cannot execute when other sessions are active"



4. shutdown immediate;  or shutdown normal;



5. startup oracle database



SQL> startup mount;

SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;

SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;

SQL> ALTER DATABASE OPEN;

SQL> ALTER DATABASE CHARACTER SET AL32UTF8;



SQL> shutdown immediate;

SQL> startup;



--------------------------------------Check the NLS parameters-------------------------------------------

SQL> SELECT PARAMETER, VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER IN ('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET');





Friday, August 30, 2013

RECOVER CONTROLFILE


ALTER TABLESPACE tbs01 RENAME TO tbs02;
crosscheck archivelog all;
delete expired archivelog all;
delete noprompt expired archivelog all;


startup nomount

CREATE CONTROLFILE SET  DATABASE "ORCL" RESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 '/oracle/product/10.2.0/oradata/orcl/redo01.log'  SIZE 50M,
  9    GROUP 2 '/oracle/product/10.2.0/oradata/orcl/redo02.log'  SIZE 50M,
 10    GROUP 3 '/oracle/product/10.2.0/oradata/orcl/redo03.log'  SIZE 50M
 11  -- STANDBY LOGFILE
 12  DATAFILE
 13    '/oracle/product/10.2.0/oradata/orcl/system01.dbf',
 14    '/oracle/product/10.2.0/oradata/orcl/undotbs01.dbf',
 15    '/oracle/product/10.2.0/oradata/orcl/sysaux01.dbf',
 16    '/oracle/product/10.2.0/oradata/orcl/users01.dbf',
 17*   '/oracle/product/10.2.0/oradata/orcl/example01.dbf'
SQL> /

alter database open resetlogs;

############################################################
to change location using RMAN

run {
sql ' alter tablespace users offline';
set newname for datafile '/oracle/use1.dbf' to '/oracle/product/10.2.0/oradata/orcl/users01.dbf';
restore tablespace users;
switch datafile all;
recover tablespace users;
 }

                                     Oracle Managed Files location, you can use this
form of the command:
RUN {
    SET NEWNAME FOR DATAFILE 3 to NEW;
    RESTORE DATAFILE 3;
    SWITCH DATAFILE 3;
    RECOVER DATAFILE 3;
}



Thursday, August 29, 2013

TABLESPACE RECOVERY USING RMAN

SQL> select * from jobs;
select * from jobs
              *
ERROR at line 1:
ORA-01116: error in opening database file 5
ORA-01110: data file 5: '/oracle/product/10.2.0/oradata/orcl/example01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3


THE RESOLVE USING RMAN

FIRST MANDATORY

FULL BACKUP PLUS ARCHIVELOG

RMAN>  sql ' alter tablespace example offline immediate';

sql statement:  alter tablespace example offline immediate

RMAN> restore tablespace example;

RMAN> recover tablespace example;

Starting recover at 29-AUG-13
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:02

Finished recover at 29-AUG-13

RMAN> sql ' alter tablespace example online';

sql statement:  alter tablespace example online


EXECUTE QUERY.....

Monday, August 5, 2013

CONNECT DATABASE REMOTELY

sqlplus hr/hr@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.146.134)(PORT=1521)))(CONNECT_DATA=(SID=orcl)))'

Thursday, August 1, 2013

INSTALL SQLDEVELOPER IN LINUX

STEP-1

Download and Install  sqldeveloper-3.2.20.09.87-1.noarch.rpm

STEP -2

Download and Install  jdk-7u21-linux-i586.rpm

STEP-3

define_editor=vi

chmod 777    /opt/sqldeveloper/sqldeveloper/bin/sqldeveloper.conf

vi     /opt/sqldeveloper/sqldeveloper/bin/sqldeveloper.conf
set Java path

/usr/java/jdk1.7.0_21/

type
sqldeveloper


Tuesday, July 23, 2013

ERROR ORA-00312 ,ORA-00350 LOGFILE DELETED .....

SQL>
SQL> select open_mode from v$database;

OPEN_MODE
----------
MOUNTED

SQL>
SQL>
SQL> alter database drop logfile group 1;
alter database drop logfile group 1
*
ERROR at line 1:
ORA-00350: log 1 of instance orcl (thread 1) needs to be archived
ORA-00312: online log 1 thread 1:
'/oracle/product/10.2.0/oradata/orcl/redo01.log'


SQL>
SQL>
SQL> select  member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/oracle/product/10.2.0/oradata/orcl/redo03.log
/oracle/product/10.2.0/oradata/orcl/redo02.log
/oracle/product/10.2.0/oradata/orcl/redo01.log

SQL> ELECT STATUS FROM V$LOG WHERE GROUP#=1;
SP2-0734: unknown command beginning "ELECT STAT..." - rest of line ignored.
SQL> sELECT STATUS FROM V$LOG WHERE GROUP#=1;

STATUS
----------------
INACTIVE

SQL>
SQL> ALTER DATABASE DROP LOGFILE GROUP 1;
ALTER DATABASE DROP LOGFILE GROUP 1
*
ERROR at line 1:
ORA-00350: log 1 of instance orcl (thread 1) needs to be archived
ORA-00312: online log 1 thread 1:
'/oracle/product/10.2.0/oradata/orcl/redo01.log'


SQL> ALTER DATABASE DROP LOGFILE GROUP1
  2  ;
ALTER DATABASE DROP LOGFILE GROUP1
                            *
ERROR at line 1:
ORA-02236: invalid file name


SQL>
SQL> ALTER DATABASE DROP LOGFILE GROUP 1;
ALTER DATABASE DROP LOGFILE GROUP 1
*
ERROR at line 1:
ORA-00350: log 1 of instance orcl (thread 1) needs to be archived
ORA-00312: online log 1 thread 1:
'/oracle/product/10.2.0/oradata/orcl/redo01.log'


SQL> alter database clear unarchived logfile group 1;

Database altered.

SQL> alter database drop logfile group 1;

Database altered.

SQL>
SQL> alter database add logfile group 1 '/oracle/product/10.2.0/oradata/orcl/redo01.log' size 10m;
alter database add logfile group 1 '/oracle/product/10.2.0/oradata/orcl/redo01.log' size 10m
*
ERROR at line 1:
ORA-00301: error in adding log file
'/oracle/product/10.2.0/oradata/orcl/redo01.log' - file cannot be created
ORA-27038: created file already exists
Additional information: 1


SQL> alter database add logfile group 1 '/oracle/product/10.2.0/oradata/orcl/redo01.log' reuse;

Database altered.

SQL>

Monday, July 22, 2013

CHECK WHETHER DATABASE RUNNING USING SPFILE OR PFILE

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

Git & GitHub Interview Questions & Answers

  Git & GitHub Interview Questions & Answers 🧑‍💻🌐   1️⃣ What is Git?   A: Git is a distributed version control system to track ...