Quantcast
Channel: Build – db2commerce.com
Viewing all 43 articles
Browse latest View live

Db2 Basics: Levels of Configuration

$
0
0

There are a number of places where we can store and change configuration for a Db2 server. I wanted to walk through the main areas and a few details about them.

Db2 Registry

The Db2 registry actually has a number of levels within itself. It is accessed using the db2set command. This is not the Windows registry. By default a couple of parameters are set at the global level in the Db2 registry when an instance is created. If db2set is run as an instance owner without specifying the level at which a setting should apply, then it takes effect at the instance level. The levels of the Db2 registry are:

  • Operating system enviornment [e]
  • Node level registry [n]
  • Instance level registry [i]
  • Global level registry [g]

Most of the parameters in the DB2 registry require a db2stop/db2start to take effect, but some may be able to take effect dynamically. To check whether a parameter can take effect without a recycle, use the -info <variable> option on the db2set command, like this:

> db2set -info DB2COMM
   Immediate change supported : NO
   Immediate by default :       NO

Some Db2 registry parameters, like DB2_WORKLOAD, are aggregate parameters that include setting a number of other registry parameters. If any Db2 registry parameters are set by an aggregate parameter, they will have the name of that parameter in square brackets, like this:

[i] DB2_EVALUNCOMMITTED=YES [DB2_WORKLOAD]

Most registry variables are documented in the Db2 Knowledge Center, however IBM sometimes introduces new functionality with a hidden or undocumented registry variable. Unlike the other major configuration locations below, Db2 registry variables do not each have their own page in the Db2 Knowledge Center, and can be a bit frustrating to find at times.

Updating Values

The db2set command is used to update the values of Db2 registry parameters. The general syntax is:

db2set parameter=value

For example:

db2set DB2COMM=TCPIP

After changing a value, always verify that the change has taken effect.

Database Manager(DBM) Configuration

The database manager configuration consists of a large number of parameters that are set at the Db2 instance level.

Viewing Values

This configuration is often referred to as the “dbm cfg” because the shortest command for listing these variables and their values is:

db2 get dbm cfg

If you’re looking for just one parameter, it’s easiest to pipe the output to grep on Linux/UNIX or select-string at a PowerShell command line:

$ db2 get dbm cfg |grep INSTANCE_MEMORY
 Global instance memory (% or 4KB)     (INSTANCE_MEMORY) = AUTOMATIC(187170)
PS C:\Windows\system32> db2 get dbm cfg |select-string instance_memory

 Global instance memory (% or 4KB)     (INSTANCE_MEMORY) = AUTOMATIC(399591)

Some parameters, when changed, have the new value deferred until the next db2start. To see the deferred value, the show detail keywords are used on the get dbm cfg command. Using these keywords requires an instance attachment:

$ db2 attach to db2inst2

   Instance Attachment Information

 Instance server        = DB2/LINUXX8664 11.1.1.1
 Authorization ID       = DB2INST2
 Local instance alias   = DB2INST2

$ db2 get dbm cfg show detail |grep INSTANCE_MEMORY
 Global instance memory (% or 4KB)     (INSTANCE_MEMORY) = AUTOMATIC(187170)          AUTOMATIC(187170)

If the deferred value and the current value are the same, then no change will take place for the parameter on db2start.

In addition to using the get dbm cfg command, the values for the database manager configuration parameters can be queried using the SYSIBMADM.DBMCFG administrative view like this:

select substr(value,1,18) as value
    , value_flags
    , substr(deferred_value,1,18) as deferred_value
    , deferred_value_flags 
from SYSIBMADM.DBMCFG 
where name='instance_memory'

VALUE              VALUE_FLAGS DEFERRED_VALUE     DEFERRED_VALUE_FLAGS
------------------ ----------- ------------------ --------------------
187170             AUTOMATIC   187170             AUTOMATIC           

  1 record(s) selected.

Querying the administrative view requires a database connection, while the get dbm cfg command doesn’t even require the Db2 instance be started.

Researching Parameters and Propagation Boundaries

Many of the parameters in the database manager configuration require a db2stop/db2start to take effect. Each parameter has an inidividual page in the IBM Db2 Knowledge Center. A list of all the parameters links to each individual page. While the summary list includes whether each parameter can be changed online, the individual page for the parameter also contains this information. If the parameter can be changed online, then the “Parameter type” section will say “Configurable Online”, and the “Propagation Class” section will specify when the change will take place. This is an example:
Config_online_DBM

There is a wealth of other information on the parameter page for each parameter.

Updating Values

The db2 update dbm cfg command is used to update the values of dbm cfg parameters. The general syntax is:

