{"id":394,"date":"2022-01-11T21:16:59","date_gmt":"2022-01-11T21:16:59","guid":{"rendered":"https:\/\/maboc.nl\/?p=394"},"modified":"2022-01-11T21:16:59","modified_gmt":"2022-01-11T21:16:59","slug":"db2-commands","status":"publish","type":"post","link":"https:\/\/maboc.nl\/?p=394","title":{"rendered":"DB2 commands"},"content":{"rendered":"<p><strong>Starting the database<\/strong><\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2start\r\n01\/11\/2022 14:57:48     0   0   SQL1063N  DB2START processing was successful.\r\nSQL1063N  DB2START processing was successful.\r\n[db2inst1@bloemkool ~]$<\/pre>\n<p><strong>Stopping the database<\/strong><\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2stop\r\n01\/11\/2022 14:58:43     0   0   SQL1064N  DB2STOP processing was successful.\r\nSQL1064N  DB2STOP processing was successful.\r\n[db2inst1@bloemkool ~]$<\/pre>\n<p><strong>Stopping the database when there are connections\/applications in the database.At first we do not succeed&#8230;ther are applications in the database.<\/strong><\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2stop\r\n01\/11\/2022 15:00:11     0   0   SQL1025N  The database manager was not stopped because databases are still active.\r\nSQL1025N  The database manager was not stopped because databases are still active.\r\n[db2inst1@bloemkool ~]$\r\n[db2inst1@bloemkool ~]$ db2stop force\r\n01\/11\/2022 15:00:17     0   0   SQL1064N  DB2STOP processing was successful.\r\nSQL1064N  DB2STOP processing was successful.\r\n[db2inst1@bloemkool ~]$ <\/pre>\n<p><strong>Connecting to the database<\/strong><\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2 connect to tinus user martijn using pwd\r\n\r\n   Database Connection Information\r\n\r\n Database server        = DB2\/LINUXX8664 11.5.6.0\r\n SQL authorization ID   = MARTIJN\r\n Local database alias   = TINUS\r\n\r\n[db2inst1@bloemkool ~]$ <\/pre>\n<p><strong>Disconnecting\/terminating the connection<\/strong><\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2 terminate\r\nDB20000I  The TERMINATE command completed successfully.\r\n[db2inst1@bloemkool ~]$<\/pre>\n<p><strong>List applications in the database<\/strong><\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2 list applications\r\n\r\nAuth Id  Application    Appl.      Application Id                        DB       # of\r\n         Name           Handle                                           Name     Agents\r\n-------- -------------- ---------- ------------------------------------- -------- -----\r\nMARTIJN  db2bp          65         *LOCAL.db2inst1.220111200924          TINUS    1    \r\nDB2INST1 db2bp          51         *LOCAL.db2inst1.220111200910          TINUS    1    \r\n\r\n[db2inst1@bloemkool ~]$<\/pre>\n<p>As you can see there are 2 connections in the database.<\/p>\n<p><strong>Forcing a connection of off the database<\/strong><\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2 \"force application (65)\"\r\nDB20000I  The FORCE APPLICATION command completed successfully.\r\nDB21024I  This command is asynchronous and may not be effective immediately.\r\n\r\n[db2inst1@bloemkool ~]$<\/pre>\n<p>The number 65 is the application-handle (see the former example (list applications))<\/p>\n<p>This will (ofcourse) result in errors on the application side of things:<\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2 \"select count(*) from t1\"\r\nSQL1224N  The database manager is not able to accept new requests, has \r\nterminated all requests in progress, or has terminated the specified request \r\nbecause of an error or a forced interrupt.  SQLSTATE=55032\r\n[db2inst1@bloemkool ~]$<\/pre>\n<p><strong>Getting configuration parameters<\/strong><\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2 get database configuration | grep -i logsecond\r\n Number of secondary log files               (LOGSECOND) = 100\r\n[db2inst1@bloemkool ~]$\r\n[db2inst1@bloemkool ~]$ db2 get db cfg | grep -i logsecond\r\n Number of secondary log files               (LOGSECOND) = 100\r\n[db2inst1@bloemkool ~]$<\/pre>\n<p>The command will get all database configuration parameters. So we need to grep the parameters we are interested.<br \/>\nIf you are lazy (as every good DBA should be) you can use the second form.<\/p>\n<p><strong>And setting a configuration parameter<\/strong><\/p>\n<pre style=\"font-size: 10px;\">[db2inst1@bloemkool ~]$ db2 update database configuration using logsecond  101\r\nDB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.\r\n[db2inst1@bloemkool ~]$<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Starting the database [db2inst1@bloemkool ~]$ db2start 01\/11\/2022 14:57:48 0 0 SQL1063N DB2START processing was successful. SQL1063N DB2START processing was successful. [db2inst1@bloemkool ~]$ Stopping the database [db2inst1@bloemkool ~]$ db2stop 01\/11\/2022 14:58:43 0 0 SQL1064N DB2STOP processing was successful. SQL1064N DB2STOP processing was successful. [db2inst1@bloemkool ~]$ Stopping the database when there are connections\/applications in the database.At first [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[77,65],"class_list":["post-394","post","type-post","status-publish","format-standard","hentry","category-db2","tag-administration","tag-db2"],"_links":{"self":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=394"}],"version-history":[{"count":18,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/394\/revisions"}],"predecessor-version":[{"id":412,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/394\/revisions\/412"}],"wp:attachment":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}