28 Haziran 2013 Cuma

Change scan_listener port in 11.2



check current port

$GRID_HOME/bin/srvctl config scan_listener
SCAN Listener LISTENER_SCAN1 exists. Port: TCP:1521
SCAN Listener LISTENER_SCAN2 exists. Port: TCP:1521
SCAN Listener LISTENER_SCAN3 exists. Port: TCP:1521


--change port

$GRID_HOME/bin/srvctl modify scan_listener -p 8003

--change remote listener parameter

alter system set remote_listener=':' scope=both;


--restart scan_listener

$GRID_HOME/bin/srvctl stop scan_listener
$GRID_HOME/bin/srvctl start scan_listener


--confirm change

$GRID_HOME/bin/srvctl config scan_listener

SCAN Listener LISTENER_SCAN1 exists. Port: TCP:8003
SCAN Listener LISTENER_SCAN2 exists. Port: TCP:8003
SCAN Listener LISTENER_SCAN3 exists. Port: TCP:8003

ORA-12012: error on auto execute of job "EXFSYS"."RLM$EVTCLEANUP"


Catalog db has an error in alert.log like :

Errors in file /u01/diag/rdbms/rmandb/rmandb/trace/rmandb_j000_25520.trc:
ORA-12012: error on auto execute of job "EXFSYS"."RLM$EVTCLEANUP"
ORA-04068: existing state of packages has been discarded
ORA-04065: not executed, altered or dropped stored procedure "EXFSYS.DBMS_RLMGR_DR"
ORA-06508: PL/SQL: could not find program unit being called: "EXFSYS.DBMS_RLMGR_DR"
ORA-06512: at line 1

check invalid objects and compile it or run utlrp.sql

SQL> select count(*) from dba_objects where status='INVALID';

  COUNT(*)
----------
        0

SQL> @?/rdbms/admin/utlrp.sql

try againg and same error...
and flush shared_pool.

SQL> alter system flush shared_pool;
SQL> alter system flush buffer_cache;

try again and it works.

27 Haziran 2013 Perşembe

Debuging PL/SQL Procedure

Which privileges do you need?

grant debug any procedure to appuser;
grant debug connect session to appuser;

You must compile with debug option procedure before to run.

alter procedure my_proc compile debug;


http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9013.htm#i2062318

DEBUGGING:
DEBUG CONNECT SESSION
Connect the current session to a debugger.
DEBUG ANY PROCEDURE
Debug all PL/SQL and Java code in any database object. Display information on all SQL statements executed by the application.
Note: Granting this privilege is equivalent to granting the DEBUG object privilege on all applicable objects in the database.



Interval partition


Interval partitioning is an extension to range partitioning.
You can use interval partition to automatically add new partitions.

Sample


CREATE TABLE mypart_table
(
  TARIH         DATE                            NOT NULL,
  KOD           NUMBER(5)                       NOT NULL,
  ALAN          VARCHAR2(600 BYTE),

)
PARTITION BY RANGE (TARIH)
(  
  PARTITION mypart_table_201303 VALUES LESS THAN (TO_DATE('2013-04-01', 'YYYY-MM-DD')),
  PARTITION mypart_table_201304 VALUES LESS THAN (TO_DATE('2013-05-01', 'YYYY-MM-DD')),
  PARTITION mypart_table_201305 VALUES LESS THAN (TO_DATE('2013-06-01', 'YYYY-MM-DD')),
  PARTITION mypart_table_201306 VALUES LESS THAN (TO_DATE('2013-07-01', 'YYYY-MM-DD'))
)
;


CREATE INDEX BANKDB.IDX_mypart_table_01 ON mypart_table
(TARIH, KOD)
LOCAL;


--add partition interval 1 day

alter table mypart_table set INTERVAL( NUMTODSINTERVAL(1,'DAY'));

You can't modify interval partitions. You can disable and enable again.

--disable interval 
ALTER TABLE mypart_table SET INTERVAL ();


When to Use Range or Interval Partitioning


24 Haziran 2013 Pazartesi

Export DDL with DBMS_METADATA



SQL>
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'SQLTERMINATOR', true);
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'STORAGE', false);
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'TABLESPACE', false);
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'SEGMENT_ATTRIBUTES', false);

select
  dbms_metadata.get_ddl('FUNCTION','SAMPLE_FUNC','APPUSER')
from dual;


14 Haziran 2013 Cuma

ORA-01111: name for data file 350 is unknown - rename to correct file



Error in alert.log

ORA-01111: name for data file 350 is unknown - rename to correct file
ORA-01110: data file 350: '/u01/app/oracle/product/11.2.0.3/dbs/UNNAMED00350'
ORA-01157: cannot identify/lock data file 350 - see DBWR trace file
ORA-01111: name for data file 350 is unknown - rename to correct file
ORA-01110: data file 350: '/u01/app/oracle/product/11.2.0.3/dbs/UNNAMED00350'
Recovery Slave PR00 previously exited with exception 1111
MRP0: Background Media Recovery process shutdown (ORCL)

