All 112 entries tagged Oracle

View all 121 entries tagged Oracle on Warwick Blogs | View entries tagged Oracle at Technorati | There are no images tagged Oracle on this blog

May 01, 2014

memory_target sga_target and db_cache_size

On my two databases, the buffer cache were way too small. One buffer was 128 mb, which was the default value set in db_cache_size; one is 64 mb while the db_cache_size value is 0.

On both servers, the memory_target parameters were set (5g and 3g respectively) while sga_targets are set to zero. It seemed ASSM mis-configured the buffer cache.

After I set the sga_target to a reasonable value, ASSM began to adjust the cache buffer and set them to a much higher value. The first one was set to 700 mb and the second 608 mb.

Both databases are 11.2.0.3 on solaris 10.

Maybe we should either set the sga_target, or set a high value in db_cache_size.


February 23, 2012

Instantiate table in Oracle Streams

Writing about web page http://krish-dba.blogspot.com/2009/01/re-synchronizingrefresh-table-in.html

Credit to this article

1. Stop Capture
EXEC DBMS_CAPTURE_ADM.STOP_CAPTURE(capture_name => 'CAP_HSUN');

2. Stop propagation
EXEC DBMS_PROPAGATION_ADM.STOP_PROPAGATION('PROP_HSUN',FORCE=>TRUE);

3. Stop Apply Process on Target(T)

EXEC DBMS_APPLY_ADM.STOP_APPLY(apply_name => 'AAPL_HSUN');

4. Delete the apply errors on Target

Check the errors in the error queue:

SQL> select apply_name, LOCAL_TRANSACTION_ID, ERROR_MESSAGE from dba_apply_error;

To delete specific transaction:

SQL> EXEC DBMS_APPLY_ADM.DELETE_ERROR('transaction_id');

To delete all errors: 

SQL> EXEC DBMS_APPLY_ADM.DELETE_ALL_ERRORS('AAPL_HSUN');

5. Truncate table 

ALTER TABLE  UWTABS.UW_TPRS ADD CONSTRAINT "C_TPRS_1" PRIMARY KEY ("TPRS_CODE");
Truncate table UWTABS.UW_TPRS

6. Re-instantiate the problem table on Source(S)

EXEC DBMS_CAPTURE_ADM.PREPARE_TABLE_INSTANTIATION('UWTABS.UW_TPRS');

DECLARE iscn NUMBER; 
BEGIN iscn:=DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER(); 
DBMS_APPLY_ADM.SET_TABLE_INSTANTIATION_SCN@target.warwick.ac.uk(
 source_object_name => 'UWTABS.UW_TPRS', 
 source_database_name => 'source.warwick.ac.uk', 
 instantiation_scn => iscn);
END;
/

7.
Synchronize the problem table through datapump exp/imp

8. Start the Apply Process on Target(T)

EXEC DBMS_APPLY_ADM.START_APPLY(apply_name => 'AAPL_HSUN');

9. Start the propagation Process on the Source(S)

EXEC DBMS_PROPAGATION_ADM.START_PROPAGATION('PROP_HSUN');

10. Start the Capture Process on the Source(S)

EXEC DBMS_CAPTURE_ADM.START_CAPTURE(capture_name => 'CAP_HSUN');

February 21, 2012

job name in datapump

Pay attention to the format of job name

oracle@db$ expdp / attach=nightly_pump_210212-1059

ed to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning and Real Application Testing options
ORA-31626: job does not exist
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
ORA-06512: at "SYS.KUPV$FT", line 405
ORA-31638: cannot attach to job nightly_pump_210212-1059 for user NIGHTLY_PUMP_210212
ORA-31632: master table "NIGHTLY_PUMP_210212.nightly_pump_210212-1059" not found, invalid, or inaccessible
ORA-00942: table or view does not exist

Datapump can find correct user after changing the job name.


oracle@db$ expdp / attach=nightly_pump_210212_1059
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning and Real Application Testing options
ORA-31626: job does not exist
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
ORA-06512: at "SYS.KUPV$FT", line 405
ORA-31638: cannot attach to job NIGHTLY_PUMP_210212_1059 for user OPS$ORACLE
ORA-31632: master table "OPS$ORACLE.NIGHTLY_PUMP_210212_1059" not found, invalid, or inaccessible
ORA-00942: table or view does not exist

Seemed the ”-” in the job name caused problem.


January 25, 2012

Use Timestamp type instead of Date type

Today I noticed another problem caused by Date type.

