2010年12月9日

Email Notifytion When Oracle Stream Replication Fail

All object in schema FRAME are replicated by Oracle Stream Replication. I create a job to check the data in table FRAME.SYS_STREAM_REPLICATION if they are same in source database and destination database.

If the data are different, use UTL_MAIL to send an email to me .
create table FRAME.SYS_STREAM_REPLICATION
(
  COL      NUMBER,
  SMS_SENT NUMBER
);

comment on table FRAME.SYS_STREAM_REPLICATION
  is '数据库同步测试表';
comment on column FRAME.SYS_STREAM_REPLICATION.SMS_SENT
  is '1 已发送,  0未发送';
grant select, insert, update, delete on FRAME.SYS_STREAM_REPLICATION to STREAMADMIN;
/* 检测数据库复制是否正常 */
declare
  src_value number;
  dest_value number;
  sms_sent number;
  err varchar2(3000);
BEGIN
  select col,sms_sent into src_value,sms_sent from frame.sys_stream_replication;
  select col into dest_value from frame.sys_stream_replication@dest_db;
  if src_value<> dest_value then  
     if sms_sent<>'1' then 
        UTL_MAIL.send(sender => 'name@domain.com',
            recipients => 'name@domain.com',
               subject => 'Database Stream Replication Fail',
               message => 'Hello World',
             mime_type => 'text; charset=us-ascii');
          
         insert into frame.sms_info_prepare_send  (sms_id,mobile_no,sms_content) values ('999'||src_value,'18912345678','Oracle Stream Replication Fail!');
         update  frame.sys_stream_replication set sms_sent='1';
     end if;
   else
     update frame.sys_stream_replication set col=col+1, sms_sent='0';

   end if;
   commit;
  EXCEPTION
  WHEN OTHERS THEN
    err := SQLERRM;
    ROLLBACK;    
      INSERT INTO job_log
             (date_time, err, remark)
      VALUES
             (sysdate,  err, '检测数据库复制是否正常 job 65');
  COMMIT;
END;

2010年9月27日

DML SQL with keyword SYSDATE may cause trouble in Oracle Stream Replication

Tow database, one way replication, if you execute DML SQL like "insert into tab (id, operate_time) values ('1',SYSDATA)" in source database. this exactly SQL will execute in destination database too, but it will execute on destination database short after the executing of source database.

(I think the period is not short sometimes, if some network problem occurs, or some other operation delay the executing on destination database.)

Yes, this SQL do not execute at same time on source database and the destination database. and the column operate_time will have different value in the two database.

OK, the value of column operate_time in two database have little different, it is not a big problem. I don't care!

Latter, I execute this SQL: "delete tab where 1=1" in source database. Oops, I got this ORA-26786 shit in destination database

My Mon

There are many peddler along the street. They sell fruits, vegetables, snack. It is too usual so that we often ignore their exists. But a few of them do touch me.

They are not mongering, the fruits or vegetables that they sell are planted by themselves. In fact, they are farmer.

Obviously, they are new here, and not have enough selling experiences. The goods may be not good looking. They haven't take a good place to sell. So They still sell even it is very late.

Their eyes tell me They are worrying about how to deal with their goods. It makes me sorrow.

My parents sell orange every winter. To take a good place, they must reach town before sun rise. So they set out about 4:00AM. They go to town by feet, carrying 50kg oranges. There is no bus because it is too early, the whole travel is by feet. And there is a hill block the way, they must go over it.

How to make self wake at 4:00AM? Alarm clock? No, most of farmer have not got that. They drink a lot water before sleep. It is much more useful than an alarm clock.

The burden is heavy. It make them sweating. But it would change minutes latter after arrival. It is so cold in winter, especially the clothes have been wet by sweat.

As industrious farmers, the difficulties above are just pieces of cake. The real discouraging is that oranges have not sold out.

That is the life of my parents 8 years before. My mom have went to heaven 5 years.

Yes, it is make me real sad that I saw a farmer with lots of fruit or vegetables not sold.

Bowl Lotus

Bowl lotus, also called mini lotus, It is a kind of small lotus that you can plant it in a big bowl. If you love Lotus, you can grow it in your yard or balcony, because she lives in water, So you don't need to water her carefully, just keep here in water will be OK. But remember, She loves sunshine very much, she may not flower if she did not get enough sunshine.

The following photoes are Lotus growed in 2008 by me.

 Leaves

 First Daughter

She is Growing Up 

 All Children

 Close Up to First Daughter

Fructus

Chinese Characters in Foreign Eyes

Elizabeth, one of my friends in MSN, is a pretty Russian girl.

One day, I recommended her a Chinese folk music "梁祝" to her. I told her, this music named "Liang & Zhu", it is based on a love story in Chinese folk legend, a love story about a guy named "Liang" and a lady named "Zhu". She thinks it is a beautiful music. and shows great interesting in Chinese characters.