--check broken filename on standby
SQL> select name from v$datafile where file#=350;

NAME
-------------------------------------------------------
/u01/app/oracle/product/11.2.0.3/dbs/UNNAMED00350

--modify parameter
alter system set standby_file_management=manual; 

--create datafile with correct filename

alter database create datafile '/u01/app/oracle/product/11.2.0.3/dbs/UNNAMED00350' as '/dev/ORCL/datadf130';

--modify parameter again to auto
alter system set standby_file_management=auto;

--start recovery
alter database recover managed standby database disconnect from session;

--check mrp
select process, status , sequence# from v$managed_standby;

11 Haziran 2013 Salı

Using JDBC with Firewalls

from Oracle® Database JDBC Developer's Guide and Reference

http://docs.oracle.com/cd/B19306_01/java.102/b14355/apxtblsh.htm#CHDBBDDA

Firewall timeout for idle-connections may sever a connection. This can cause JDBC applications to hang while waiting for a connection. You can perform one or more of the following actions to avoid connections from being severed due to firewall timeout:
  • If you are using connection caching or connection pooling, then always set the inactivity timeout value on the connection cache to be shorter than the firewall idle timeout value.
  • Pass oracle.net.READ_TIMEOUT as connection property to enable read timeout on socket. The timeout value is in milliseconds.
  • For both JDBC OCI and JDBC Thin drivers, use net descriptor to connect to the database and specify the ENABLE=BROKEN parameter in the DESCRIPTIONclause in the connect descriptor. Also, set a lower value for tcp_keepalive_interval.
  • Enable Oracle Net DCD by setting SQLNET.EXPIRE_TIME=1 in the sqlnet.ora file on the server-side.

14 Aralık 2012 Cuma

Handling PL/SQL Errors


Good article to understand error management with PL/SQL




http://www.oracle.com/technetwork/issue-archive/2005/05-mar/o25plsql-093886.html

8 Ağustos 2012 Çarşamba

How to call External Procedure from Oracle Database




create a file which has name "shell.c"

content of shell.c file
------------------------------------
#include
#include
#include

void sh(char *);

void sh( char *cmd )
{
int num;

num = system(cmd);
}
------------------------------------

--create object file
[oracle@host01 lib]$  gcc -fPIC -g -c -Wall shell.c

--create shared library file
[oracle@host01 lib]$  gcc -shared -o shell.so shell.o


modify parameter in $ORACLE_HOME/hs/admin/extproc.ora file

SET EXTPROC_DLLS=/home/oracle/lib/shell.so

--create lib and procedure for test

CREATE OR REPLACE LIBRARY SHELL_LIB
 IS '/home/oracle/lib/shell.so'
/

CREATE OR REPLACE PROCEDURE "SHELL" (cmd IN char)
as external
name "sh"
library shell_lib
language C
parameters (cmd string);
/


SQL> exec shell('/bin/pwd > /home/oracle/lib/aa.txt');


output file looks like

[oracle@host01 lib]$ more aa.txt
/u01/oracle/11.2.0.3/dbs



ORA-28575: unable to open RPC connection to external procedure agent


10 Temmuz 2012 Salı

RMAN ORA-01008: not all variables bound


Recovery Manager: Release 11.2.0.2.0 - Production on Tue Jul 10 10:33:11 2012

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

RMAN> connect target /


DBGSQL:     TARGET> select count(*) into :dbstate from v$parameter where lower(name) = '_dummy_instance' and upper(value) = 'TRUE'
DBGSQL:        sqlcode = 1008
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
ORA-01008: not all variables bound




workaround:

SQL>alter system flush shared_pool;


20 Haziran 2012 Çarşamba

Oracle database trigger order


Oracle Database fires multiple triggers in an unspecified, random order, if more than one trigger of the same type exists for a given statement; that is, triggers of the same type for the same statement are not guaranteed to fire in any specific order.

Execution steps of trigger.
http://docs.oracle.com/cd/B28359_01/server.111/b28318/triggers.htm#CNCPT418


 DBA_TRIGGER_ORDERING description
http://docs.oracle.com/cd/B28359_01/server.111/b28320/statviews_2107.htm#REFRN20581

sample:

create or replace trigger trigger_01
before insert on test
for each row
follows trigger_02
....


create or replace trigger trigger_02
before insert on test
for each row




15 Haziran 2012 Cuma

sqlplus ORA-01031: insufficient privileges


You want to connect intance to start.(oracle 11g)

but there is an error.

like