select page3_.*
from sb2.NEWS_ITEM this_ inner join sb2.CONTENT_FETCHER cf1_ on this_.news_id=cf1_.ID
 inner join sb2.CONTENT content2_ on cf1_.content_id=content2_.id 
  inner join sb2.PAGE page3_ on content2_.page_id=page3_.id
where ( this_.discriminator = 'calendar_item') and page3_.LAST_UPDATED_DATE>:1 
order by page3_.LAST_UPDATED_DATE asc, this_.publication_date asc

The SQL Tunning Advisor suggested that “page3_.LAST_UPDATED_DATE>:1 ” has an implicit data type conversion prevent the optimizer from selecting indices.

The LAST_UPDATED_DATE column is of “DATE” type.

From V$SQL_MONITOR, the bind variable is:
<binds>
<bind name=":1" pos="1" dty="180" dtystr="TIMESTAMP" maxlen="11" len="7" format="hexdump">78640101010101</bind>
</binds>

After inspecting the source code, it is appear bind as java.util.Date.

I think it should be bound as java.sql.Date, not java.sql.Timestamp or java.util.Date. See http://databaseperformance.blogspot.com/2009/01/java-data-types-and-oracle-index-usage.html


Oracle saw the value it was getting was of type TIMESTAMP, which has sub-second values in it. And rather than lose precision by truncating its value, it was instead converting the DATE value in each data row to a TIMESTAMP value before comparing.

Better to use Timestamp type instead of Date type. The index should work properly whether you bind java.sql.Date or java.sql.Timestamp.

Data Type Conversion
Oracle will convert the value to most precise type:

Column type DATE, predicate value is TIMESTAMP => Right size is more precise => Convert every row to timestamp
Column type Timestap, predicate value is DATE => Left size is more precise => convert predicate to Timestap
Column type varchar, predicate value is number => Right size is more precise => convert every row to varchar
Column type is number, predicate value is varchar => Left size is more precise => convert predicate value to number


January 12, 2012

Delete old rman backup piece manually

My Nagios checking reported there were an old backup dated back 2010. There is no such backup on disk. RMAN crosscheck and delete wont be able to remove it.

Tried to delete it with “nice” rman command:
RMAN> delete backup tag = 'TAG20101029T101009';

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=317 device type=DISK
specification does not match any backup in the repository

RMAN> delete backuppiece tag = 'TAG20101029T101009';
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of delete command at 01/12/2012 09:59:49
RMAN-06168: no backup pieces with this tag found: TAG20101029T101009
Resort to manually deleting in the base table:
SELECT * FROM rc_backup_set where db_id='1320220071' order by start_time
select * from bp where db_key=10492312 and tag = 'TAG20101029T101009'
delete from  bp where db_key=10492312 and tag = 'TAG20101029T101009'

January 10, 2012

Install Oracle Instant Client on Ubuntu

1. Download instantclient-basic-linux.x64-11.2.0.3.0.zip and instantclient-sqlplus-linux.x64-11.2.0.3.0.zip and unzip them into /apps/oracle/instantclient_11_2

2. sudo apt-get install libaio1

3. Append the following line into ~/.bashrc

export LD_LIBRARY_PATH=/apps/oracle/instantclient_11_2
export SQLPATH=~/code/oracle-scripts/scripts:/app/oracle/instantclient_11_2
PATH=$PATH:/apps/oracle/instantclient_11_2
export TNS_ADMIN=/apps/oracle/instantclient_11_2

No need the TNS_ADMIN if you just want to use easy connect.

4. (optional)
create tnsnames.ora

5. Now sqlplus should works.
sqlplus system/password@oracle_server

This doc help me a lot.


Use online redefinition to change a table into a partitioned table

Created a test user hsun


drop table log purge;
drop table children purge;
drop table parent purge;
drop view children_less_10_v;

create table parent (id number);
alter table parent add constraint pk_parent_id primary key (id);

create table log (msg varchar2(50));

create table children (id number,pid number,  constraint  pk_id  primary key  (id));
alter table children add constraint fk_pid foreign key (pid) references parent (id);
create view children_less_10_v as select * from children where id < 10;

create or replace trigger children_tri 
before insert or update on children 
for each row 
begin
  insert into log values('new' || :new.id);
end;
/   

insert into parent  select rownum from dual connect by level < 15;
insert into children  select rownum, rownum from dual connect by level < 15;
COMMIT;
exit;

Run the script status.sql that contains the following SQL:


set lin 200;
col object_name format a20
select object_name, object_type, status from user_objects order by 2, 1 ;
select trigger_name , table_name from user_triggers order by 2;
select view_name, text from user_views;
select CONSTRAINT_NAME, table_name, status from user_constraints order by 2;
select table_name, PARTITION_NAME from user_tab_partitions order by 1;

SQL> @/tmp/status.sql
OBJECT_NAME          OBJECT_TYPE         STATUS
-------------------- ------------------- -------
PK_ID                INDEX               VALID
PK_PARENT_ID         INDEX               VALID
CHILDREN             TABLE               VALID
LOG                  TABLE               VALID
PARENT               TABLE               VALID
CHILDREN_TRI         TRIGGER             VALID
CHILDREN_LESS_10_V   VIEW                VALID

7 rows selected.

TRIGGER_NAME                   TABLE_NAME
------------------------------ ------------------------------
CHILDREN_TRI                   CHILDREN

VIEW_NAME                      TEXT
------------------------------ --------------------------------------------------------------------------------
CHILDREN_LESS_10_V             select "ID","PID" from children where id < 10

CONSTRAINT_NAME                TABLE_NAME                     STATUS
------------------------------ ------------------------------ --------
FK_PID                         CHILDREN                       ENABLED
PK_ID                          CHILDREN                       ENABLED
PK_PARENT_ID                   PARENT                         ENABLED

no rows selected


Run as SYSDBA in a different session:


-- -- Check table can be redefined
EXEC DBMS_REDEFINITION.can_redef_table('HSUN', 'CHILDREN');

drop table hsun.children_p purge;
create table hsun.children_p (id number,pid number) 
 partition by range (id)
 ( partition p1 values less than (5),  
   partition p2 values less than (10),   
   partition p3 values less than (maxvalue));

-- Start Redefinition
EXEC DBMS_REDEFINITION.start_redef_table('HSUN', 'CHILDREN', 'CHILDREN_P');

SET SERVEROUTPUT ON
DECLARE
  l_num_errors PLS_INTEGER;
BEGIN
 DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS(uname => 'HSUN',
       orig_table => 'CHILDREN',
       int_table => 'CHILDREN_P', 
       copy_indexes  => DBMS_REDEFINITION.cons_orig_params,
       num_errors => l_num_errors);
 DBMS_OUTPUT.put_line('l_num_errors=' || l_num_errors);
END;
/

-- Optionally synchronize new table with interim data before index creation
EXEC DBMS_REDEFINITION.sync_interim_table('HSUN', 'CHILDREN', 'CHILDREN_P'); 

-- Complete redefinition
EXEC DBMS_REDEFINITION.finish_redef_table( 'HSUN',  'CHILDREN', 'CHILDREN_P');

drop table hsun.children_p purge;

Run status.sql again:


SQL> @/tmp/sta

OBJECT_NAME          OBJECT_TYPE         STATUS
-------------------- ------------------- -------
PK_ID                INDEX               VALID
PK_PARENT_ID         INDEX               VALID
CHILDREN             TABLE               VALID
LOG                  TABLE               VALID
PARENT               TABLE               VALID
CHILDREN             TABLE PARTITION     VALID
CHILDREN             TABLE PARTITION     VALID
CHILDREN             TABLE PARTITION     VALID
CHILDREN_TRI         TRIGGER             INVALID
CHILDREN_LESS_10_V   VIEW                INVALID

10 rows selected.

TRIGGER_NAME                   TABLE_NAME
------------------------------ ------------------------------
CHILDREN_TRI                   CHILDREN

VIEW_NAME                      TEXT
------------------------------ --------------------------------------------------------------------------------
CHILDREN_LESS_10_V             select "ID","PID" from children where id < 10

CONSTRAINT_NAME                TABLE_NAME                     STATUS
------------------------------ ------------------------------ --------
FK_PID                         CHILDREN                       ENABLED
PK_ID                          CHILDREN                       ENABLED
PK_PARENT_ID                   PARENT                         ENABLED

TABLE_NAME                     PARTITION_NAME
------------------------------ ------------------------------
CHILDREN                       P1
CHILDREN                       P3
CHILDREN                       P2

The Database versions

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for Solaris: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
Observation:
  • The primary key, foreign key and triggers remains “ENABLED”
  • View and trigger are “INVALID”

January 05, 2012

Solaris df reported disk usage differently to du

I dropped the hitlogging tablespace whose size was 200+ gb.
But:

run df report