So, I introduced Chinese character to her. I said, some Chinese character are paintings. for example, "山" means hill in Chinese.

She told me, in Russian, "Ш" means hill. and she thinks, "Ш" is better than "山", because "山" looks more like a crown. and she said, "说" looks like a octopus.

Interesting girl. lol.

And I tell her another interesting Chinese character, "休". "亻"is a guy, "木" is a tree, "休" is a guy cling to a tree, means "have a rest".

She thought it is amazing, and wanna know what is her name in Chinese.

I told her it is 伊丽莎白, pronounced by "yee-lee-sa-bei". In Chinese, 伊 means "she", 丽 mans "pretty", 莎 often use to name a girl, a girl may called 莎莎. 白 is "White".

She loves her new name very much. and change her name to 伊丽莎白 in her blog as soon as possible ...

This artice is wrote on 2008-07-30

My home town

All pictures are photographed in my home town. some of them can see in Google Earth.

I was catching fireflies in the fields, I was swimming in the lake, I was searching wild fruit around the hills.

Lots of laughs have been left here, lots of happiness have been left here.

I will get me a tent and boat, spend weekend here.










You may want to check out the locations of these pictures, go http://www.panoramio.com/user/1244283

This ariticle is writen on 2008-07-01

SSH 端口转发

再说如何使用SSH端口转发前,我们先看看它的作用

如上图,主机A1和主机B1可以互相访问,A1,A2可以互相访问;B1,B2可以互相访问。其它主机之间不能直接访问。
SSH端口转发的神奇之处在于:我们我们可以让A2访问网络B的主机B1和B2;让B2访问A1和A2。有如下3个ssh端口转发方法可以达到这个目的
  • ssh -C -f -N -g -L listen_port:DST_Host:DST_port user@Tunnel_Host

    • 在ssh客户端(本地)监听端口(listen_port),此端口的访问被转到DST_Host的DST_port
    • ssh服务端(Tunnel_Host)必须能成常访问DST_Host:DST_port
    • 应用举例:(以下操作均在本地机器上执行,本地机器的ip为1.1.1.34,这是在局域网内手动指定的一个ip)



        aray:~# ifconfig eth0
        eth0      Link encap:Ethernet  HWaddr 00:25:b3:74:b6:eb  
                  inet addr:1.1.1.34  Bcast:1.1.1.255  Mask:255.255.255.0
                  inet6 addr: fe80::225:b3ff:fe74:b6eb/64 Scope:Link
                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                  RX packets:134567 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:70777 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000 
                  RX bytes:173447487 (165.4 MiB)  TX bytes:5818516 (5.5 MiB)
                  Interrupt:17 
        
        aray@aray:~$ ssh -C -f -N -g -L 9999:192.168.1.1:80 araycn.3322.org
        Warning: Permanently added the RSA host key for IP address '222.182.90.241' to the list of known hosts.
        aray@araycn.3322.org's password: 
        bind: Address already in use
        
        aray@aray:~$ ssh -C -f -N -g -L 1.1.1.34:9998:192.168.1.1:80 araycn.3322.org
        aray@araycn.3322.org's password: 
        
        aray@aray:~$ netstat -nap | grep ssh | grep tcp
        (Not all processes could be identified, non-owned process info
         will not be shown, you would have to be root to see it all.)
        tcp        0      0 1.1.1.34:9998           0.0.0.0:*               LISTEN      4367/ssh        
        tcp        0      0 1.1.1.34:32903          222.182.90.241:22       ESTABLISHED 4352/ssh        
        tcp        0      0 1.1.1.34:34268          222.182.90.241:22       ESTABLISHED 4367/ssh        
        tcp6       0      0 :::9999                 :::*                    LISTEN      4352/ssh   
        
        注意: ssh -C -f -N -g -L 1.1.1.34:9998:192.168.1.1:80 araycn.3322.org 这个指定本地只监听1.1.1.34这个ip,如果不指定1.1.1.34,则监听所有网络连接。
        现在本地机器(1.1.1.34)所在的局域网内的所有机器,都可以访问http://1.1.1.34:9998或者http://1.1.1.34:9999,来打开远程局域网里的网页http://192.168.1.1了
  • ssh -C -f -N -g -R listen_port:DST_Host:DST_port user@Tunnel_Host

    • 在远ssh服务端(Tunnel_Host)上,监听端口(listen_port),访问远程服务器的端口listen_port,就等于访问了本地机器访问得到的DST_Host的端口DST_Port)
  • ssh -C -f -N -g -D listen_port user@Tunnel_Host

    • 在ssh客户端建立一个SOCKETS4代理服务器,这个代理服务器监听本地的listen_port,通过这个代理服务器,能访问到Tunnel_Host访问得到的仍和服务器。