db2 update dbm cfg using parameter value

For example:

db2 update dbm cfg using SYSMON_GROUP mon_grp

After changing a value, always verify that the change has taken effect using the show detail syntax detailed above. Sometimes if a parameter is deferred, you can attach to the instance and re-issue the update command to make the setting immediate. You may also want to use the immediate keyword:

db2 update dbm cfg using SYSMON_GROUP mon_grp immediate

Multiple changes can be done in a single command with syntax like this:

db2 update dbm cfg using parameter1 value1 parameter2 value2

For example:

db2 update dbm cfg using SYSMON_GROUP mon_grp mon_dft_buffpool ON

Database(DB) Configuration

There is a separate database configuration for each database, even if the databases are in the same instance. There are a lot of similarities between the db config and the dbm config. In fact, over the years, it seems like some things that used to be set at the database manager level seem to move to the database level. For example, the old snapshot monitors used the DFT_MON parameters in the dbm configuration. The newer mon_get* interfaces use the MON_* variables in the db configuration.

Viewing Values

The command for viewing the database configuration is similar to the one for the dbm cfg, though if there is no database connection, the database name must be specified:

db2 get db cfg for sample

Again, If you’re looking for just one parameter, it’s easiest to pipe the output to grep on Linux/UNIX or select-string at a PowerShell command line:

$ db2 get db cfg for sample |grep DATABASE_MEMORY
 Size of database shared memory (4KB)  (DATABASE_MEMORY) = AUTOMATIC(63936)
PS C:\Windows\system32> db2 get db cfg for sample |select-string database_memory

 Size of database shared memory (4KB)  (DATABASE_MEMORY) = AUTOMATIC(62336)

Some parameters, when changed, have the new value deferred until the next database deactivation and activation. To see the deferred value, the show detail keywords are used on the get db cfg command. Using these keywords requires an database connection:

$ db2 connect to sample

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.1.1.1
 SQL authorization ID   = DB2INST2
 Local database alias   = SAMPLE

$ db2 get db cfg for sample show detail |grep DATABASE_MEMORY
 Size of database shared memory (4KB)  (DATABASE_MEMORY) = AUTOMATIC(63936)           AUTOMATIC(63936) 

If the deferred value and the current value are the same, then no change will take place for the parameter on database deactivation/activation.

In addition to using the get db cfg command, the values for database configuration parameters can be queried using the SYSIBMADM.DBCFG administrative view like this:

select substr(value,1,18) as value
    , value_flags
    , substr(deferred_value,1,18) as deferred_value
    , deferred_value_flags 
from SYSIBMADM.DBCFG 
where name='database_memory'

VALUE              VALUE_FLAGS DEFERRED_VALUE     DEFERRED_VALUE_FLAGS
------------------ ----------- ------------------ --------------------
63936              AUTOMATIC   63936              AUTOMATIC           

  1 record(s) selected.

Querying the administrative view requires a database connection, while the get db cfg command doesn’t.

Researching Parameters and Propagation Boundaries

Some of the parameters in the database configuration require the database be deactivated and then activated (while there are no connections) to take effect. Each parameter has an individual page in the IBM Db2 Knowledge Center. A list of all the parameters links to each individual page. While the summary list includes whether each parameter can be changed online, the individual page for the parameter also contains this information. If the parameter can be changed online, then the “Parameter type” section will say “Configurable Online”, and the “Propagation Class” section will specify when the change will take place. This is an example:
Config_online_DBM

There is a wealth of other information on the parameter page for each parameter.

Updating Values

The db2 update db cfg command is used to update the values of db cfg parameters. The general syntax is:

db2 update db cfg for dbname using parameter value

For example:

db2 update db cfg for sample using LOCKTIMEOUT 90

After changing a value, always verify that the change has taken effect using the show detail syntax detailed above. Sometimes if a parameter is deferred, you can connect to the database and re-issue the update command to make the setting immediate. You may also want to use the immediate keyword:

db2 update db cfg for sample using LOCKTIMEOUT 90 immediate

Multiple changes can be done in a single command with syntax like this:

db2 update db cfg for dbname using parameter1 value1 parameter2 value2

For example:

db2 update db cfg using LOCKTIMEOUT 90 NEWLOGPATH /db2logs

Note that some parameters may put the database into a backup pending state, so be sure to research parameters before changing them.

Other Configurations

