Home » RDBMS Server » Performance Tuning » Database Links (Oracle, 10g, Windows Server 2003)
Database Links [message #489977] Thu, 20 January 2011 07:46 Go to next message
faizul
Messages: 23
Registered: June 2005
Junior Member
Hi Guru's,

We have a situation where we could have our database split into two and located in single or multiple servers.

Depending on the choices our customers make, they can also install the two databases into a single database (using different schema names).

I know I can access remote databases using database links but what would happen performance ways if these remote databases were actually local database with different schema name (a loopback database link)?

Here's an example

One customer might go with the option:
ServerA.DatabaseA.SchemaA
ServerB.DatabaseB.SchemaB

and another might go with the option:
ServerA.DatabaseA.SchemaA
ServerA.DatabaseA.SchemaB

and another might go with the option:
ServerA.DatabaseA.SchemaA
ServerA.DatabaseB.SchemaB

What performance issues should I be expecting? Ideally I would like to have one set of stored procedures that work with both cases.

What can I do in a loopback case as it needs the trailing identifier?

Thanks

[Updated on: Thu, 20 January 2011 07:48]

Report message to a moderator

Re: Database Links [message #489980 is a reply to message #489977] Thu, 20 January 2011 08:07 Go to previous messageGo to next message
John Watson
Messages: 8960
Registered: January 2010
Location: Global Village
Senior Member
I wouldn't think that performance would be an issue, but data integrity might be. With a loopback database link, Oracle will think there are two databases, and two tables for storing the in-doubt transactions. But in fact, there is only one. I think this can cause problems with the two phase commit.
Re: Database Links [message #489983 is a reply to message #489980] Thu, 20 January 2011 08:16 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
And also transaction processing is not the same one, you enter the world of distributed transactions with 2-phase commits and where even SELECT generates transactions.
So yes, there will be an impact in performances, response time and throughput.

Regards
Michel

[Edit: fix typo]

[Updated on: Thu, 20 January 2011 10:53]

Report message to a moderator

Re: Database Links [message #490008 is a reply to message #489977] Thu, 20 January 2011 10:21 Go to previous messageGo to next message
Kevin Meade
Messages: 2103
Registered: December 1999
Location: Connecticut USA
Senior Member
Wow, John and Michel really took my interest here. I never would have thought to this level of detail... verying interesting.

I profess ingnorance here, but that has never stopped me from offering up an opinion so here is my few words.

1) I would be surprised to have a 2pc issue with the same table being treated as two tables. I would expect the entire thing to be transparent and work the same way regardless of if it is the same database or not. Otherwise Oracle has a serious issue with its implementation that needs to be addressed. Again however, I do not claim to know what will actually happen.

2) I wonder if a 2pc transaction will actually happen. I remember from years ago that on a DEC machine in an oracle class, we used a database link to get oracle to start a distributed transaction. But I then also recall that newer versions of oracle are actually smart enough today to know that in fact the database link points back to the same database and thus oracle does not actually go out across the network int his case, which makes me wonder if a distributed transaction will actually be initiated.

Once again I profess not to know the answers and maybe even my rememberence is bad.

I would ask John and Michel if there is a way to know when a distributed transaction has actually been started. Must be some v$ table to look at for it or some other record. If you guys can tell me how to know, I will do some work at home to see what happens by doing this an on 11gR2 database on Windows7. Might be interesting to see what I find out. I am for sure too stupid to show address or prove/disprove performance issues as alluded to by Michel but I can check to see if a distributed transaction is started when using a databse link that points back to the same database/host.

Kevin
Re: Database Links [message #490009 is a reply to message #490008] Thu, 20 January 2011 10:24 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
I once experimented with using loopback DB links to join tables within the same database together (dont ask) and hit massive performance issues.

These were just selects though.
Re: Database Links [message #490028 is a reply to message #490009] Thu, 20 January 2011 11:14 Go to previous messageGo to next message
John Watson
Messages: 8960
Registered: January 2010
Location: Global Village
Senior Member
This script
drop user jon cascade;
grant dba to jon identified by jon;
conn jon/jon
create database link l1 connect to jon identified by jon using 'orcl';
create database link l2 connect to jon identified by jon using 'orcl';
create table t1 as select * from all_users;

delete from t1@l1;
insert into t1@l2 select * from all_users;

select count(*) from v$transaction;
select count(*) from dba_2pc_pending;

shows one transaction, no pending transactions. Does that mean that Kevin is right: Oracle is clever enough to sort it out? I took the test a step further, and on a two node RAC I created the database links going to different instances, same result.
Re: Database Links [message #490033 is a reply to message #490028] Thu, 20 January 2011 11:25 Go to previous messageGo to next message
John Watson
Messages: 8960
Registered: January 2010
Location: Global Village
Senior Member
Correction! In the RAC, I don't get the same result:
RDB1> select inst_id from gv$transaction;

no rows selected

RDB1> delete from t1@l1;
insert into t1@l2 select * from all_users;

38 rows deleted.

RDB1>
38 rows created.

RDB1> select inst_id from gv$transaction;

   INST_ID
----------
         1
         2

RDB1> select count(*) from dba_2pc_pending;

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

RDB1> commit;

Commit complete.

RDB1> select inst_id from gv$transaction;

no rows selected

RDB1>

The RAC does see it as two transactions, but still nothing in dba_2pc_pending. Am I misunderstanding that view?
Re: Database Links [message #490045 is a reply to message #490033] Thu, 20 January 2011 12:28 Go to previous messageGo to next message
Kevin Meade
Messages: 2103
Registered: December 1999
Location: Connecticut USA
Senior Member
That is pretty cool stuff. I would have had to spend some time figuring out how to test it.

I found this in the oracle docs and it explains the empty table:

Quote:
DBA_2PC_PENDING
Lists all in-doubt distributed transactions. The view is empty until populated by an in-doubt transaction. After the transaction is resolved, the view is purged.


I am guessing none of your transactions are in-doubt since there was no failure after commit was issued. Thus we can't really tell yet if we are executing a distributed transactions, a remote transaction, or a local transaction, or why there are two rows in gv$transaction when using RAC.

I will keep looking for more info, but real cool stuff dude.

Kevin
Re: Database Links [message #490046 is a reply to message #490033] Thu, 20 January 2011 12:37 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
dba_2pc_pending is filled only when a 2PC is waiting for recovery not when a distributed transaction is active. DBA_2PC_NEIGHBORS is maybe a better choice for this.
But querying v$dblink (.in_transaction) is even better (although it gives less information).
For instance, I have a db loopback link from MICHEL to SCOTT, you can see the remote access via:
SQL> set autotrace traceonly explain
SQL> select * from emp@mika@scott;

Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932

----------------------------------------------------------------------------------------
| Id  | Operation              | Name | Rows  | Bytes | Cost (%CPU)| Time     | Inst   |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT REMOTE|      |    14 |  1218 |     3   (0)| 00:00:01 |        |
|   1 |  TABLE ACCESS FULL     | EMP  |    14 |  1218 |     3   (0)| 00:00:01 |   MIKA |
----------------------------------------------------------------------------------------

Note
-----
   - fully remote statement
   - dynamic sampling used for this statement

See the "SELECT REMOTE", the first note "fully remote statement" and the "Inst" column telling on which site the line is executed.
Now if I query v$dblink I get:
SQL> select logged_on, in_transaction, update_sent from v$dblink 
  2  where db_link='MIKA.XXX@SCOTT';
LOG IN_ UPD
--- --- ---
YES NO  NO

The point there is that Oracle is smart enough to see it is a loopback db link and does not start a transaction has it would do with a remote site but it still treat it as it when optimizing the query.
Now if I make an update:
SQL> update emp@mika@scott set sal=sal+1;

14 rows updated.

SQL> select logged_on, in_transaction, update_sent from v$dblink 
  2  where db_link='MIKA.XXX@SCOTT';
LOG IN_ UPD
--- --- ---
YES YES YES

SQL> select sys_context('userenv','sid') mysid, sid, username 
  2  from v$transaction t, v$session s where t.ses_addr = s.saddr;
MYSID             SID USERNAME
---------- ---------- ------------------------------
159               159 MICHEL

SQL> select sid from v$session where username='SCOTT';
       SID
----------
       139

There is only one transaction going-on and my session is the owner of this transaction when there should be 2 transactions going-on in a real remote case one for MICHEL and one for SCOTT.
So we have not a distributed transaction, this is a good point - I was wrong.
But the optimizer still thinks it is a remote or distributed statement and acts as it, this is the bad point.
SQL> set autotrace traceonly explain
SQL> update emp@mika@scott set sal=sal+1;

14 rows updated.


Execution Plan
----------------------------------------------------------
Plan hash value: 1494045816

----------------------------------------------------------------------------------------
| Id  | Operation              | Name | Rows  | Bytes | Cost (%CPU)| Time     | Inst   |
----------------------------------------------------------------------------------------
|   0 | UPDATE STATEMENT REMOTE|      |    14 |   182 |     3   (0)| 00:00:01 |        |
|   1 |  UPDATE                | EMP  |       |       |            |          |   MIKA |
|   2 |   TABLE ACCESS FULL    | EMP  |    14 |   182 |     3   (0)| 00:00:01 |   MIKA |
----------------------------------------------------------------------------------------

Note
-----
   - fully remote statement
   - dynamic sampling used for this statement

Note that during this test DBA_2PC_NEIGHBORS was always empty.

Regards
Michel

[Edit: remove domain name]

[Updated on: Thu, 20 January 2011 13:37]

Report message to a moderator

Re: Database Links [message #490053 is a reply to message #490046] Thu, 20 January 2011 13:19 Go to previous messageGo to next message
Kevin Meade
Messages: 2103
Registered: December 1999
Location: Connecticut USA
Senior Member
I remember when it worked exactly like you stated Michel. You were not wrong in that sense. It is only the more recent releases that got smarter about it.

Since the individual sql statement you are showing is labeled as FULLY REMOTE, that means all objects required by the sql statement live on the same node. I would thus expect optimization to be done for this sql statment with that in mind so I would not expect query plans to change (though I have seen dumber things happen eh!).

This is real cool for me to see you guys reason this out. Thanks.

Kevin
Re: Database Links [message #490056 is a reply to message #490053] Thu, 20 January 2011 13:30 Go to previous messageGo to next message
Kevin Meade
Messages: 2103
Registered: December 1999
Location: Connecticut USA
Senior Member
I seem to recall also that when a distributed transaction is started, a DISTRIBUTED TRANSACTION LOCK will be taken and this is visible from V$LOCK as DX. Maybe we can use that to see if Oracle is treating things like a distributed transaction.

Kevin
Re: Database Links [message #490058 is a reply to message #490053] Thu, 20 January 2011 13:35 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
I remember when it worked exactly like you stated Michel.

I remember too but I should test again each piece at each version. By the ages of versions 7 and 8.* I did it but after that pieces (features) were too numerous and versions come too fast to be able to just test the new features.
Just to name a few: locks on SELECT FOR UPDATE changed between 2 patchsets of 9.2; locks on DDL change at each version; in 11g it is no more necessary to index foreign key there is no more lock on the whole child table if it is not indexed when you update/delete a parent row, without speaking about all these "ONLINE" statements that also change the locks at each version...

Regards
Michel
Re: Database Links [message #490070 is a reply to message #490058] Thu, 20 January 2011 14:48 Go to previous message
John Watson
Messages: 8960
Registered: January 2010
Location: Global Village
Senior Member
Faizul: I must apologize for your thread being hi-jacked. I guess you can tell that no-one knows for sure what will happen with your database link solution, but it doesn't sound like a good idea.
---
I've tried to globalize Michel's example, with DML through links to the two instances:
RDB1> select inst_id from gv$transaction;

no rows selected

RDB1> select logged_on, in_transaction, update_sent from v$dblink;

no rows selected

RDB1> delete from t1@l1 where username='SYS';

1 row deleted.

RDB1> delete from t1@l2 where username='SYSTEM';

1 row deleted.

RDB1> select inst_id from gv$transaction;

   INST_ID
----------
         1
         2

RDB1> select logged_on, in_transaction, update_sent from v$dblink;

LOG IN_ UPD
--- --- ---
YES YES YES
YES YES YES

RDB1> select * from dba_2pc_neighbors;

no rows selected

RDB1> commit;

Commit complete.

RDB1> select inst_id from gv$transaction;

no rows selected

RDB1> select logged_on, in_transaction, update_sent from v$dblink;

LOG IN_ UPD
--- --- ---
YES NO  NO
YES NO  NO

RDB1>

Was there a two phase commit? If I understand Michel's post correctly, a distributed transaction should show as one transaction in the source database, plus one transaction in the linked database. So in my example with two updates through different links, I would expect to see three transactions, if it is being managed by 2PC. If it is not being managed by 2PC, does that mean that I could end up with half the transaction committed, if one of the instances fails? Because Oracle has realized that it is only one database, but has not realized that it is two instances which commit independently?

I do of course realize that this is of no practical value: you would need to be a complete lunatic (or a DBA stuck in a hotel room in Geel, which is in Belgium) to construct this example.


Previous Topic: AWR report in 11g standard not supported?
Next Topic: Query regarding tkprof output and cardinality in it
Goto Forum:
  


Current Time: Mon Nov 25 03:05:55 CST 2024