Thursday, December 20, 2012

run command as another user in linux using "sudo"

#this will run the command with another user's environment and account.
sudo -i -u username command

Reference
http://linux.die.net/man/8/sudo

compare strings in bash shell script

if [ $1 == $2 ] ; then
echo "Equal"
else
echo "not equal"
fi

if [ $1 != $2 ]; then
echo "not equal"
else
echo "equal"
fi


if [ $1 == "test" ] ; then
echo "Equal"
else
echo "not equal"
fi

reference:
http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/

Thursday, December 13, 2012

ORA-14048: by Alter index unusable usable : IMPORT

PROBLEM:
when importing schema to database (version 11.2.0.3 linux 64bit) using data pump, Below errors appeared in log.

ORA-39083: Object type CONSTRAINT failed to create with error:
ORA-14048: a partition maintenance operation may not be combined with other operations
Failing sql is:
 ALTER INDEX "TEST"."SYS_C001906177"  UNUSABLE ENABLE

CAUSE:
This is unpublished bug 4919496.  When schema was exported, system generated index was put into unusable state. So export generate the "alter index .... unusable; enable" statement in dump file. this can be proved by generate SQLFILE using import tool. 

SOLUTION:
the error can be ignored during importing. To avoid this error, make system generated index usable when doing export.

reference:
Import Fails With Error ORA-14048 A Partition Maintenance Operation May Not Be Combined With Other Operations [ID 787407.1]




Tuesday, December 11, 2012

Password in Oracle 11G

ISSUE:

When we move schemas in one database or from it to another by datapump, we sometimes can not login to moved schemas with its password.

CAUSE:
Password has version (10G or 11G) in 11G database. Version usage is controlled by parameter.

HASH PROCESS:

a. in 10G
 passphrase + username are used to generate hash

b. in 11G
 passphrase + salt are userd to generate hash.

c. sec_case_sensitive_logon parameter is used to control password authentication method.
   sec_case_sensitive_logon -> TRUE   : 11G authentication
   sec_case_sensitive_logon -> FALSE  : 10G authentication

SYNOMINAL:

move schema TEST (11G) to TEST1 (10G) :  need reset pass
move schema TEST (11G) to TEST (10G) :  might need reset pass if 10G hash value is not correct
 move schema TEST (11G) to TEST1 (11G): no need to reset pass
move schema TEST (11G) to TEST (11G): no need to reset pass
move schema TEST (10G) to TEST (10G) : no need to reset pass
move schema TEST (10G) to TEST1 (10G) : need reset pass

move schema TEST (10G) to TEST (11G) : might need reset pass if 11G hash value is not null or correct
move schema TEST (10G) to TEST1 (11G) : need reset pass if 11G hash value is not correct

EXPLANATION:
Two hash values are stored in 11G database. One is for back-track to 10G pass authentication and the other one for new 11G authentication.

to check what hash was stored:
select username, password_versions from dba_users;
results can be:
10G
11G
10G 11G

to check the hash values
select name, password,spare4 from sys.user$;
password column is 10G hash value
spare4 column is 11G hash value(3-42) and its salt harsh value(43-63)


Reference:
http://www.notesbit.com/index.php/scripts-oracle/oracle-11g-new-password-algorithm-is-revealed-by-seclistsorg/
http://www.petefinnigan.com/sha1.sql
http://docs.oracle.com/cd/E11882_01/server.112/e25513/dynviews_1101.htm#sthref3208
http://askdba.org/weblog/2008/11/how-to-changerestore-user-password-in-11g/






Friday, November 30, 2012

CHARACTER SET MIGRATION in ORACLE

ISSUE:

Database is using an invalid (non-UTF8) character set: (NLS_CHARACTERSET = WE8MSWIN1252) was given when tried to install space walk application.

CAUSE:
database was created with WE8MSWIN1252 because host os is windows. 

SOLUTION:
user csscan, csalter, datapump to migrate character set to AL32UTF8


STEPS:
1. csscan full=Y tochar=AL32UTF8
2. export user with application data need be converted. drop them from database
3. run csalter to change dictinary table character set
4. import back the dropped user.

POINTS:
it is good to user AL32UTF8 as character set at beginning. 
datapump and origical exp/imp tools can do character conversion on fly.

TABLE/VIEW:
nls_session_parameters
nls_instance_parameters
nls_database_parameters
v$nls_valid_values
v$nls_parameters

CHECK database character set:
select * from nls_database_parameters where parameter like '%CHAR%';

NLS paramters:

PARAMETER
------------------------------
NLS_LANGUAGE
NLS_TERRITORY
NLS_CURRENCY
NLS_ISO_CURRENCY
NLS_NUMERIC_CHARACTERS
NLS_CHARACTERSET
NLS_CALENDAR
NLS_DATE_FORMAT
NLS_DATE_LANGUAGE
NLS_SORT
NLS_TIME_FORMAT
NLS_TIMESTAMP_FORMAT
NLS_TIME_TZ_FORMAT
NLS_TIMESTAMP_TZ_FORMAT
NLS_DUAL_CURRENCY
NLS_COMP
NLS_LENGTH_SEMANTICS
NLS_NCHAR_CONV_EXCP
NLS_NCHAR_CHARACTERSET
NLS_RDBMS_VERSION

reference:
http://www.morganslibrary.org/reference/character_sets.html
http://docs.oracle.com/cd/E11882_01/server.112/e10729/ch12scanner.htm#g1035448
http://docs.oracle.com/cd/E11882_01/server.112/e10729/ch11charsetmig.htm#g1011430
https://forums.oracle.com/forums/thread.jspa?threadID=990007
http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch1overview.htm#i1005900
https://forums.oracle.com/forums/thread.jspa?messageID=3471873
https://forums.oracle.com/forums/thread.jspa?threadID=2206301




Compress tablespace , table partition and ORA-04031

ISSUE:
ORA-04031 appears in alert log and shared memory is used up. most of sql can not  be executed due to ORA-04031.

CAUSE:
1. we use basic compress technology on partition tables.
2. new column need be added to the partition tables with basic compression. so below need be done.
   alter table p1 move;
   alter table p1 add column c1;
   alter table p1 move compress;
3. there are 200000 subpartitions on p1 because of old data.

SYMPTOM:
ORA-0431 error.
PRTMV portion in shared pool is extremely high. in may case PRTMV used 18G of 20G shared pool

SOLUTION:
reduce subpartition to reasonable number.




Monday, November 26, 2012

DEFERRED_SEGMENT_CREATION and ORA-04031

11g new feature:

segment will be created when first insert statment is issued for table. if DEFERRED_SEGMENT_CREATION is true.

ISSUE:
When partition table is used, it might cause ORA-04031 error.  The PRTMV part of shared pool will take most of shared pool memory.

Solution:
set DEFERRED_SEGMENT_CREATION  to false.


reference:
11.2 Database New Feature Deferred Segment Creation [Video] [ID 887962.1]
http://www.dba-oracle.com/t_shared_pool_scripts.htm
http://blog.tanelpoder.com/2009/06/04/ora-04031-errors-and-monitoring-shared-pool-subpool-memory-utilization-with-sgastatxsql/