{"id":455,"date":"2009-02-13T11:23:21","date_gmt":"2009-02-13T16:23:21","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=455"},"modified":"2012-10-11T07:34:20","modified_gmt":"2012-10-11T12:34:20","slug":"db2-getting-started","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=455","title":{"rendered":"Db2 Getting Started"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#DB2_Instance\">DB2 Instance<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Env_variables\">Env variables<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Update_Parameters\">Update Parameters<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#Database\">Database<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Connect\">Connect<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Databases\">Databases<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Tablespace\">Tablespace<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#Example\">Example<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#CLP\">CLP<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Help\">Help<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Scripting\">Scripting<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"DB2_Instance\"><h2>DB2 Instance<\/h2><\/span>\n<pre lang=\"bash\">\r\n# Create an instance:\r\ndb2icrt db2inst1\r\n\r\n# Drop an instance:\r\ndb2idrop db2inst1\r\n\r\n# List all instances:\r\ndb2ilist\r\n\r\n# Start an instance:\r\ndb2start\r\n\r\n# Stop an instance:\r\ndb2stop\r\n\r\n# Restart an instance\r\ndb2 force applications all\r\nsleep 10\r\ndb2 stop\r\nsleep 10\r\nps -ef|grep db2inst1\r\ndb2 start\r\n<\/pre>\n<span id=\"Env_variables\"><h2>Env variables<\/h2><\/span>\n<p>* Source env variables:<\/p>\n<pre lang=\"bash\">\r\n\/home\/db2inst1\/sqllib\/db2profile # source db2cshrc from c shell instead.\r\n<\/pre>\n<p>* DB2INSTANCE<\/p>\n<pre lang=\"bash\">\r\necho $DB2INSTANCE\r\ndb2inst1\r\n<\/pre>\n<p>* db2 profile registry<br \/>\n-global registry<br \/>\n-instance registry<\/p>\n<pre lang=\"bash\">\r\n# View all registry\r\ndb2set -lr\r\n\r\n# Set global env\r\ndb2set DB2INSTPROF=<val> -g\r\n\r\n# Set instance env\r\ndb2set DB2INSTPROF=<val> -i MyInst\r\n<\/pre>\n<p>* dbm cfg (database mgr cfg file)<\/p>\n<pre lang=\"bash\">\r\n# get dbm cfg\r\ndb2 get dbm cfg\r\ndb2 qet db cfg for <dbname>\r\n\r\n# update dbm cfg\r\ndb2 update dbm cfg using <parm> <val>\r\ndb2 update db cfg for <db> using <parm> <val>\r\n<\/pre>\n<span id=\"Update_Parameters\"><h3>Update Parameters<\/h3><\/span>\n<pre lang=\"bash\">\r\ndb2 update db cfg for itimdb using database_memory 40000\r\ndb2 alter bufferpool IBMDEFAULTBP size automatic\r\n\r\ndb2set DB2COMM\r\n<\/pre>\n<span id=\"Database\"><h2>Database<\/h2><\/span>\n<span id=\"Connect\"><h3>Connect<\/h3><\/span>\n<p>* System db directory<br \/>\nContains all dbs you can connect to from your db2 system. Stored at instance level.<\/p>\n<pre lang=\"bash\">\r\ndb2 list db directory\r\n<\/pre>\n<p>Local: indirect<br \/>\nRemote: remote<br \/>\n* Add db directory entry<\/p>\n<pre lang=\"bash\">\r\ndb2 catalog db <db_name> as <alias> at node <node_name>\r\n<\/pre>\n<p>* Local db directory<br \/>\nContains info about local dbs.<\/p>\n<pre lang=\"bash\">\r\ndb2 list db directory on <path>\r\n<\/pre>\n<p>* Node directory<br \/>\nContains all connectivity info for remote databases. Supports only tcpip in ver8.<\/p>\n<pre lang=\"bash\">\r\ndb2 list node directory\r\ndb2 catalog tcpip node mynode remote 9.26.138.35 server 60000\r\n<\/pre>\n<p>* DCS directory<br \/>\nContains connectivity info for host dbs on zSeries or iSeries machines.<\/p>\n<pre lang=\"bash\">\r\ndb2 list dcs directory\r\ndb2 catalog dcs db as db1g\r\n<\/pre>\n<span id=\"Databases\"><h3>Databases<\/h3><\/span>\n<p>* Create database<\/p>\n<pre lang=\"bash\">\r\ndb2 create database temporal\r\ndb2 connect to mydb2 user peenv7\r\ndb2 list tables\r\ndb2 list tablespaces\r\n<\/pre>\n<span id=\"Tablespace\"><h3>Tablespace<\/h3><\/span>\n<p>\u2022 Catalog (SYSCATSPACE)<br \/>\n\u2022 Temp (TEMPSPACE1)<br \/>\n\u2022 User space (USERSPACE1)<\/p>\n<span id=\"Example\"><h2>Example<\/h2><\/span>\n<pre lang=\"bash\">\r\ndb2ilist\r\ndb2 get instance\r\nset DB2INSTANCE=MyInstance\r\ndb2 list db directory\r\ndb2 create database temporal\r\ndb2 connect to mydb2 user peenv7\r\ndb2 list tables\r\ndb2 list tablespaces\r\n\/\/ backup instance\r\ndb2 qet dbm cfq > dbmcfq.bak\r\ndb2set -all > db2set.bak\r\ndb2 list db directory > systemdbdir.bak\r\ndb2 list node directory > nodedir.bak\r\ndb2 list dcs directory > dcs.bak\r\n\/\/end backup\r\ndb2 drop database temporal\r\n<\/pre>\n<span id=\"CLP\"><h3>CLP<\/h3><\/span>\n<p>* Verify installation<\/p>\n<pre lang=\"bash\">\r\nselect count(*) from syscat.tables\r\nselect count(*) from sysibm.tables\r\nselect count(*) from sysibm.sysdummy1\r\ndescribe table syscat.tables\r\n<\/pre>\n<span id=\"Help\"><h3>Help<\/h3><\/span>\n<p>db2 ? sql0100 | more<\/p>\n<span id=\"Scripting\"><h3>Scripting<\/h3><\/span>\n<pre lang=\"bash\">\r\nselect text from syscat.views\r\nselect text,tabname from syscat.checks\r\nselect text from syscat.procedures\r\nselect text from syscat.triggers\r\n<\/pre>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"http:\/\/users.sdsc.edu\/~jrowley\/db2\/howto.html\">DB2 HOW TOs<\/a><br \/>\n* <a href=\"http:\/\/dublintech.blogspot.com\/2011\/10\/db2-cheat-sheet.html\">DB2 cheat sheet<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DB2 Instance # Create an instance: db2icrt db2inst1 # Drop an instance: db2idrop db2inst1 # List all instances: db2ilist # Start an instance: db2start # Stop an instance: db2stop # Restart an instance db2 force applications all sleep 10 db2 &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=455\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[46],"tags":[],"class_list":["post-455","post","type-post","status-publish","format-standard","hentry","category-db2"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-7l","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=455"}],"version-history":[{"count":5,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":6236,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions\/6236"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}