[oracle@oratest01 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Tue Jun 23 02:00:05 2009

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

ERROR:
ORA-01031: insufficient privileges


1-Check groups in linux.(if dba group doesn't exist firstly create it)

more /etc/group
.
....

oinstall:x:500:
dba:x:501:oracle


2-Check your oracle user groups

more /etc/passwd
.
....
oracle:x:500:500::/home/oracle:/bin/bash



[root@oratest01 ~]# id oracle
uid=500(oracle) gid=500(oinstall) groups=500(oinstall),501(dba)




12 Haziran 2012 Salı

RMAN-20032: checkpoint change# too low



If you use catalog for backup


RMAN> resync database;
RMAN-20032: checkpoint change# too low

If database returned from cold backup resync can't be succesful.

solution

connect target /
connect catalog user@catdb

unregister database;
register database;



Veritas Volume Manager


Useful command samples for Veritas Volume Manager.

http://www.hyborian.demon.co.uk/notes/vx_cli.html



11 Haziran 2012 Pazartesi

ORA-22858: invalid alteration of datatype (convert varchar2 to clob)


When you convert a field from varchar2 to clob
raise an error ORA-22858: invalid alteration of datatype


SQL> create table vty_ra1 (a varchar2(10));



SQL> alter table vty_ra1 modify a clob;



ORA-22858: invalid alteration of datatype



workaround:

alter table vty_ra1 modify a long;

alter table vty_ra1 modify a clob;

28 Mayıs 2012 Pazartesi

RMAN-00569: ERROR MESSAGE STACK FOLLOWS


When you want to backup your db with using catalog database.

If raise an error like follow


INF - RMAN-00571: ===========================================================
INF - RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
INF - RMAN-00571: ===========================================================
INF - Recovery Manager complete.
INF - End of Recovery Manager output.
INF - End Oracle Recovery Manager.

Cause
Catalog db's tns entry must be in tnsnames.ora.
Check your $ORACLE_HOME/network/admin/tnsnames.ora file.

8 Mayıs 2012 Salı

How to open large file more than 2GB

in C program you can add line.

#define _FILE_OFFSET_BITS 64


3 Mayıs 2012 Perşembe

Uninstall ORACLE HOME manually

You can use to deinstall ORACLE_HOME from inventory with following method.(oracle database or grid home)


export ORACLE_HOME=

# detach 
$ORACLE_HOME/oui/bin/runInstaller -detachHome -silent -local ORACLE_HOME=$ORACLE_HOME

# confirm:
$ORACLE_HOME/OPatch/opatch lsinventory -all   

# remove directory
rm -rf $ORACLE_HOME





26 Nisan 2012 Perşembe

MUST_BE_SAME_TIMEZONE_FILE_VERSION

When you upgrade database to 11g r2

when running catupgrd.sql

SQL> SELECT TO_NUMBER('MUST_BE_SAME_TIMEZONE_FILE_VERSION')
  2     FROM sys.props$
  3     WHERE
  4       (
  5        ((SELECT TO_NUMBER(value$) from sys.props$
  6           WHERE name = 'DST_PRIMARY_TT_VERSION') !=
  7         (SELECT tz_version from registry$database))
  8        AND
  9        (((SELECT substr(version,1,4) FROM registry$ where cid = 'CATPROC') =
10           '9.2.') OR
11         ((SELECT substr(version,1,4) FROM registry$ where cid = 'CATPROC') =
12           '10.1') OR
13         ((SELECT substr(version,1,4) FROM registry$ where cid = 'CATPROC') =
14           '10.2') OR
15         ((SELECT substr(version,1,4) FROM registry$ where cid = 'CATPROC') =
16           '11.1'))
17       );
SELECT TO_NUMBER('MUST_BE_SAME_TIMEZONE_FILE_VERSION')
                 *
ERROR at line 1:
ORA-01722: invalid number


control following steps


SQL> SELECT * FROM v$timezone_file;

FILENAME                VERSION
-------------------- ----------
timezlrg_14.dat              14


SQL> select TZ_VERSION from registry$database;

TZ_VERSION
----------
        4


If version of timezone_file is different than TZ_VERSION
run following update.

SQL> update registry$database set TZ_VERSION = (select version FROM v$timezone_file);
SQL> commit;


try to run catupgrd.sql





25 Nisan 2012 Çarşamba

ORA-14265: data type or length of a table subpartitioning column may not be changed

When you want to modify partition table' s key columns.

sample

1 - create partitioned table with subpartition.


SQL> CREATE TABLE vty_log
    (tarih        DATE,
    program       VARCHAR2(6),
    pcismi        VARCHAR2(12),
    mesaj         VARCHAR2(2000),
    boyut         NUMBER(10,0))
  PARTITION BY RANGE (TARIH)
  SUBPARTITION BY HASH (program)
  (
  PARTITION vty_log_201201 VALUES LESS THAN (TO_DATE(' 2012-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
  LOGGING
  (
  SUBPARTITION vty_log_201201_P1,
  SUBPARTITION vty_log_201201_P2,
  SUBPARTITION vty_log_201201_P3,
  SUBPARTITION vty_log_201201_P4
  )
  );


2- try to modify subpartition column

SQL> alter table vty_log modify program varchar2(10);
*
ERROR at line 1:
ORA-14265: data type or length of a table subpartitioning column may not be changed 

you have to drop/create table to achive this problem.

You can create non-partition table for each partition which has same name with partition
and exchange partition 
or
If have enoguh downtime you can export/import with orjinal table. 
or
you can create dummy table desired structure and you can insert/select/rename.