There are a wealth of other locations where things can be configured. Some parameters can be set in the userprofile (which is sourced by the db2profile). Others can be set in the CLI configuration file for certain kinds of applications. Some are set for the current session only, and the methodology for setting them depends heavily on the type of application being used. If the same parameter can be set in multiple places, the local or session values usually override the ones set at the server level. An example of this is LOCKTIMEOUT. There is always some value set for this at the database level in the db cfg. However, it can also be configured at the session/connection level using the SET CURRENT LOCK TIMEOUT command. It can also be set using an ODBC keyword. Things like binding packages can also have a profound impact on how a database behaves.


SQL1643C on Rollforward

$
0
0

I ran into this error message recently and thought I’d describe what the issue was.

The Scenario

I was building a new consolidated development database server for a client – moving away from 10 separate database servers to one (big) VM to run their development workloads. This was a Linux server, so I was setting INSTANCE_MEMORY to prevent any one instance from eating all the memory and to make it less likely that I would have a Db2 instance crash due to a Linux Out Of Memory condition killing the biggest memory consumer.

The Problem

I was restoring each database in using a redirected restore the place storage where I wanted it. The backups I was working from were all online backups. On the 8th database I restored, I got the following error on roll forward after the restore.

$ db2 "rollforward db SAMPLE to end of backup and stop overflow log path ('/db2/backups/SAMPLE')"
SQL1643C  The database manager failed to allocate shared memory because the
database manager instance memory limit has been reached.

It took me a while to track down where the issue was. I tried reducing the size of the largest bufferpool (though I didn’t think that would help, since DB2 would start up with the hidden buffer pools if my buffer pools were too large). It should have gone with the hidden buffer pools if any of the memory areas were over-sized. What I did was to set INSTANCE_MEMORY to AUTOMATIC for this one instance to get the roll forward to complete so I could look at the database memory that Db2 was allocating.

After I restarted the instance, I could get the roll forward to complete and then get details on what Db2 was allocating:

$ db2pd -dbptnmem
Database Member 0 -- Active -- Up 0 days 00:06:21 -- Date 2017-12-06-22.21.11.488636

Database Member Memory Controller Statistics

Controller Automatic: Y
Memory Limit:         59181724 KB
Current usage:        6302464 KB
HWM usage:            6302464 KB
Cached memory:        166848 KB

Individual Memory Consumers:

Name             Mem Used (KB) HWM Used (KB) Cached (KB)
========================================================
APPL-SAMPLE             160000        160000      160000
DBMS-b2cnadv1           113024        113024        6848
FMP_RESOURCES            22528         22528           0
PRIVATE                   6528          6528           0
DB-SAMPLE              6000000       6000000           0
LCL-p6116                  128           128           0
LCL-p5530                  128           128           0
LCL-p5582                  128           128           0

$ db2pd -d SAMPLE -mempools

Database Member 0 -- Database SAMPLE -- Active -- Up 0 days 00:05:42 -- Date 2017-12-06-22.21.26.384984

Memory Pools:
Address            MemSet   PoolName   Id    SecondId    Overhead   LogSz       LogHWM      PhySz       PhyHWM      CfgSize     Bnd BlkCnt CfgParm
0x00007F9828009578 SAMPLE   bph        16    2           0          180959744   180959744   181534720   181534720   181534720   No  3488   n/a
0x00007F98280037A8 SAMPLE   bph        16    1           0          3478197376  3478197376  3480485888  3480485888  3480485888  No  24894  n/a
0x00007F9827FFD9D8 SAMPLE   bph        16    4099        0          784768      784768      1835008     1835008     1835008     No  5      n/a
0x00007F9827FF7C08 SAMPLE   bph        16    4098        0          522624      522624      1572864     1572864     1572864     No  3      n/a
0x00007F9827FF1E38 SAMPLE   bph        16    4097        0          391552      391552      1441792     1441792     1441792     No  2      n/a
0x00007F9827FEC068 SAMPLE   bph        16    4096        0          326016      326016      1376256     1376256     1376256     No  2      n/a
0x00007F9827FE6298 SAMPLE   shsorth    18    0           0          0           0           0           0           66191360    No  0      SHEAPTHRES_SHR
0x00007F9827FE33B0 SAMPLE   lockh      4     0           0          56110208    56110208    56164352    56164352    56229888    No  1      LOCKLIST
0x00007F9827FE04C8 SAMPLE   dbh        2     0           167904     34377208    34377208    35454976    35454976    145096704   No  850    DBHEAP
0x00007F99963833B0 Appl     apph       1     8           0          0           0           0           0           1048576     No  0      APPLHEAPSZ
0x00007F99963804C8 Appl     appshrh    20    0           0          0           0           0           0           81920000    No  0      application shared

