Tuesday, December 26, 2006

DB2: How to stop DB2 instance

SQL1025N The database manager was not stopped because databases are still active.
Often I met this problem when I want to stop the db2 instance using "db2stop"
Here is the solution:http://safari5.bvdep.com/0130463884/app07

This appendix describes the necessary steps to stop and start a DB2 instance. There are many ways to stop and start a DB2 instance, but the following steps will guide you to stop a DB2 instance to ensure that any defunct DB2 processes, interprocess communications, and defunct DARI processes have been removed successfully.

Current configuration:

Instance:db2inst1
Database:sample
Server:phantom

  1. Stop the DB2 instance.

    • Check existing applications that are currently connected to the database by logging on to phantom server as DB2 instance owner db2inst1:

      $ db2 list applications

      Auth Id Appl. Name Appl.. Handle Appl. Id DB Name # of Agents
      ------- ---------- ------------- ---------------------------- ------- -----------
      DB2INST1 db2bp 207 *LOCAL.db2inst1.010824003917 SAMPLE 1
      DB2INST1 java 276 CCF21FFC.E5D8.010829004049 SAMPLE 1
      DB2INST1 java 51 CCF21FFC.E5D9.010829004051 SAMPLE 1


    • If there is any application connected to the database, you can tell who is currently connected and from which location they are connected. In this case, there is one local connection from db2inst1 user ID, and there are two remote connections from IP address: 204.242.31.252 converted from hex to decimal: CCF21FFC.

    • For remote connections, after you get the IP address, you can get the hostname by issuing the nslookup command:

      $ /usr/sbin/nslookup 204.242.31.252

      Server: charter.phantom.com
      Address: 204.242.31.83

      Name: phantom.phantom.com
      Address: 204.242.31.252
    • If there are any applications connected to the database, verify that they are not currently executing:

      $ db2 list applications show detail | egrep –i "executing|pending" 
    • If there are applications executing or pending, you can now force them off. Then verify to make sure there is no application connected to the database. If you see the following message, you're ready to stop the DB2 instance:

      $ db2 force application all

      DB20000I The FORCE APPLICATION command completed successfully.
      DB21024I This command is asynchronous and may not be effective immediately.

      $ db2 list applications

      SQL1611W No data was returned by Database System Monitor. SQLSTATE=00000


    • Now you can stop the DB2 instance. When you get the message "SQL1064N DB2STOP processing was successful" you're ready to do the next step. If you get the message below, you must start this step again:

      $ db2stop

      SQL1025N The database manager was not stopped because databases are still active.


    • LAST RESORT. If for some reason you cannot stop the DB2 instance or DB2 commands are hung, you must run this utility to remove the DB2 engine and client's IPC resources for that instance. This is your lifesaver:

      $ ipclean

      ipclean: Removing DB2 engine and client's IPC resources for db2inst1.
  2. Stop the DB2 Administration Server instance.

    • Skip this step if DB2 Admin instance is not running; otherwise, execute this command:

    $ db2admin stop 
  3. Remove defunct DARI processes, DB2 background processes, or other defunct threads.

    • List all DB2 processes for this instance:

      $ ps –ef | grep db2

      db2as 23797 23796 0 Aug 28 ? 0:00 db2sysc
      db2as 23800 23798 0 Aug 28 ? 0:00 db2sysc
      db2inst1 22229 1 0 13:08:01 pts/5 0:00 /db2/dbhome/db2inst1/sqllib/bin/db2bp 20580 5
      db2as 23802 23797 0 Aug 28 ? 0:00 db2sysc
      db2as 23801 23797 0 Aug 28 ? 0:00 db2sysc
      db2as 23799 23797 0 Aug 28 ? 0:00 db2sysc


    • From the list above, we notice that there are processes belonging to the DB2 Admin services instance, so you must leave them alone. There is only one process that belongs to db2inst1, and that is a DB2 background process that did not get cleaned up after executing ipclean. Get the PID number and kill that process:

      $ kill –9 22229 
    • Most of the time, you will see many defunct processes, and to save time, you should execute the following command instead of executing the kill -9 ${PID} command many times:

      $ ps –ef | grep db2inst1 | awk '{print "kill –9 "$2}' > /tmp/kpid
      $ chmod +x /tmp/kpid
      $ /tmp/kpid
    • Verify that no defunct processes are left. Repeat this step if necessary:

      $ ps –ef | grep db2inst1 
  4. Remove defunct interprocess communication segments.

    • List all memory segments:

      $ ipcs –am | grep db2inst1

      IPC status from as of Thu Aug 30 13:16:55 2001
      T ID KEY MODE OWNER GROUP
      Shared Memory:
      m 9910 0x74006380 --rw-rw-rw- db2inst1 db2grp
      m 59714 0x61006380 --rw------- db2inst1 db2grp
    • From the list above, you notice that there are two memory segments that were not removed when executing ipclean. You must remove them manually:

      $ ipcrm –m 9910
      $ ipcrm –m 59714
    • List all semaphore segments:

      $ ipcs –as | grep db2inst1

      IPC status from as of Thu Aug 30 13:16:55 2001
      T ID KEY MODE OWNER GROUP
      Shared Memory:
      s 1900549 0x74006380 --ra-ra-ra- db2inst1 db2grp 1
      s 1310727 00000000 --ra-ra---- db2inst1 db2grp 1
      s 2031624 0x73006380 --ra-ra-ra- db2inst1 db2grp 1
    • From the list above, notice that there are three semaphore segments that were not removed after executing ipclean. You must remove them manually:

      $ ipcrm –s 1900549
      $ ipcrm –s 1310727
      $ ipcrm –s 2031624
    • List all message queue segments:

      $ ipcs –aq | grep db2inst1

      IPC status from as of Thu Aug 30 13:16:55 2001
      T ID KEY MODE OWNER GROUP
      Shared Memory:
      q 1572868 0x01dadd16 -Rrw------- db2inst1 db2grp 65535
      q 901125 0x01eba5ed --rw------- db2inst1 db2grp 65535
      q 1609739 00000000 --rw------- db2inst1 db2grp 65535
      q 659468 00000000 -Rrw------- db2inst1 db2grp 65535
    • From the list above, notice that there are four message queue segments that were not removed after executing ipclean. You must remove them manually:

      $ ipcrm –q 1572868
      $ ipcrm –q 901125
      $ ipcrm –q 1609739
      $ ipcrm –q 659468
    • Verify that there are no defunct interprocess communications left. Repeat this step if necessary:

      $ ipcs –a | grep db2inst1 
  5. Before you start the DB2 instance, it is best practice to back up the previous db2diag.log, any event logs, notification log, and the associated trap files, and start with a fresh copy.

    • Move the current db2diag.log to the backup directory:

      $ mkdir –p /db2/backup/db2inst1/diaglogSep12
      $ cd /db2/dbhome/db2inst1/sqllib/db2dump
      $ mv db2diag.log /db2/backup/db2inst1/diaglogSep12/
      $ mv db2eventlog* /db2/backup/db2inst1/diaglogSep12/
      $ mv db2inst1.nfy /db2/backup/db2inst1/diaglogSep12/
      $ touch db2diag.log db2inst1.nfy db2eventlog.nnn where nnn is the database partition number
      $ chmod 666 db2diag.log db2inst1.nfy db2eventlog.*


    • If there are any trap files, group them together:

      $ cd /db2/dbhome/db2inst1/sqllib/db2dump
      $ tar –cvf /db2/backup/db2inst1/diaglog/trapAug292001.tar t* c* l* [0-9]*
    • Or execute this keepDiagLog.sh script:

      #!/bin/ksh
      #
      # Clean up db2diag.log, trap files, dump files, etc
      #
      # Usage: keepDiagLog.sh
      #
      # Execute as DB2 instance owner
      #
      LOGTIME=`date '+%y%m%d%H%M%S'`
      DIAGDIR=${HOME}/sqllib/db2dump
      typeset instname=${1-db2inst1}
      typeset ROOTDIR=${2-/dbbackup}
      typeset dbname=${3-sample}
      typeset OLDDIR=${4-${ROOTDIR}/${instname}/${dbname}/db2diag${LOGTIME}}
      mkdir –p ${OLDDIR}
      cd ${DIAGDIR}
      cp –r * ${OLDDIR}/
      for j in `ls`
      do
      if [ -d "${j}" ]; then
      rm –r ${j}
      else
      rm ${j}
      fi
      done
      touch db2diag.log ${instname}.nfy
      chmod 666 db2diag.log ${instname}.nfy
      exit 0
      # You need to add the steps for the event log files based on the
      # number of database partitions defined on your server.


  6. Now you're ready to start the DB2 instance.

    • Start the DB2 instance:

      $ db2start

      SQL1063N DB2START processing was successful.
  7. And you're ready to start the DB2 Admin instance.

    • Start the DB2 Admin instance:

      $ db2admin start 
  8. Verify the database connection.

    • Connect to the sample database:

      $ db2 connect to sample

      Database Connection Information
      Database server = DB2/SUN 8.1.0
      SQL authorization ID = DB2INST1
      Local database alias = SAMPLE
    • Disconnect from the sample database:

      $ db2 terminate 
  9. Reactivate the database to improve performance.

    • Activate the sample database:

      $ db2 activate database sample

      DB20000I The ACTIVATE DATABASE command completed successfully.

