{"id":1148,"date":"2012-03-30T11:15:42","date_gmt":"2012-03-30T03:15:42","guid":{"rendered":"http:\/\/learn-house.idv.tw\/?p=1148"},"modified":"2012-09-05T22:50:07","modified_gmt":"2012-09-05T14:50:07","slug":"db2%e8%b3%87%e6%96%99%e5%ba%ab%e5%b8%b8%e7%94%a8%e6%8c%87%e4%bb%a4%e5%a4%a7%e5%85%a8","status":"publish","type":"post","link":"https:\/\/learn-house.idv.tw\/?p=1148","title":{"rendered":"DB2\u8cc7\u6599\u5eab\u5e38\u7528\u6307\u4ee4\u5927\u5168"},"content":{"rendered":"<p>\u7db2\u8def\u8f49\u8f09<\/p>\n<p>*\u547d\u4ee4\u5217\u7a97\u53e3*<\/p>\n<p>#\u6253\u958b\u547d\u4ee4\u5217\u8996\u7a97<br \/>\ndb2cmd<br \/>\n#\u6253\u958b\u63a7\u5236\u4e2d\u5fc3<br \/>\ndb2cmd db2cc<br \/>\n#\u6253\u958b\u547d\u4ee4\u7de8\u8f2f\u5668<br \/>\ndb2cmd db2ce<br \/>\n<!--more-->*\u64cd\u4f5c\u8cc7\u6599\u5eab\u547d\u4ee4*<\/p>\n<p>#\u555f\u52d5\u8cc7\u6599\u5eab\u5be6\u4f8b<br \/>\ndb2start<br \/>\n#\u505c\u6b62\u8cc7\u6599\u5eab\u5be6\u4f8b<br \/>\ndb2stop<br \/>\n\u5982\u679c\u4f60\u4e0d\u80fd\u505c\u6b62\u8cc7\u6599\u5eab\u7531\u65bc\u555f\u52d5\u7684\u9023\u63a5\uff0c\u5728\u904b\u884cdb2stop\u524d\u57f7\u884cdb2 force<br \/>\napplication all\u5c31\u53ef\u4ee5\u4e86<br \/>\n#\u5275\u5efa\u8cc7\u6599\u5eab<br \/>\ndb2 create db [dbname]<br \/>\n#\u9023\u63a5\u5230\u8cc7\u6599\u5eab<br \/>\ndb2 connect to [dbname] \u00a0user [username] using [password]<br \/>\n#\u65b7\u958b\u8cc7\u6599\u5eab\u9023\u63a5<br \/>\ndb2 connect reset<br \/>\n#\u5217\u51fa\u6240\u6709\u8cc7\u6599\u5eab<br \/>\ndb2 list db directory<br \/>\n#\u5217\u51fa\u6240\u6709\u555f\u52d5\u7684\u8cc7\u6599\u5eab<br \/>\ndb2 list active databases<br \/>\n#\u5217\u51fa\u6240\u6709\u8cc7\u6599\u5eab\u914d\u7f6e<br \/>\ndb2 get db cfg<br \/>\n#\u522a\u9664\u8cc7\u6599\u5eab<br \/>\ndb2 drop database [dbname]<\/p>\n<p>*\u64cd\u4f5c\u8cc7\u6599\u8868\u547d\u4ee4*<\/p>\n<p>#\u5217\u51fa\u6240\u6709\u7528\u6236\u8868<br \/>\ndb2 list tables<br \/>\n#\u5217\u51fa\u6240\u6709\u7cfb\u7d71\u8868<br \/>\ndb2 list tables for system<br \/>\n#\u5217\u51fa\u6240\u6709\u8868<br \/>\ndb2 list tables for all<br \/>\n#\u5217\u51fa\u7cfb\u7d71\u8868<br \/>\ndb2 list tables for system<br \/>\n#\u5217\u51fa\u7528\u6236\u8868<br \/>\ndb2 list tables for user<br \/>\n#\u5217\u51fa\u7279\u5b9a\u7528\u6236\u8868<br \/>\ndb2 list tables for schema [user]<\/p>\n<p>#\u5275\u5efa\u4e00\u500b\u8207\u8cc7\u6599\u5eab\u4e2d\u67d0\u500b\u8868(t2)\u7d50\u69cb\u76f8\u540c\u7684\u65b0\u8868(t1)<br \/>\ndb2 create table t1 like t2<\/p>\n<p>#\u5c07\u4e00\u500b\u8868t1\u7684\u8cc7\u6599\u5c0e\u5165\u5230\u53e6\u4e00\u500b\u8868t2<\/p>\n<p>db2 \u201cinsert into t1 select * from t2\u2033<\/p>\n<p>#\u67e5\u8a62\u8868<br \/>\ndb2 \u201cselect * from table name where \u2026\u201d<br \/>\n#\u986f\u793a\u8868\u7d50\u69cb<br \/>\ndb2 describe table tablename<br \/>\n#\u4fee\u6539\u5217<br \/>\ndb2 alter table [tablename] alter column [columname] set data type<br \/>\nvarchar(24)<\/p>\n<p>*\u6307\u4ee4\u6a94\u64cd\u4f5c\u547d\u4ee4*<\/p>\n<p>#\u57f7\u884c\u6307\u4ee4\u6a94<br \/>\ndb2 -tvf scripts.sql<\/p>\n<p>*\u5e6b\u52a9\u547d\u4ee4*<\/p>\n<p>#\u67e5\u770b\u547d\u4ee4\u5e6b\u52a9<br \/>\ndb2 ? db2start<br \/>\n#\u67e5\u770b\u932f\u8aa4\u78bc\u8cc7\u8a0a<br \/>\ndb2 ? 22001<\/p>\n<p>******************************************************************************<\/p>\n<p>\u555f\u52d5DB2\u670d\u52d9\uff1adb2start<br \/>\n\u95dc\u9589DB2\u670d\u52d9: db2stop<\/p>\n<p>\u4e00\u3001\u8f09\u5165\u6578\u64da\uff1a<br \/>\n1\u3001 \u4ee5\u9ed8\u8a8d\u5206\u9694\u7b26\u865f\u8f09\u5165,\u9ed8\u8a8d\u70ba\u201c,\u201d\u865f<br \/>\ndb2 \u201cimport from btpoper.ixf of ixf insert into btpoper\u201d<br \/>\n2\u3001 \u4ee5\u6307\u5b9a\u5206\u9694\u7b26\u865f\u201c|\u201d\u8f09\u5165<br \/>\ndb2 \u201cimport from btpoper.ixf of ixf modified by coldel| insert into btpoper\u201d<br \/>\n\u4e8c\u3001\u5378\u8f09\u6578\u64da\uff1a<br \/>\n1\u3001 \u5378\u8f09\u4e00\u500b\u8868\u4e2d\u5168\u90e8\u8cc7\u6599<br \/>\ndb2 \u201cexport to btpoper.ixf of ixf select * from btpoper\u201d<br \/>\ndb2 \u201cexport to btpoper.ixf of ixf modified by coldel| select * from btpoper\u201d<br \/>\n2\u3001 \u5e36\u689d\u4ef6\u5378\u8f09\u4e00\u500b\u8868\u4e2d\u8cc7\u6599<br \/>\ndb2 \u201cexport to btpoper.txt of del select * from btpoper where<br \/>\nbrhid=\u2019907020000\u2032\u201d<br \/>\ndb2 \u201cexport to cmmcode.ixf of ixf select * from cmmcode where codtp=\u201901\u2032\u201d<br \/>\ndb2 \u201cexport to cmmcode.ixf of ixf modified by coldel| select * from<br \/>\ncmmcode where codtp=\u201901\u2032\u201d<br \/>\n\u4e09\u3001\u67e5\u8a62\u8cc7\u6599\u7d50\u69cb\u53ca\u8cc7\u6599\uff1a<br \/>\ndb2 \u201cselect * from btpoper\u201d<br \/>\ndb2 \u201cselect * from btpoper where brhid=\u2019907020000\u2032 and oprid=\u20190001\u2032\u201d<br \/>\ndb2 \u201cselect oprid,oprnm,brhid,passwd from btpoper\u201d<br \/>\n\u56db\u3001\u522a\u9664\u8868\u4e2d\u8cc7\u6599\uff1a<br \/>\ndb2 \u201cdelete from btpoper\u201d<br \/>\ndb2 \u201cdelete from btpoper where brhid=\u2019907020000\u2032 or brhid=\u2019907010000\u2032\u201d<br \/>\n\u4e94\u3001\u4fee\u6539\u8868\u4e2d\u8cc7\u6599\uff1a<br \/>\ndb2 \u201cupdate svmmst set prtlines=0 where brhid=\u2019907010000\u2032 and jobtp=\u201902\u2032\u201d<br \/>\ndb2 \u201cupdate svmmst set prtlines=0 where jobtp=\u201902\u2032 or jobtp=\u201903\u2032\u201d<br \/>\n\u516d\u3001\u806f\u63a5\u8cc7\u6599\u5eab<br \/>\ndb2 connect to btpdbs<br \/>\n\u4e03\u3001\u6e05\u9664\u8cc7\u6599\u5eab\u806f\u63a5<br \/>\ndb2 connect reset \u00a0 \u00a0\u65b7\u958b\u8cc7\u6599\u5eab\u9023\u63a5<br \/>\ndb2 terminate \u00a0 \u00a0 \u00a0 \u00a0\u65b7\u958b\u8cc7\u6599\u5eab\u9023\u63a5<br \/>\ndb2 force applications all \u00a0 \u00a0\u65b7\u958b\u6240\u6709\u8cc7\u6599\u5eab\u9023\u63a5<br \/>\n\u516b\u3001\u5099\u4efd\u8cc7\u6599\u5eab<br \/>\n1\u3001 db2 backup db btpdbs<br \/>\n2\u3001 db2move btpdbs export<br \/>\ndb2look -d btpdbs -e -x [-a] -o crttbl.sql<br \/>\n\u4e5d\u3001\u6062\u5fa9\u8cc7\u6599\u5eab<br \/>\n1\u3001 db2 restore db btpdbs without rolling forward<br \/>\n2\u3001 db2 -tvf crtdb.sql<br \/>\ncrtdb.sql\u6a94\u5167\u5bb9\uff1acreate db btpdbs on \/db2catalog<br \/>\ndb2 -stvf crttbl.sql<br \/>\ndb2move btpdbs import<br \/>\n\u5341\u3001DB2\u5e6b\u52a9\u547d\u4ee4\uff1a<br \/>\ndb2 ?<br \/>\ndb2 ? restroe<br \/>\ndb2 ? sqlcode (\u4f8b\uff1adb2 ? sql0803) \u6ce8\uff1acode\u5fc5\u9808\u70ba4\u4f4d\u6578\uff0c\u4e0d\u59204\u4f4d\uff0c\u524d\u9762\u88dc0<\/p>\n<p>\u5341\u4e00\u3001bind\u547d\u4ee4\uff1a\u5c07\u61c9\u7528\u7a0b\u5f0f\u8207\u8cc7\u6599\u5eab\u4f5c\u4e00\u6346\u7d81,\u6bcf\u6b21\u6062\u5fa9\u8cc7\u6599\u5eab\u5f8c\uff0c\u5efa\u8b70\u90fd\u8981\u505a<br \/>\n\u4e00\u6b21bind<br \/>\n(1) db2 bind br8200.bnd<br \/>\n(2) \/btp\/bin\/bndall \/btp\/bnd<br \/>\n\/btp\/bin\/bndall \/btp\/tran\/bnd<br \/>\n\u5341\u4e8c\u3001\u67e5\u770b\u8cc7\u6599\u5eab\u53c3\u6578\uff1a<br \/>\ndb2 get dbm cfg<br \/>\ndb2 get db cfg for btpdbs<br \/>\n\u5341\u4e09\u3001\u4fee\u6539\u8cc7\u6599\u5eab\u53c3\u6578\uff1a<br \/>\ndb2 update db cfg for btpdbs using LOGBUFSZ 20<br \/>\ndb2 update db cfg for btpdbs using LOGFILSIZ 5120<br \/>\n\u6539\u5b8c\u5f8c\uff0c\u61c9\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f7f\u5176\u751f\u6548\uff1a<br \/>\ndb2 stop<br \/>\ndb2 start<\/p>\n<p>\u88dc\u5145\uff1a<br \/>\ndb2 set schema btp \u00a0 \u00a0\u4fee\u6539\u7576\u524d\u6a21\u5f0f\u70ba\u201dbtp\u201d<br \/>\ndb2 list tablespaces show detail \u00a0 \u00a0 \u67e5\u770b\u7576\u524d\u8cc7\u6599\u5eab\u8868\u7a7a\u9593\u5206\u914d\u72c0\u6cc1<br \/>\ndb2 list tablespace containers for 2 \u00a0show detail \u67e5\u770btablespace id=2\u4f7f<br \/>\n\u7528\u5bb9\u5668\u6240\u5728\u76ee\u9304<br \/>\ndb2 list application                \u5217\u51fa\u76ee\u524d\u9023\u7d50\u5230\u8cc7\u6599\u5eab\u7684\u6240\u6709\u61c9\u7528\u7a0b\u5f0f<br \/>\ndb2 list db directory \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u5217\u51fa\u6240\u6709\u8cc7\u6599\u5eab<br \/>\ndb2 list active databases \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u5217\u51fa\u6240\u6709\u6d3b\u52d5\u7684\u8cc7\u6599\u5eab<br \/>\ndb2 list tables for all \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u5217\u51fa\u7576\u524d\u8cc7\u6599\u5eab\u4e0b\u6240\u6709\u7684\u8868<br \/>\ndb2 list tables for schema btp \u00a0 \u00a0 \u00a0\u5217\u51fa\u7576\u524d\u8cc7\u6599\u5eab\u4e2dschema\u70babtp\u7684\u8868<br \/>\ndb2 list tablespaces show detail \u00a0 \u00a0\u986f\u793a\u8cc7\u6599\u5eab\u7a7a\u9593\u4f7f\u7528\u60c5\u6cc1<br \/>\ndb2 list packages for all<\/p>\n<p>db2 get authorizations \u7528\u4f86\u7372\u53d6\u7576\u524d\u7528\u6236\u7684\u8a31\u53ef\u6b0a<\/p>\n<p>db2 \u201cimport from tab76.ixf of ixf commitcount 5000 insert into achact\u201d<br \/>\ndb2 \u201ccreate table achact_t like achact\u201d<\/p>\n<p>db2 \u201crename table achact_t to achact\u201d<\/p>\n<p>db2 \u201cinsert into achact_t select * from achact where txndt&gt;=(select<br \/>\nlstpgdt from<br \/>\nacmact where actno=achact.actno)\u201d<\/p>\n<p>db2 get snapshot for dynaimic sql on jining<br \/>\n\u522a\u9664\u4e00\u500b\u5be6\u4f8b\uff1a<br \/>\n# cd \/usr\/lpp\/db2_07_01\/instance<br \/>\n# .\/db2idrop InstName<br \/>\n\u5217\u51fa\u6240\u6709DB2\u5be6\u4f8b\uff1a<br \/>\n# cd \/usr\/lpp\/db2_07_01\/bin<br \/>\n# .\/db2ilist<br \/>\n\u70ba\u8cc7\u6599\u5eab\u5efa\u7acb\u7de8\u76ee<br \/>\n$ db2 catalog db btpdbs on \/db2catalog<br \/>\n\u53d6\u6d88\u5df2\u7de8\u76ee\u7684\u8cc7\u6599\u5eabbtpdbs<br \/>\n$ db2 uncatalog db btpdbs<\/p>\n<p>\u67e5\u770b\u7248\u672c<br \/>\n# db2level<br \/>\n\u986f\u793a\u7576\u524d\u8cc7\u6599\u5eab\u7ba1\u7406\u5be6\u4f8b<br \/>\n$ db2 get instance<br \/>\n\u8a2d\u7f6e\u5be6\u4f8b\u7cfb\u7d71\u555f\u52d5\u6642\u662f\u5426\u81ea\u52d5\u555f\u52d5\u3002<br \/>\n$ db2iauto -on \u00a0 \u00a0 \u81ea\u52d5\u555f\u52d5<br \/>\n$ db2iauto -off \u00a0 \u00a0\u4e0d\u81ea\u52d5\u555f\u52d5<br \/>\n\u8cc7\u6599\u5eab\u512a\u5316\u547d\u4ee4\uff1a<br \/>\nreorg\u3001runstats<br \/>\n\u7576\u8cc7\u6599\u5eab\u7d93\u904e\u4e00\u6bb5\u6642\u9593\u4f7f\u7528\uff0c\u8cc7\u6599\u7a7a\u9593\u6703\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u9f90\u5927\u3002\u4e00\u4e9bdelete\u6389<br \/>\n\u7684\u8cc7\u6599\u4ecd\u5b58\u653e\u5728\u8cc7\u6599\u5eab\u4e2d\uff0c\u4f54\u7528\u8cc7\u6599\u7a7a\u9593\uff0c\u5f71\u97ff\u7cfb\u7d71\u6027\u80fd\u3002\u56e0\u6b64\u9700\u8981\u5b9a\u671f<br \/>\n\u904b\u884creorg\u3001runstats\u547d\u4ee4\uff0c\u6e05\u9664\u5df2delete\u7684\u8cc7\u6599\uff0c\u512a\u5316\u8cc7\u6599\u7d50\u69cb\u3002<br \/>\ndb2 reorg table \u8868\u540d<br \/>\ndb2 runstats on table \u8868\u540d with distribution and indexes all<br \/>\n\u56e0\u70ba\u8981\u512a\u5316\u7684\u8868\u6bd4\u8f03\u591a\uff0c\u6240\u4ee5\u5728\/btp\/bin\u76ee\u9304\u4e0b\u63d0\u4f9b\u4e86\u4e00\u500bsh\u7a0b\u5f0frunsall\uff0c<br \/>\n\u53ef\u5728\u7576\u5929\u696d\u52d9\u7d50\u675f\u5f8c\uff0c\u904b\u884crunsall\uff0c\u5c0d\u8cc7\u6599\u5eab\u9032\u884c\u512a\u5316<\/p>\n<p>*************************************************************************<\/p>\n<p>list node directory;<\/p>\n<p>list db directory;<\/p>\n<p>catalog tcpip node dbxx remote serverA server 3800;<br \/>\ncatalog database dbxx at node dbxx;<\/p>\n<p>***********************************************************<\/p>\n<p>Backup Command:<\/p>\n<p>db2 BACKUP DATABASE dbxxx TO \/dev\/null WITHOUT PROMPTING;<\/p>\n<p>************************************************************<\/p>\n<p>\u5e38\u7528SQL\u8a9e\u6cd5<\/p>\n<p>INSERT INTO table (store_name, Sales, Date) VALUES (&#8216;Los Angeles&#8217;, 900, &#8216;Jan-10-1999&#8217;)<\/p>\n<p>UPDATE table SET Sales = 500 WHERE Number = 6000 AND Date = &#8220;Jan-08-1999&#8221;<\/p>\n<p>Export SQL Schema(\u532f\u51fadb2 \u8cc7\u6599\u8868\u7d50\u69cb)<\/p>\n<p>db2look\u00a0\u00a0-d dbname -a -e -x -c -o\u00a0\u00a0filename.sql<\/p>\n<p>Import SQL Schema(\u532f\u5165db2\u8cc7\u6599\u8868\u7d50\u69cb)<\/p>\n<p>db2 -tvf filename.sql<\/p>\n<p>\u7576drop database dbName\u51fa\u73feSQL1035N  The database is currently in use.  SQLSTATE=57019<br \/>\n\u53ef\u5617\u8a66\u7528db2 connect reset\u6216deactivate database dbName<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7db2\u8def\u8f49\u8f09 *\u547d\u4ee4\u5217\u7a97\u53e3* #\u6253\u958b\u547d\u4ee4\u5217\u8996\u7a97 db2cmd #\u6253\u958b\u63a7\u5236\u4e2d\u5fc3 db2cmd db2cc #\u6253\u958b\u547d\u4ee4<span class=\"post-excerpt-end\">&hellip;<\/span><\/p>\n<p class=\"more-link\"><a href=\"https:\/\/learn-house.idv.tw\/?p=1148\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1148","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/1148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1148"}],"version-history":[{"count":0,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/1148\/revisions"}],"wp:attachment":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}