What immediately struck me in this output is that the database memory DB-SAMPLE is an awfully round number, and on careful analysis way higher than even the high water marks add up to.

When I checked the setting for DATABASE_MEMORY, I saw:

$ db2 get db cfg for SAMPLE |grep DATABASE_MEMORY
 Size of database shared memory (4KB)  (DATABASE_MEMORY) = 1500000

Indeed, someone had set DATABASE_MEMORY to a static value. I guess this was surprising to me because these databases had not had support from a DBA, and the first 8 similar databases did not have DATABASE_MEMORY set.

The Solution

The solution here was simple – I updated DATABASE_MEMORY to be automatic:

$ db2 update db cfg for WCBSTGQA using DATABASE_MEMORY AUTOMATIC
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.

I also changed INSTANCE_MEMORY back to my original limiting value.

Db2 Basics: Using FTPS to get a Fixpack Directly to a Db2 Server

$
0
0

This is the third time I have written this post. It keeps changing, so I keep sharing.

I work from home, so downloading software to my laptop and then uploading it to a server is not very efficient. Download speeds aren’t bad, but uploading can take 8 hours or more, depending on the client. This forces me, whenever possible, to move code directly to the server. The first time I wrote about this, it was little more than a wrapper around a tech note. The second time, I went into greater detail about a slightly different method. IBM has actually made it quite easy now.

You first have to know the Operating System and Fix Pack number you need. A full Db2 install is now possible from any fix pack code, so this goes for brand new installs, too. Though you will still have to get your license file from Passport Advantage, as the fix packs only come with a try-and-buy license. The easiest way to get to the code you need is by starting at the Fixes by Version page. This page presents a nice list of all available Db2 fix packs:
FixesByVersion

Once you’ve selected the fix pack number you want there, you’ll need to select the plus sign next to the operating system. Under the operating system, you have several options.
FixPackPage
If you don’t know what to pick, select “DB2 Universal Fix Pack”.

Once you have made that selection a separate tab or window will open up for the right fix pack in Fix Central. You will be required to log in with your IBM ID. If you don’t already have one, IBM IDs are free, and you don’t have to have any association whatsoever in order to download a fix pack for free.

The Fix Central screen should have only one package available. Check the box next to it, and click Continue at the bottom: FixCentral1

There is then a screen where you may have to wait for a bit:
FixCentral2

Once it is done loading, you have a screen that gives you the details of how to login via FTPS to get your fix pack:
FixCentral3
The three pieces of information you need there are in the red boxes. Once you have this, you just use those to get the fix pack from a UNIX/Linux command line:

$ ftp -s delivery04.dhe.ibm.com
Connected to server.boulder.ibm.com.
220 ProFTPD 1.3.5b Server (proftpd) []
234 AUTH TLS successful
TLS Auth Entered.
TLS handshake succeeded, though Server signed it's own cert!
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            30:ee:0e:4d:47:3f:76:4d:dc:bc:6a:07:4d:8e:a1:72
        Issuer: C=US, O=GeoTrust Inc., CN=GeoTrust SSL CA - G3
        Validity
            Not Before: Jan  5 00:00:00 2017 GMT
            Not After : Mar  6 23:59:59 2018 GMT
        Subject: C=US, ST=New York, L=Armonk, O=INTERNATIONAL BUSINESS MACHINES CORPORATION, CN=*.dhe.ibm.com
TLSv1/SSLv3 ( AES256-SHA ), 256 bits
Name (delivery04.dhe.ibm.com:vdba): asdfghkLer
331 Password required for asdfghkLer
Password:
230 User asdfghkLer logged in
200 PBSZ 0 successful
200 Protection set to Private
ftp> passive
Passive mode on.
ftp> binary
200 Type set to I
ftp> prompt
Interactive mode off.
ftp> mget *
TLSv1/SSLv3 ( AES256-SHA ), 256 bits
227 Entering Passive Mode (170,225,15,105,254,132).
150 Opening BINARY mode data connection for v10.5fp2_aix64_universal_fixpack.tar.gz (1913464208 bytes)
TLSv1/SSLv3 ( AES256-SHA ), 256 bits
226 Transfer complete
1913464208 bytes received in 869.7 seconds (2149 Kbytes/s)
local: v10.5fp2_aix64_universal_fixpack.tar.gz remote: v10.5fp2_aix64_universal_fixpack.tar.gz
ftp> bye
221 Goodbye.

Note that the above is slightly sanitized output from downloading a different fix pack than the one I showed in the screen shots from fix central. I did not share the real userid and pw from my code download, as that doesn’t seem quite right to me.

Viewing all 43 articles
Browse latest View live