bash-3.00# df -h
la-ora01-db            588G    31K    44G     1%    /oradb
la-ora01-db/data       588G   489G    44G    92%    /oradb/data

bash-3.00# du -s -h /oradb/data
 217G   /oradb/data

-bash-3.00# for pid in `ps -ef | grep ora_ | awk '{print $2}'`; do 
 pfiles  $pid | grep log  ; done | sort | uniq
   ...
      /oradb/data/stats2/hitlog2010.dbf
      /oradb/data/stats2/hitlog2011.dbf
      /oradb/data/stats2/hitlog2012.dbf
      /oradb/data/stats2/hitlogempty.dbf
      /oradb/data/stats2/hitlogmview01.dbf
 ...
The files I drooped were hitlogging*.dbf and non of them appear in the list above.
After 3-4 hours waiting to remove the possibility of cache effect, I restarted the database

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

-bash-3.00# df -h
Filesystem             size   used  avail capacity  Mounted on
/                       39G   8.8G    30G    23%    /
/dev                    39G   8.8G    30G    23%    /dev

la-ora01-db            588G    31K   316G     1%    /oradb
la-ora01-db/data       588G   217G   316G    41%    /oradb/data

Maybe some other user process hold the files? I only inspected the oracle background process and usually the most likely suspect is db file writer (dbwn).

December 20, 2011

UKOUG 2011

Another year of UKOUG conference closed its curtain. I attended all of the four days session, including the oaktable Sunday afternoon. I lost trace of how many times I went to this year end festival.
I now have some time to reflect what’s good :

Good Presentations:
A Deep Dive into the SQL monitoring Report by Greg Rahn
Oracle Optimizer: Upgraing to 11g without Pain by Maria Colgan
Oracle optimizer: Best Practices for Managing Optimizer Stats by Maria Colgan
Implementing Effective Database Auditing in 3 steps

Not too bad
user Experiences with Data Guard Fas-start Failover
Net Services – Best Practices for Performance, Scalability & High Availability by Kussi Mensah

Round Tables
Oracle scurity
RAC and HA roundtables

Keynote by Cary Millsap started to become interesting when I planned to leave. I ended up finished it.

The last day of the conference is not the best day. So if you can only go to conference for one day, don’t choose the last day.


February 16, 2011

Oracle locks

Follow-up to oracle lock – look it again from Oracle/Java/Others

Step 1


create table test (id number)
insert into test values (1);

Before commit or rollback, check the v$lock table.
Two locks:
First one’s lock type is TM (DML enqueue), Lock mode is 3 – row-x(SX), Request is 0 (none)
and
Second one’s lock type is TX (Transaction enqueue), Lock mode is 6 – exclusive (X), Request is 0 (none).

Check v$locked_object table. It displays the similar information as well

Step 2
In the same session

update test set id = 2

The locks in v$lock and v$locked_objects show same information as step 1.

Step 3
Open a new session

update test set id = 3

Now check the v$lock table
The lock associated with the first session is still same: two locks.
But the “block” column in the “TX” lock is 1 , means it is blocking another session.
The “block” column in “TM” lock is still 0.

Session 2 has two locks now:
TM lock, Lmode is 3 (SX), request is 0
TX lock, LMode is 6 (X), request is 6 (X – exclusive X)

Check the v$locked_object

The row attached to session 1 is same.
A new row attached to session 2 has same (locked_mode, object_id), but XIDUSN, XIDSLOT, XIDSQN are all zero.

Conclusion

v$locked_object is very useful. It displays 1) user 2) object_id information 3) blocker & waiter

how to find out locked object in v$lock?

Other tables

- dba_waiters: including waiters and blocker, mode_held & mode_requested
- dba_blockers: just one column holding_session.
- dba_lock_internal: Very slow to access
- v$access : Very slow to access


Search this blog

Search Warwick Blogs

 

Tags

Most recent comments

  • Oracle 11g is the clear leader in this area. Oracle has invested heavily into self–tuning capabiliti… by shaane on this entry
  • All the features are very nice.I like Repair Advisors the most.Oracle 10G introduced some of the dat… by lucy on this entry
  • "logical standby failed to re–start, I am also getting the same error. I have search on internet and… by anemia on this entry
  • Thanks for the nice information because from last three days i am stuck on this problem…. by robot vacuum on this entry
  • So what happen City speed dating when you tried this coding once in your PC.. Please tell me so i am… by John Bergeron on this entry
RSS2.0 Atom
Not signed in
Sign in

Powered by BlogBuilder
© MMXXIII