Wednesday, December 20, 2006

Such is the power of the Long Tail. Its time has come

不知不觉,google上搜到的东西很多都带了一个“长尾”关键词,这令我很是纳闷,从字面上看长长的尾巴?八成是从国外飘来的,于是又搜到了 “The Long Tail” by Chris Anderson in 2004.
2004年10月,《连线》杂志主编Chris Anderson在一篇文章中,首次提出了一个“长尾理论”(The long tail)来解释这一现象:只要渠道足够大,非主流的、需求量小的商品销量也能够和主流的、需求量大的商品销量相匹敌。
长尾的力量说明了新娱乐经济的新法则,借用《The Long Tail》原著中的话,可以概括为3点:
1. 要应有尽有
任何东西,只要有一点点的机会能找到买主,它就有存在的价值
2. 比半价还要更便宜
3. 引导用户去探索
(比如现在很多网站做的根据用户的喜好来推荐的功能,下载此书的用户还下载了....)

长尾商业通过在大众化产品之外提供众多的个性化定制,从而做到区别对待每一个个体的客户。

当然,长尾理论初初看来是新鲜出炉,但是确是Chris 根据美国的一些互联网英雄如Amazon, Netflix, iTunes的成功模式总结出来的,他所提出的推动型模式与拉动型模式的结合,广泛性与个性化的统一,可以为众多网络创业的公司提供指引。

但是这种模式是否可以为中国的音乐,娱乐的网络创业带来成功,就要拭目以待了....

Tuesday, December 19, 2006

GAS 回来, office的一天

我在GAS的使命终于结束了, 回到office这个大家庭,meeting, learning忙的不亦乐乎.
毕竟是错过了这半年的一些东西,因此处于catch-up阶段的我竟然很不适应,是自己忙碌惯了,不希望自己总是旁边看...
今天老板虽然没有批我,自己却羞得无地自容,ISO的东西早就弄完,也懒得去一遍有一遍的review, 但是有些事情却非做不可,而且不是可以选择的,让我想起了刚开始做intern的时候,要迭代的修改好多的UC,但两者的不同在于,至少后者我是感兴趣的 (: 不过怎样,既然担当起了这样的角色,就要把事情做好,因此今天晚上把DOM更新完毕.
以前不了解老板,今天忽然发现人做到什么位置都是有他的理由的,比如说想的周到,我想到一步,老板却想到两步,这跟vision是相关的.
知耻而后勇----
今天在team member 面前觉得很羞愧,现在才去了解一个system, 总比别人知道的少,希望我的Rachel尽快赶回来...