You are on page 1of 38
Understanding DB2 : Learning Edition Visually with Examples, Second by Raul F. Chong, IBM Xiaomei
Understanding DB2 : Learning Edition Visually with Examples, Second by Raul F. Chong, IBM Xiaomei

Understanding DB2 : Learning Edition Visually with Examples, Second

by Raul F. Chong, IBM Xiaomei Press. (c) Wang, 2008. Michael Copying Dang Prohibited. and Dwaine R. Snow

Reprinted for Apurba Thakur, IBM apurba.thakur@in.ibm.com Reprinted with permission http://www.books24x7.com/ as a subscription benefit of Books24x7,

All rights reserved. Reproduction other forms without and/or written distribution permission in whole is or prohibited. in part in electronic,paper or

other forms without and/or written distribution permission in whole is or prohibited. in part in electronic,paper

Understanding DB2 : Learning Visually with Examples, Second Edition

Chapter 2: DB2 at a Glance: The Big Picture

Overview

introduction This chapter to is DB2 like a core book concepts within a and book: components, It covers a vast but also range an of understanding topics that will of provide how these you components with not only work a good together DB2 revisit and where architecture and expand they fit that in what the will has DB2 help been scheme you discussed better of things. understand here. After the reading topics this discussed chapter you in the should next chapters. have a general Subsequent knowledge chapters of the will

In this chapter you will learn about the following:

n

SQL statements, XQuery statements, and DB2 commands

n

DB2 tools

n

The DB2 environment

n

Federation

n

The Database Partitioning Feature (DPF)

statements You by passing interact these and with commands DB2 statements by issuing from and an SQL commands application statements, to or the you XQuery DB2 can server use statements, DB2 for processing. tools. and The DB2 DB2 This commands. tools is shown interact You in Figure with can issue the 2.1. DB2 these environment

in Figure with can issue the 2.1 . DB2 these environment Figure 2.1: Overview of DB2

Figure 2.1: Overview of DB2 2.1 SQL Statements, XQuery Statements, and DB2 Commands

SQL several database Recent is the additions industry management standard leading to the language systems standard companies used (RDBMSs) include determines for retrieving XML follow extension the and these standard modifying functions. standards for data these These to in make SQL a relational are statements, it easier also refered database. for customers and to the as An SQL/XML different SQL to use council relational their extension formed databases. by functions. This section introduces the different categories of SQL statements and presents some examples.

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 2 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

The XML Query Language (XQuery) specification is a language used for querying XML documents. XQuery includes the a XML consortium Path Language formed (XPath), by several which industry is also leading used companies to query XML and documents. the academia. The The XQuery specification specification has is not managed been fully by W3C, Recommendationcompleted; will provide a however, few simple status, several XQuery bringing of the and the working XPath specification examples. drafts of as the a whole specification much closer have now to Final reached Recommendation. W3C Candidate In this section we

DB2 of DB2 commands commands: are directives specific to DB2 that allow you to perform tasks against a DB2 server. There are two types

n

System commands

n

Command Line Processor (CLP) commands

Note some explanation SQL statements of the of commands the and use DB2 of are uppercase commands case-sensitive. versus can be XQuery lowercase specified statements in in DB2. uppercase are case or lowercase. sensitive. However, See Appendix in Linux B for or a UNIX detailed

2.1.1 SQL Statements

against SQL SQL statements. statements the database allow you you are to work connected with the to, relational not against and the XML entire data DB2 stored environment. in your database. There are The three statements different are classes applied of

n

Data Definition Language (DDL) statements create, modify, or drop database objects. For example

ALTER DROP CREATE VIEW TABLE INDEX view1 t1 ix1 ADD ON hiredate t1 (salary) DATE

n

Data example Manipulation Language (DML) statements insert, update, delete, or retrieve data from the database objects. For

UPDATE INSERT DELETE t1 INTO FROM SET t1 t1 lastname VALUES (10,'Johnson','Peter') = 'Smith' WHERE firstname = 'Peter' SELECT * FROM t1 WHERE salary > 45000 SELECT FROM patients lastname WHERE passing xmlexists PATIENTS.INFO ($p/address[zipcode='12345'] as p) AND salary > 45000

n

Data the objects Control in your Language database. (DCL) For statements example grant or revoke privileges or authorities to perform database operations on

REVOKE GRANT update select ON ON employee employee FROM TO peter paul

Note SQL SQL statements statements, are see commonly the DB2 SQL referred Reference to simply manual. as statementsin most RDBMS books. For detailed syntax of

2.1.2 XQuery Statements

are XQuery connected statements to, not allow against you the to work entire with DB2 relational environment. and XML There data. are The two statements main ways are to work applied with against XML documents the database in DB2: you

n XPath is part of XQuery. Working with XPath is like working with the Change Directory (cd) command in Linux or MS- directory For DOS. example, Using tree. the Figure Similarly, cd operating 2.2 by shows using system an the XML slash command, document (/) in XPath, one in both can you go serialized can from navigate one format subdirectory a and tree, parsed which to another hierarchical represents subdirectory the format. XML in document. the

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 3 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

DB2 : Learning Visually with Examples, Second Edition Figure 2.2: An XML document in serialized and

Figure 2.2: An XML document in serialized and parsed hierarchical format Table as input. 2.1 shows some XPath expressions and the corresponding values obtained using the XML document in Figure 2.2

Table 2.1: Sample XPath Expressions

XPath expression Value to be returned /medInfo/patient/@type c1 p2 /medInfo/patient/bloodType
XPath expression Value to be returned /medInfo/patient/@type c1 p2 /medInfo/patient/bloodType

XPath expression

Value to be returned

/medInfo/patient/@type

c1

p2

/medInfo/patient/bloodType

/medInfo/patient/DNA/geneX

<bloodType>B</bloodType>

<bloodType>O</bloodType>

<geneX>555555</geneX>

<geneX>111111</geneX>

n XQuery FLWOR expression. FLWOR stands for:

FOR:

Iterates through an XML sequence, binds variables to items

LET:

Assigns an XML sequence to a variable

WHERE:

Eliminates items of the iteration; use for filtering

ORDER:

Reorders items of the iteration

RETURN:

Constructs query results; can return another XML document or even HTML

xquery

for let return $h $g := in $g/patient[@type="cl"]/DNA/geneX/text() db2-fn:xmlcolumn('GENOME.INFO')/medInfo <geneXList> {$h} </geneXList> which <geneXList> would return:

555555

</geneXList>

For discussed example, in more using detail the XML in Chapter document 10, as Mastering shown in the Figure DB2 2.2, pureXML an XQuery Support. expression could be XPath and XQuery will be

2.1.3 DB2 System Commands

You configuring started use (instances DB2 parameters. system are commands discussed Most DB2 later for system many in this commands purposes, chapter). including DB2 do not system require starting command the services instancethe names or processes, have DB2 the server following invoking engine utilities, format: processto and be

db2x

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 4 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

where x represents one or more characters. For example

db2start db2set

db2icrt

Note Many using the DB2 -h system option. commands For example, provide typing a quick db2set way -h to displays obtain syntax the syntax and help of the information db2set command, about the with command an by explanation of its optional parameters. 2.1.4 DB2 Command Line Processor (CLP) Commands

commands parameter DB2 Command configuration. typically Line require Processor For the example (CLP) instance commands to be started, are processed and they can by the be used CLP tool for database (introduced and in instance the next monitoring section). These and for

list applications catalog create database tcpip node

You invoke the Command Line Processor by entering db2 at an operating system prompt. If you enter db2 and press the On Enter example the key, other you hand, will be if you working dont with want the to CLP work in with interactive the CLP mode, in interactive and you mode, can enter precede the CLP each commands CLP command as shown with db2. above. For

db2 list applications db2 db2 catalog create database tcpip node

Tools, Many books, explains including the CLP this in greater one, display detail. CLP commands as db2 CLP_command for this reason. Chapter 4, Using the DB2 Note The On the DB2 Windows Command platform, Window db2 and must the be DB2 entered CLP are in a discussed DB2 Command in detail Window, in Chapter not at 4, the Using operating the DB2 system Tools. prompt. Note A followed quick way by the to obtain command. syntax For and example help information about a CLP command is to use the question mark (?) character

db2 or just ? catalog tcpip node db2 ? catalog

For detailed syntax of a command, see the DB2 Command Reference manual. 2.2 DB2 Tools Overview Figure 2.3 shows all the tools available from the IBM DB2 menu. The IBM DB2 menu on a Windows system can be graphical introduces typically displayed support the tools needs by presented choosing to be installed. in Start the IBM > Programs DB2s DB2 menu. graphical > IBM Chapter interface DB2. 4, On Using looks a Linux the the or DB2 same UNIX Tools, on system, all covers platforms. the these operating This tools section systems in more briefly detail, but for now simply familiarize yourself with them.

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 5 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

DB2 : Learning Visually with Examples, Second Edition Figure 2.3: The IBM DB2 menus 2.2.1 Command-Line

Figure 2.3: The IBM DB2 menus

2.2.1 Command-Line Tools

Window. from Command-line a command-line The Command tools, as interface. the Window name The is implies, available two text-based allow only you on interfaces to Windows, issue DB2 are while the commands, Command the CLP SQL is Line available statements, Processor on all and (CLP) other XQuery platforms. and the statements Command The also Command has the ability Editor to invoke is a graphical the Visual interface Explain tool tool, that which provides shows the the same access functionality plan for a as query. the text-based toolsand more. It

2.2.2 General Administration Tools

The from general a central administration location. tools allow database administrators (DBAs) to manage their database servers and databases

n

The Control Center is the most important of these tools. Not only does it support the administration of DB2 database configure Center, servers on database your the Linux, system objects UNIX, more can and quickly. be Windows created, altered, platforms, and but dropped. also on The the OS/390 tool also and comes z/OS with platforms. several From advisors the Control to help you

n

The been Journal executed. tool can help investigate problems in the system. It tracks error messages and scheduled tasks that have

n

The License Center summarizes the licenses installed in your DB2 system and allows you to manage them.

n

want The Replication to propagate Center data from lets one you location set up and to another. manage your replication environment. Use DB2 replication when you

n

The backup Task task Center to run allows at a time you when to schedule there is tasks minimal to be database performed activity. automatically. For example, you can arrange for a

2.2.3 Information Tools

method access The Information it to via search the menu Internet. the DB2 provides Use manuals. the easy Check You access can for to DB2 install the Updates DB2 the Information documentation. menu option Center The to locally obtain Information on the your most computer Center up-to-date provides or information intranet a fast server, and about easy or updates to the DB2 product.

2.2.4 Monitoring Tools

To detect maintain problems your proactively database system, before they DB2 cause provides performance several tools deterioration. that can help pinpoint the cause of a problem or even

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 6 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

n

n

n

n

n

SQL The Activity statement Monitor execution allows for a you database. to monitor You application can more performance easily diagnose and problems concurrency, with the resource reports consumption, this tool generates. and

need, For The example, Event a deadlock Analyzer when event two processes applications occurs. This the cannot information event can continue be collected captured their by processing by an an event event because monitor monitor, based the and other you on is the can holding occurrence use the resources Event of an Analyzer they event. captured transactions. to examine are the connections captured data to the related database, to the buffer deadlock pool and activity, help table resolve space the contention. activity, table Some activity, other SQL events statements, that can and be

The notifications Health Center to be sent. detects The DBA problems can then before choose they happen to execute by setting a recommended up thresholds, action which to relieve when the exceeded situation. cause alert

The been Indoubt committed Transaction or rolled back. Manager This is can only help applicable resolve issues to two-phase with transactions commit transactions. that have been prepared but have not

The memory Memory consumption. Visualizer tool lets you track the memory used by DB2. It plots a graph so you can easily monitor

2.2.5 Setup Tools

The development Setup tools tools. help you configure your system to connect to remote servers, provide tutorials, and install add-ins to

n

n

n

n

n

the The connection. Configuration Assistant allows you to easily configure your system to connect to remote databases and to test

Configure DB2 .NET Data Provider allows you to easily configure this provider for .NET applications.

you First to Steps create is a a sample good starting database point and for provides new DB2 tutorials users who that help wish you to become familiarize familiar yourself with with the product. DB2. This tool allows

The Register Visual Studio Add-Ins menu item lets you add a plug-in into Microsoft Visual Studio so that DB2 tools development provide can be invoked Microsoft tools, from Visual the Visual add-in Studio Basic, inserts programmers Visual the C++, DB2 with menu and a the rich entries .NET set into of development application the tools View, development environment. Tools, and tools In each Help to create of menus. these stored Microsoft These add-ins procedures and user-defined functions designed for DB2.

installation but Default one of DB2 them copy and should to Database use as be the chosen Client default. as Interface the Starting default Selection with copy. DB2 Multiple 9 Wizard(Windows multiple DB2 DB2 copy installations installation only) allows are is described you possible to choose on in the Chapter the same DB2 3, machine, Installing provider) DB2. copy. This tool will also help you choose the default IBM database client interface (ODBC/CLI driver and .NET

2.2.6 Other Tools

The following are other DB2 tools that are not invoked directly from the DB2 menus.

n

n

n

n

from Visual tables. Explain describes the access plan chosen by the DB2 optimizer, the brain of DB2, to access and retrieve data

SQL Assist aids new users who are not familiar with the SQL language to write SQL queries.

The server. Satellite Administration Center helps you set up and administer both satellites and the central satellite control

projects and database The XQuery IBM and Data applications statements queries Studio using throughout provides more Data easily. an Modeling the integrated You data can diagrams. management data also management use It comes it lifecycle. to develop with environment Data an and Integrated Studio debug which can stored Query be helps used procedures, Editor you for that develop design helps user-defined and and you prototype manage build SQL of

functions, downloadable and image Web services. based on IBM the Data Eclipse Studio Integrated supports Development most IBM Data Environment Servers including (IDE). It replaces Informix. the This Development is a separate,

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 7 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

Center used in previous DB2 versions.

n of DB2 The your Data for administrative Linux, Server UNIX Administration and tasks. Windows, It can be Console DB2 used for to z/OS (DSAC) manage and is IDS. hundreds a Web-based It is fast, of IBM simple tool data that but servers allows powerful, from you and to different perform task based. platforms about Web-based 80 such percent as tools such as the DSAC represent the new generation of tooling that will replace existing tools in the near future. 2.3 The DB2 Environment

database, a Several multipartition items and control in database Section the system behavior 2.6, Database (we of dont your Partitioning database want to overload system. Feature you We (DPF), with first we information describe expand the the at DB2 this material environment stage to in include the chapter). on concepts a single-partition relevant to

Figure 2.4 provides an overview of the DB2 environment. Consider the following when you review this figure:

n

n

n

n

n

The in detail figure in may the following look complex, sections. but dont be overwhelmed by first impressions! Each item in the figure will be discussed

Since figure is we available reference for Figure free in 2.4 color throughout as a GIF this file chapter, (Figure_2_4.gif), we strongly on the recommend books Web that site you bookmark page 43. This (www.ibmpressbooks.com/title/0131580183). Consider printing it.

prompt from The commands the on DB2 Linux graphical shown and UNIX. in tools. the Chapter figure can 4, Using be issued the DB2 from Tools, the Command describes Window equivalent on methods Windows to or perform the operating these system commands

color modify Each printer) arrow these points inquires contents, to a about set and of the the three third contents commands. command of a configuration (in The purple) first command illustrates file, the in second how each to set command use (in the blue command. (in if you black) printed indicates the figure the syntax using to a

The numbers in parentheses in Figure 2.4 match the superscripts in the headings in the following subsections.

superscripts in the headings in the following subsections. Figure 2.4: The DB2 environment 2.3.1 An Instance

Figure 2.4: The DB2 environment

2.3.1 An Instance (1) In DB2, an instance provides an independent environment where databases can be created and applications can be run

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 8 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

against them. Because of these independent environments, databases in separate instances can have the same name. production, MYDB2 For example, is associated test, in Figure and development to 2.4 instance the database myinst. purposes. called Instances MYDB2 allow is users associated to have to instance separate, DB2, independent and another environments database called for When environments, DB2 is installed if you choose on the to Windows create the platform, default an instance, instance it is named called DB2 db2inst1. is created by default. In the Linux and UNIX

To create an instance explicitly, use

db2icrt instance_name

To drop an instance, use

db2idrop instance_name

To start the current instance, use

db2start

To stop the current instance, use

db2stop

the When server an instance in Figure is 2.4 created was a on Linux Linux or and UNIX UNIX, server logical and links the instances to the DB2 DB2 executable and myinst code were are created, generated. both For of them example, would if UNIX the be linked sqllib installations directory. to the same as On we DB2 Windows, will code. see in A there Chapter logical is a link shared 3, works Installing install as an DB2, path, alias each and or pointer instance all instances to has another its access own program. local the same copy For libraries of non-root the DB2 and Linux code and under executables. 2.3.2 The Database Administration Server The graphical using Database a graphical administration Administration interface from from remote Server a remote (DAS) clients client, is using a daemon you the dont Control or need process Center. to start running If the you DAS. dont on the There need database to can administer only server be one that your DAS allows DB2 per server for server remote regardless data using server the DSAC, of you the are the number planning DAS of is instances not to administer required. or DB2 remotely, install copies not at the on DB2 the server. client. Note If you that choose the DAS to administer needs to your be running data servers at the

To start the DAS, use the following command:

db2admin start

To stop the DAS, use the following command:

db2admin stop

2.3.3 Configuration Files and the DB2 Profile Registries (2) Like These many include other RDBMSs, DB2 uses different mechanisms to influence the behavior of the database management system.

n

Environment variables

n

DB2 profile registry variables

n

Configuration parameters

2.3.3.1 Environment Variables

Environment variables are defined at the operating system level. On Windows you can create a new entry for a variable or Linux edit (provided the and value after UNIX of DB2 you an existing installation), can normally one by to add choosing the a instance line to Control execute owners Panel the .login script > System or db2profile .profile > initialization Advanced (Bourne files. Tab or Korn > Environment shell) or db2cshrc Variables. (C shell) On

The DB2INSTANCE environment variable allows you to specify the current active instance to which all commands apply. If

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 9 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

DB2INSTANCE instance DB2INSTANCE myinst. is variable If set you to wanted myinst, to DB2. to then create issuing this database the command in instance CREATE DB2, DATABASE you would mydb first will change create the a database value of the associated to Using the Control Panel (Windows) or the user profile (Linux or UNIX) to set the value of an environment variable guarantees temporarily on Linux or UNIX. while that value in The a given will command be window used the or next session, time you you can open use a window the operating or session. system If you set only command want to on change Windows, this or value export

set DB2INSTANCE=DB2 (on Windows)

or

export DB2INSTANCE=DB2 (on Linux and UNIX)

sets spaces the before value of and/or the DB2INSTANCE after the equal sign environment (=)no spaces variable should to DB2. be A entered. common mistake when using the command is to leave

To check the current setting of this variable, you can use any of these three commands:

echo set DB2INSTANCE %DB2INSTANCE% (Windows only) db2 get instance

For a list of all available instances in your system, issue the following command:

db2ilist

2.3.3.2 The DB2 Profile Registry

simply variables The word the provide registryDB2 registry a centralized always variables, causes location have confusion where no relation when some whatsoever working key variables with with DB2 influencing the on Windows Windows. DB2s Registry The behavior DB2 variables. profile reside. registry The DB2 variables, registry or

Note Some of the DB2 registry variables are platform-specific. The DB2 Profile Registry is divided into four categories:

n

The DB2 instance-level profile registry

n

The DB2 global-level profile registry

n

The DB2 instance node-level profile registry

n

The DB2 instance profile registry

registries, apply The first to all two as instances are you the can most on tell the from common server. their ones. names, As you The can is the main see scope difference from to Figure which between 2.4, the this variables the registry global-level apply. has been Global-level and drawn the instance-level outside profile registry of the profile two variables instance profile registry boxes. boxes Instance-level inside each profile of the registry two instances variables in apply the figure. to a specific instance. You can see separate instance-level

To view the current DB2 registry variables, issue the following command from the CLP:

db2set -all

You may get output like this:

[i]

[g]

DB2INSTPROF=C:\PROGRAM DB2SYSTEM=PRODSYS FILES\SQLLIB

As that you it has may been have defined already at guessed, the global [i] level. indicates the variable has been defined at the instance level, while [g] indicates

The following are a few other commands related to the DB2 Registry variables. To view all the registry variables that can be defined in DB2, use this command:

db2set -lr

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 10 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

To set the value of a specific variable (in this example, DB2INSTPROF) at the global level, use

db2set DB2INSTPROF="C:\PROGRAM FILES\SQLLIB" -g

To set a variable at the instance level for instance myinst, use

db2set DB2INSTPROF="C:\MY FILES\SQLLIB" -i myinst

When instance Note that a registry level. for the variable above commands, is defined at the different same variable levels, DB2 has been will always set at choose both levels: the value the global at the level lowest and level, the instance in this case level. the

For the db2set command, as with the set command discussed earlier, there are no spaces before or after the equal sign.

registry that Some have registry variables this requirement. variables do not require have this you requirement. to stop and Refer start the to the instance DB2 Administration (db2stop/db2start) Guide: for Performance the change for to a take list of effect. variables Other

2.3.3.3 Configuration Parameters

Configuration each level are parameters different (not are like defined DB2 registry at two different variables, levels: where the the instance same variables level and can the be database defined level. at different The variables levels). at

At variables the instance affect level, all databases variables associated are stored to in that the Database instance, which Manager is why Configuration Figure 2.4 file shows (dbm a Database cfg). Changes Manager to these Configuration file box defined per instance and outside the databases. To view the contents of the Database Manager Configuration file, issue the command:

db2 get dbm cfg

To update the value of a specific parameter, use

db2 update dbm cfg using parameter value

For example

db2 update dbm cfg using INTRA_PARALLEL YES

Many of the Database Manager Configuration parameters are now configurable online,meaning the changes are Tools, dynamicyou you can dont access need the to Database stop and Manager start the instance. (DBM) Configuration From the Control panel Center, (right click described on the desired in Chapter instance, 4, Using and the choose DB2 not. depending Configure In addition, Parameters), on your many system. of which these has parameters the column are Dynamicalso Automatic,that indicates meaning whether that DB2 the automatically parameter is calculates configurable the online best value or

parameters Database At the database Configuration only level, affect parameter the file specific box inside values database each are of stored the the Database databases in the Database Configuration defined. Configuration file applies file to. (db In cfg). Figure Changes 2.4 you to can these see there is a

To view the contents of the Database Configuration file, issue the command:

db2 get db cfg for dbname

For example

db2 get db cfg for mydb2

To update the value of a specific variable, use

db2 update db cfg for dbname using parameter value

For example

db2 update db cfg for mydb2 using MINCOMMIT 3

disconnect Using Many of the these DB2 all connections parameters Tools, you can are to the access configurable database the Database for online, the change meaning Configuration to that take the effect. panel change From (right is the click dynamic, Control on the and Center, desired you no described database, longer need in and Chapter to choose 4, Configure Parameters), which has the column Dynamicthat indicates whether the parameter is configurable online or

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 11 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

not. Many of these parameters are also Automatic,where DB2 configures the parameter for you.

2.3.4 Connectivity and DB2 Directories (3) In are DB2, four directories main directories, are used which to store are described connectivity in the information following about subsections. databases The and corresponding the servers commands on which they to set reside. up There database very convenient and server to set connectivity up database are and also server included; connectivity. however, many users find the Configuration Assistant graphical tool

Chapter in detail, 6, including Configuring the Configuration Client and Server Assistant. Connectivity, discusses all the commands and concepts described in this section

2.3.4.1 System Database Directory

The all the system databases database to which directory you can (or system connect db from directory) your DB2 is like server. the main As you table can of see contentsfrom Figure that 2.4, contains the system information db directory about is stored at the instance level. To list the contents of the system db directory, use the command:

db2 list db directory

Any is, a entry database from that the output resides of on this the command data server containing on which the you word are Indirect working. indicates The entry that also the points entry to is for the a local local database database, that directory indicated by the Database drive item (Windows) or Local database directory (Linux or UNIX). Any other Node entry than name containing the item. one on the which word you Remote are currently indicates working. that the The entry entry is for also a remote points to databasea the node directory database entry residing indicated on a by server the

To enter information into the system database directory, use the catalog command:

db2 catalog db dbname as alias at node nodename

For example

db2 catalog db mydb as yourdb at node mynode

The catalog catalog entry is commands automatically are normally created after used creating only when the adding database information with the CREATE for remote DATABASE databases. command. For local databases, a

2.3.4.2 Local Database Directory

The local database directory contains information about databases residing on the server where you are currently working. database Figure 2.4 directory shows the associated local database to all of directory the databases overlapping residing the in database the same box. location This means (the drive that on there Windows will be or one the local path on DB2 instance Linux Environment, or UNIX). level either; The it local will it is be in database easier a layer to between directory understand these does this two. not concept.) reside (After inside you read the Section database 2.3.10, itself, The but Internal it does not Implementation reside at the of the Note When also you from create Figure a database 2.4 that with there the is CREATE no specific DATABASE command command, used to enter an entry information is added into to this this directory. directory, only to retrieve it.

To list the contents of the local database directory, issue the command:

db2 list db directory on drive

where (Linux or drive UNIX) can in be the obtained corresponding from the entry item of Database the system drive db directory. (Windows) or path from the item Local database directory

2.3.4.3 Node Directory

protocol, want The node to connect this directory directory resides, stores shows and all connectivity the entries port such number information as the of the host associated for name remote or IP DB2 database address instance. servers. of the server For example, where the if database you use the to TCP/IP which you

/

path

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 12 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

To list the contents of the node directory, issue the command:

db2 list node directory

To enter information into the node directory, use

db2 catalog tcpip node node_name server remote service_name hostname or IP_address or port_number

For example

db2 remote catalog 192.168.1.100 tcpip node mynode server 60000

parameter the You port can number, obtain in the the Database you port need number to Manager look of for the Configuration the remote corresponding instance file of to entry that which instance. in you the TCP/IP want If this to services connect parameter by file looking contains mapping at a this the string SVCENAME string value to the rather port than number.

2.3.4.4 Database Connection Services Directory

The System Database z (z/OS Connection or OS/390) Services or System (DCS) i (OS/400) directory server. contains You connectivity need to have information DB2 Connect for host software databases installed. residing on

To list the contents of the DCS directory, issue the following command:

db2 list dcs directory

To enter information into the DCS directory, use

db2 catalog dcs db dbname as location_name

For example

db2 catalog dcs db mydb as db1g

2.3.5 Databases (4)

Databases A database are is a closed collection and of independent information units organized associated into interrelated to an instance. objects Because like table of this spaces, independence, tables, and objects indexes. in two or database database more databases MYDB2, MYDB1 can associated which have is the also to same instance associated name. DB2. For to instance example, Another DB2. table Figure space 2.4 shows with the a name table space MyTablespace1 called MyTablespace1 is also used inside inside the the Since For example, databases a query are closed involving units, Table1 you cannot in database perform MYDB1 queries and involving TableZ in tables database of two MYDB2 different is databases not readily in allowed. a direct For way. an SQL statement to work against tables of different databases, you need to use federation (see Section 2.4, Federation). You buffer create pool, a and database several with configuration the command files, CREATE which is DATABASE. why this command This command can take automatically a few seconds creates to complete. three table spaces, a

Note While CREATE DATABASE looks like an SQL statement, it is considered a DB2 CLP command.

2.3.6 Table Spaces (5)

the specific Table data spaces buffer is physically pool are logical (database stored objects in cache) files, used directories, and as to a layer specific or between raw containers. devices. logical When tables you and create physical a table containers. space, you Containers can associate are where it to a

USERSPACE1 Three table spacesSYSCATSPACE (the default user table space)are (holding the automatically Catalog tables), created TEMPSPACE1 when you create (system a temporary database. SYSCATSPACE space), and SYSCATSPACE times. and TEMPSPACE1 Some other contains RDBMSs can be the considered call catalog this structure tables system containing a structures, data dictionary.metadata as they are (data needed about for your the database normal operation objects) and of your must database. exist at all

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 13 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

Note relationship Do not confuse at all. the term catalogin this section with the catalog command mentioned earlier; they have no

A system temporary table space is the work area for the database manager to perform operations, such as joins and

overflowed sorts. There must be at least one system temporary table space in each database. The USERSPACE1 table space is created by default, but you can delete it. To create a table in a given table space, use the created the table CREATE in will the TABLE be USERSPACE1 created statement in the with table first the usercreated space. IN table_space_name table space. If you clause. have If not a table yet created space is a not table specified space, in the this table statement, will be

Figure figure if 2.4 you shows printed other the table softcopy spaces version). that were Chapter explicitly 8, The created DB2 Storage with the Model, CREATE discusses TABLESPACE table statement spaces in more (in brown detail. in the

2.3.7 Tables, Indexes, and Large Objects (6)

A table is an unordered set of data records consisting of columns and rows. An index is an ordered set of pointers

associated such as video, with audio, a table, and and scanned is used documents, for performance are stored purposes in tables and to as ensure large objects uniqueness. (LOBs). Non-traditional Tables and indexes relational reside data, in

table spaces. Chapter 8 describes these in more detail.

2.3.8 Logs (7)

Logs database are used to a consistent by DB2 to point. record See every Chapter operation 14, Developing against a database. Database In Backup case of and a failure, Recovery logs Solutions, are crucial for to more recover the

information about logs.

2.3.9 Buffer Pools (8)

A buffer pool is an area in memory where all index and data pages other than LOBs are processed. DB2 retrieves LOBs

directly DB2 Storage from disk. Model, Buffer discusses pools are buffer one pools of the in most more important detail. objects to tune for database performance. Chapter 8, The

2.3.10 The Internal Implementation of the DB2 Environment We have already discussed DB2 registry variables, configuration files, and instances. In this section we illustrate how

some of these concepts physically map to directories and files in the Windows environment. The structure is a bit different

internal in Linux implementation and UNIX environments, that corresponds but the main to Figure ideas 2.4. are the same. Figures 2.5, 2.6, and 2.7 illustrate the DB2 environment

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 14 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

DB2 : Learning Visually with Examples, Second Edition Figure 2.5: The internal implementation environment for DB2

Figure 2.5: The internal implementation environment for DB2 for Windows

The internal implementation environment for DB2 for Windows Figure 2.6: Expanding the DB2 instance directory Reprinted

Figure 2.6: Expanding the DB2 instance directory

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 15 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

DB2 : Learning Visually with Examples, Second Edition Figure 2.7: Expanding the directories containing the

Figure 2.7: Expanding the directories containing the database data

several that Figure is created 2.5 subdirectories shows for the each directory and instance files where that created belong DB2 on was to the DB2, installed: server. including For H:\Program example, the binary in Files\IBM\SQLLIB. Figure code that 2.5 makes the subdirectories The DB2 SQLLIB work, and DB2 directory a and subdirectory MYINST contains correspond to the instances DB2 and myinst respectively. The DB2DAS00 subdirectory corresponds to the DAS.

At for the instance top of myinst. the figure Similarly, there is the a directory H:\DB2 directory H:\MYINST. contains This directory all the databases contains created all the databases under the created H: drive under for instance the H: DB2. drive Figure about the 2.6 instance shows an DB2. expanded The db2systm view of the binary H:\Program file contains Files\IBM\SQLLIB\DB2 the database manager directory. configuration This directory (dbm cfg). contains The other information two files these highlighted files in the in figure the figure is sufficient. (db2nodes.cfg The figure and also db2diag.log) points out are the discussed directories later where in this the system book. For database, now, the Node, description and DCS of directories reside. Note that the Node and DCS directories dont exist if they dont have any entries. In under the Figure actual H:\DB2\NODE0000 2.7, database the H:\DB2 names, and correspond you H:\MYINST can review to the directories the two contents databases have of been the created local expanded. under database instance The directory subdirectories DB2. with To this map SQL00001 command: these directory and SQL00002 names to

list db directory on h:

Chapter directory 6, is Configuring stored in the Client subdirectory and Server SQLDBDIR. Connectivity, This shows subdirectory sample is output at the same of this level command. as each Note of the that database the local database subdirectories; subdirectories, one therefore, under when H:\DB2\NODE0000 a database is dropped, and another this one subdirectory under H:\MYINST\NODE0000. is not dropped. Figure 2.6 shows two SQLDBDIR

DB2? example, Knowing Would how looking this the mean back DB2 environment at that Figure databases 2.4 is (the internally MYDB1 one you and implemented should MYDB2 have are can printed!), also help dropped? you what understand would The happen answer the DB2 if is you no. concepts dropped Figure better. 2.5 the clearly instance For shows dropped. data that the resides directory (H:\DB2) where are the totally instance different. information When resides an instance (H:\Program is dropped, Files\IBM\SQLLIB\DB2) only the subdirectory and created the directory for that instance where the is Similarly, access the lets oldsay databases you uninstall created DB2 before at a given you time, uninstalled and later DB2 you the reinstall first time? it on The the answer same drive. is yes. After When reinstallation, you uninstalled can you DB2, removed, default you DB2 removed but instance; the databases the no SQLLIB other were instance directory, left untouched. is therefore created. When The the DB2 new you binary reinstall DB2 instance code, DB2, as a will well new have as SQLLIB the a new instance directory empty subdirectories, system is created database with were a new

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 16 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

directory put the information (db2systm). in the So even DB2 system though database the directories directory containing for DB2 the to database recognize data the existence were left intact, of these you databases. need to explicitly For example, entry to the if you system would database like to access directory: the MYDB1 database of the DB2 instance, you need to issue this command to add an

catalog db mydb1 on h:

If instance, the database switch you to the want instance, to access and is then MYDB2, issue which the catalog was in the command myinst instance, as shown you below. would first need to create this

set catalog db2icrt DB2INSTANCE=myinst db myinst mydb2 on h:

It is a good practice to back up the contents of all your configuration files as shown below.

db2 db2set db2 get get -all dbm db cfg > cfg db2set.bk for > dbmcfg.bk database_name > dbcfg.bk db2 db2 list list db node directory directory > systemdbdir.bk > nodedir.bk db2 list dcs directory > dcsdir.bk

Notice that all of these commands redirect the output to a text file with a .bk extension.

Caution section. implementation. The purpose You should of this We section only strongly modify is suggest to the help files you that using understand you do the not commands tamper the DB2 with described environment the files in and earlier by describing directories sections. its discussed internal in this 2.4 Federation Database The databases federated may support be local in or DB2 remote; allows they tables can also from belong multiple to databases different RDBMSs. to be presented While Chapter as local 1, tables Introduction to a DB2 to server. DB2, briefly introduced federated support, this section provides an overview of how federation is implemented. First set to of YES. all, make sure that your server allows federated support: The database manager parameter FEDERATED must be

DB2 example uses illustrated NICKNAME, in Figure SERVER, 2.8. WRAPPER, and USER MAPPING objects to implement federation. Lets consider the

objects to implement federation. Let ’ s consider the Figure 2.8: An overview of a federation

Figure 2.8: An overview of a federation environment

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 17 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

The DB2 user db2user connects to the database db2db. He then issues the following statement:

SELECT * FROM remote_sales

The possibly table in remote_sales, another server and however, from a is different not a local RDBMS. table but A nickname a nickname, is created which with is a pointer the CREATE to a table NICKNAME in another statement, database, and requires (csmmgr.sales). a SERVER object (aries in the example) and the schema and table name to be accessed at this server

connect RDBMSs, A SERVER to you a object given need is RDBMS. to associated obtain For the to IBM IBM a WRAPPER. databases Websphere like A Federation wrapper Informix, is these Server associated wrappers software. to a or library In libraries Figure that 2.8, are contains provided the wrapper all the with code called DB2. required informix For other to was created, and it is associated to the library db2informix.dll.

user This establish To access is informixuser achieved a the mapping Informix with are between the associated table CREATE csmmgr.sales, the with DB2 USER this user MAPPING statement. id however, and statement. an Informix you cannot Figure user use id 2.8 that the shows DB2 has the user how authority the id and DB2 password to user access db2user directly. the desired and You the table. need Informix to 2.5 Case Study: The DB2 Environment Note recommend to Several follow assumptions them, you some use a steps have test computer been may not made work system. in for this you. case If study you do and follow the some rest of or the all case of the studies steps in in the this case book, studies, so if you we try You running recently Windows attended Vista a and DB2 DB2 training Enterprise class and has would been installed. like to try You things open out the on Command your own laptop Window at the and office. take the Your following laptop is steps.

1. First, you want to know how many instances you have in your computer, so you enter

db2ilist

2. Then, to find out which of these instances is the current active one, you enter db2 get instance the With db2 the get db2ilist instance command, command, you found you learned out there that were the DB2 two instances instance is defined the current on this active computer, instance. DB2 and myinst. With

3. You first switch would to now this like instance to list the temporarily databases in in the the current myinst Command instance. Window: Since this one is not the current active instance, you

set DB2INSTANCE=myinst

4. db2start You again command. issue db2 get instance to check that myinst is now the current instance, and you start it using the

5. To list the databases defined on this instance you issue db2 list db directory This command shows that you only have one database (MYDB2) in this instance.

6. You want to try creating a new database called TEMPORAL, so you execute db2 create database temporal The Issuing creation another of the list database db directory takes some command time because now shows several two objects databases: are created MYDB2 by and default TEMPORAL. inside the database.

7. (db2 You connect list tables to the MYDB2 for all). database You also (db2 check connect how many to mydb2) table spaces and check are defined which tables (db2 you list have tablespaces). in this database

8. Next, you want to review the contents of the database configuration file (db cfg) for the MYDB2 database:

db2 get db cfg for mydb2

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 18 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

9.

To review the contents of the Database Manager Configuration file (dbm cfg) you issue db2 get dbm cfg

10.

parameter, At this point, which you want has a to value practice set changing to NO. You the change value of its a value dbm cfg to YES parameter, as follows: so you pick the INTRA_PARALLEL db2 update dbm cfg using INTRA_PARALLEL YES

11. You learned at the class that this parameter is not configurable online,so you know you have to stop and start the sequence database instance. Since earlier of commands: there from is your a connection current Command to a database Window), in the DB2 current will not instance allow you (remember to stop the you instance. connected Enter to the the MYDB2 following db2 terminate (terminates the connection) db2start db2stop And thats it! In this case study you have reviewed some basic instance commands like db2ilist and get instance. You instance, database have also review manager reviewed the configuration how contents to switch of the file to database parameter, another instance, configuration and stop create and file and start and connect an the instance. database to a database, manager list configuration the databases file, in update the a

2.6 Database Partitioning Feature

partition new In this servers section your and database we spread introduce across your you database multiple to the Database servers across them. or Partitioning within That a means large Feature SMP more (DPF) server. CPUs, available This more allows memory, on DB2 for scalability, and Enterprise. more since disks DPF you from lets can you each add of the additional servers for your database! DB2 online processing Enterprise analytical (OLTP) with processing workloads. DPF is ideal (OLAP), You to do manage also not known have large to as databases, install Decision any Support new whether code Systems you to enable are doing (DSS), this data feature, or working warehousing, but with you must online data purchase transaction mining, this feature without before the need enabling to know the that Database the database Partitioning is spread Feature. among Users several connect partitions. to the database and issue queries as usual

Up to this point, we have been discussing a single partition environment and its concepts, all of which apply to a multipartition concepts, multipartition including environment. environment database as well. partitions, We will partition now point groups, out some and the implementation coordinator partition, differences that and are introduce relevant only a few to new a 2.6.1 Database Partitions

A database partition is an independent part of a partitioned database with its own data, configuration files, indexes, and

transaction latter case, logs. the partitions You can are assign called multiple logical partitions partitions, across and several they can physical share the servers servers or to resources. a single physical server. In the

A single-partition database is a database with only one partition. We described the DB2 environment for this type of

database in Section 2.3, The DB2 Environment. A multipartition database (also referred to as a partitioned database)

is a database with two or more database partitions. Depending on your hardware environment, there are several

topologies per server. for The database illustration partitioning. at the top Figure of the figure 2.9 shows shows single an SMP partition server and with multipartition one partition configurations (single-partition with environment). one partition

This means the entire database resides on this one server.

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 19 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

DB2 : Learning Visually with Examples, Second Edition Figure 2.9: Database partition configurations with one

Figure 2.9: Database partition configurations with one partition per server The database illustration is split at between the bottom the shows two partitions. two SMP servers, one partition per server (multipartition environment). This means the

Note In Figure 2.9, the symmetric multiprocessor (SMP) systems could be replaced by uniprocessor systems. Figure one partition 2.10 shows per server, multipartition this figure configurations illustrates two with (or multiple more) partitions partitions per per server. server. Unlike Figure 2.9 where there was only

per server. server. Unlike Figure 2.9 where there was only Figure 2.10: Database partition configurations with

Figure 2.10: Database partition configurations with multiple partitions per server

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 20 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

and 2.4 To visualize to shows use the it how split Linux a into DB2 operating three environment physical system partitions, is instead split in of a one DPF the partition Windows system, per Figure operating server. 2.11 (We system.) illustrates have changed a partial the reproduction server in the of original Figure 2.4, Figure

reproduction server in the of original Figure 2.4 , Figure Figure 2.11: The DB2 environment on

Figure 2.11: The DB2 environment on DB2 Enterprise with DPF Note Because we reference Figure 2.11 throughout this section, we recommend that you bookmark page 61. www.ibmpressbooks.com/title/0131580183 Alternatively, since this figure is available in (Figure_2_11.gif), color on the books consider Web site, printing it. In Figure 2.11, the DB2 environment is splitso that it now resides on three servers running the same operating system system. Pack (Linux, levels in this are example). allowed. The This partitions figure shows are also where running files and the objects same DB2 would version, be located but it is on important a new installation to note that of a different multipartition Fix It is also important to note that all of the servers participating in a DPF environment have to be interconnected by a high- interpartitionas speed follows communication (assuming communication. you facility chose that For to supports create example, the the by db2inst1 TCP/IP default protocol. instance): after installation, TCP/IP ports the services are reserved file on on Linux each (/etc/services) server for this is updated

DB2_db2inst1_1 DB2_db2inst1 60000/tcp 60001/tcp DB2_db2inst1_END db2c_db2inst1 DB2_db2inst1_2 50000/tcp 60002/tcp 60003/tcp

interpartition partitions This will vary you communication. depending are configuring. on the You number can update of partitions the services on the file server. with the By default, correct number ports 60000 of entries through to support 60003 are the reserved number of for

When the partitions reside on the same server, communication between the partitions still requires this setup.

directories. the For host a DB2 name client In the can to example, be connect any of the to the a port DPF servers number system, participating to you use issue in these in catalog the commands DPF environment. commands is 50000 at The the to connect client server to used to populate the in db2inst1 the the catalog system instance, command and and node becomes the coordinator, unless the DBPARTITIONNUM option of the connect statement is used. The concept of

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 21 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

catalog coordinator command is described in detail. later in this section. Chapter 6, Configuring Client and Server Connectivity, discusses the Note those Each of files the that servers are applicable participating to DB2 in the interpartition DPF environment communication have their must own be separate the same. services file, but the entries in 2.6.2 The Node Configuration File they servers The node reside with configuration that two belong partitions to file an on (db2nodes.cfg) instance. each server. Figure contains 2.12 shows information an example about of the the database db2nodes.cfg partitions file and for a the cluster servers of four on which UNIX

file and for a the cluster servers of four on which UNIX Figure 2.12: An example

Figure 2.12: An example of the db2nodes.cfg file

database in In ascending Figure 2.12, partition order, the within partition can start DB2. number, from You any can the number, see first that column and there gaps in are the between eight db2nodes.cfg partitions the numbers file, in total. indicates are The allowed. numbering the number The numbering of that the identifies partitions used the must is be important as it will be taken into consideration in commands or SQL statements. The second column is the hostname or TCP/IP address of the server where the partition is created.

specifies the The mapping third the column, between logical the port logical the for db2nodes.cfg the port, partition is required entries within when the for server partitions you create and 2 must more and 3 be than for unique server one partition within myserverb a server. on the and same In the Figure physical server. 2.12, This server you column can see implementation. The logical ports must also be in the same order as in the db2nodes.cfg file. The interpartition fourth column communication in the db2nodes.cfg or if the resourcesetname file, the netname, column is required is used. if you are using a high-speed interconnect for

The the partition fifth column should in the be db2nodes.cfg started in. file, the resourcesetname, is optional. It specifies the operating system resource that

On Windows, the db2nodes.cfg file uses the computer name column instead of the resourcesetname column. The columns computer is name slightly column different: stores partition the computer number, name host-name, for the computer server on name, which logical a partition port, resides. netname, Also, and the resourcesetname. order of the The db2nodes.cfg file must be located

n Under the SQLLIB directory for the instance owner on Linux and UNIX

n Under the SQLLIB\instance_name directory on Windows In server Figure whose 2.11 disk(s) this file can would be be shared. on the Linux3 server, as this server is the Network File System (NFS) source server, the

On Linux and UNIX you can edit the db2nodes.cfg file with any ASCII editor or use DB2 commands to update the file. On

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 22 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

Windows, db2nodes.cfg you file can should only use not the be db2ncrt edited directly. and db2ndrop commands to create and drop database partitions; the

respectively. instance For any platform, and update you the can db2nodes.cfg also use the db2start file using the command add dbpartitionnum to add and or remove and the a drop database dbpartitionnum partition from the clauses DB2 2.6.3 An Instance in the DPF Environment Partitioning environment is an a concept instance that is created applies once to the on database, an NFS source not the server. instance; The you instance partition owners a database, home directory not an instance. is then exported In a DPF to owner, all servers password, where and DB2 shared is to be instance run. Each home partition directory. in the database has the same characteristics: the same instance

own On Linux home and directory. UNIX, an In most instance installations maps to /home/user_name an operating system is the user; home therefore, directory. when All an instances instance created is created, on each it will of have the its directory shared participating file of system. the servers corresponding Figure in a DPF 2.13 environment operating illustrates system an must example user use the to of be this. same the name same directory and password. for all In instances, addition, which you must must specify be created the home on a

which you must must specify be created the home on a Figure 2.13: An instance in

Figure 2.13: An instance in a partitioned environment In Figure 2.13, the instance myinst has been created on the shared file system, and myinst maps to an operating system each servers user of of the share the same participating directory name, /home/myinst, which servers, in the but figure they which must has resides a share home on the directory a instance shared of file home /home/ system directory. myinst. local to This As Linux3. shown user Since must in Figure be the created instance 2.13, all separately three owner Linux in directory is locally stored on the Linux3 server, this server is considered to be the DB2 instance-owning server. Figure in a DPF 2.13 environment. also shows There that the can Database only be one Administration DAS per physical Server server user db2as regardless is created of the locally number on of each partitions participating that server server contains. passwords The can DAS be used users to home create directory the DAS cannot on different be mounted servers. on a shared file system. Alternatively, different userids and

Note communicate. environment; Make sure the otherwise passwords the for partitioned the instances system are will the look same like on it each is hanging of the because participating the partitions servers in are a DPF not able to 2.6.4 Partitioning a Database When example, you if want the instance to partition owner a database home directory in a DPF is /home/myinst, environment, simply when you issue execute the CREATE this command: DATABASE command as usual. For

CREATE DATABASE mydb2

the structure created is as shown in Figure 2.14. Listing 2.14: A partitioned database in a single file system

/home

/myinst /NODE0000

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 23 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

/SQL00001

/NODE0001 /SQL00001

/NODE0002 /SQL00001

If you dont specify a path in your CREATE DATABASE command, by default the database is created in the directory directory. the specified other by servers This the partitioning database across a manager is network. not optimal configuration because parameter all of the database DFTDBPATH, data would which reside defaults in one to the file instance system that owners is shared home by

environment the We command recommend in Figure that you 2.13, create lets a assume directory the with directory the same /data name, has been locally created in each locally of the on participating each server. servers. When For you the execute

CREATE DATABASE mydb2 on /data

the following directory structure is automatically built for you:

/data/instance_name/NODExxxx/SQLyyyyy

The /data directory is specified in the CREATE DATABASE command, but the directory must exist before executing the are the command. database, working instance_name with, where where yyyyy xxxx is represents the represents name a of number. the the number instance; If you of for the have example, partition only one specified myinst. database NODExxxx in the on your db2nodes.cfg distinguishes system, then file. which yyyyy SQLyyyyy partition is equal identifies to you 00001; SQL00003. if you To have map three the database databases names on your to these system, directories, you will have you different can review directories the local as database follows: directory SQL00001, using SQL00002, the following command:

list db directory on /data

Inside assuming the all SQLyyyyy table spaces directories are defined are subdirectories as system-managed for table space spaces, (SMS). and within them, files containing database data

Figure 2.15 illustrates a partitioned database created in the /data directory.

a partitioned database created in the /data directory. Figure 2.15: A partitioned database across several file

Figure 2.15: A partitioned database across several file systems

Note Before path make created sure creating to locally include a database, with this the path be same in sure your name to CREATE change on each DATABASE the of value the participating of command. the dbm cfg servers Similarly, parameter, of to your create DFTDBPATH, DPF the system. SAMPLE Alternatively, to an database, existing specify this path in the command:

db2sampl path

Partitioning a database is described in more detail in Chapter 8, The DB2 Storage Model. 2.6.5 Configuration Files in a DPF Environment

and As shown DCS directory in Figure are 2.11, all the part Database of the instance-owning Manager Configuration server and file are (dbm not cfg), partitioned. system What database about directory, the other node configuration directory,

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 24 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

files?

n

n

n

n

variables. Environment variables: Each participating server in a partitioned environment can have different environment

Global-level the /var directory. profile There registry is a local variable: copy of This this is file stored on each in a server. file called default.env that is located in a subdirectory under

database. database. Database In configuration a partitioned database file: This is environment, stored in the a file separate SQLDBCON SQLDBCON that is file located is created in the for SQLyyyyy each partition directory in every for the

SQLDBDIR has The the local same database file name exists as directory: for the each system partition This database is in stored each directory, in database. the file which SQLDBDIR is located in the under corresponding the instance directory directory. for A the separate database. It Caution using We strongly the commands suggest you described do not in manually earlier sections. edit any of the DB2 configuration files. You should modify the files Note The directory values entries of the should global-level be the profile same registry for each variables, database database partition. configuration file parameters, and local database

2.6.6 Logs in a DPF Environment

files partition The logs (LOGPATH) includes on each a on database NODE000x each partition partition subdirectory. should should point be For kept to example, a in local a separate file the system, value place. of not this The a parameter shared database file in system. configuration the DPF The system default parameter shown log path Path in Figure in to each log 2.11 could be:

n

For Partition 0: /datalogs/db2inst1/NODE0000/SQL00001/SQLOGDIR/

n

For Partition 1: /datalogs/db2inst1/NODE0001/SQL00001/SQLOGDIR/

n For Partition 2: /datalogs/db2inst1/NODE0002/SQL00001/SQLOGDIR/ To change the path for the logs, update the database configuration parameter NEWLOGPATH.

2.6.7 The Catalog Partition

As table stated space previously, SYSCATSPACE, when you contains create a the database, DB2 system several catalogs. table spaces In a partitioned are created environment, by default. SYSCATSPACE One of them, the is catalog not

command catalog partitioned partition. is but issued resides Figure becomes on 2.11 one shows the partition catalog SYSCATSPACE known partition as the for catalog the residing new database. partition. on server The All Linux1, access partition so to the from system CREATE which tables DATABASE the must CREATE go command through DATABASE this was

issued from this server.

directory. indicates For an existing the The catalog database, output partition of you this number can command determine for has that which the database. field partition Catalog is the database catalog partition partition number by issuing for each the command of the entries, list which db

2.6.8 Partition Groups

A can partition belong to group more is than a logical one partition layer that group. provides When for a the database grouping is of created, one or DB2 more creates database three partitions. default partition A database groups, partition and

these partition groups cannot be dropped.

n

n

defined partition IBMDEFAULTGROUP: in group. the db2nodes.cfg This file. is the This default partition partition group group cannot for be any modified. table you Table create. space It contains USERSPACE1 all database is created partitions in this

IBMTEMPGROUP: defined in the db2nodes.cfg This partition file. Table group space is used TEMPSPACE1 by all system is temporary created in tables. this partition It contains group. all database partitions

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 25 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

n IBMCATGROUP: databases catalog This partition. partition This group partition contains group the cannot catalog be tables modified. (table space SYSCATSPACE). It only includes the

creates group, To create and the new records database database the partition partition partition group group groups, within definition use the the database, in CREATE the database assigns DATABASE system database PARTITION catalog partitions tables. GROUP that statement. you specified This to statement the partition

The following statement creates partition group pgrpall on all partitions specified in the db2nodes.cfg file:

CREATE DATABASE PARTITION GROUP pgrpall ON ALL DBPARTITIONNUMS

To create a database partition group pg23 consisting of partitions 2 and 3, issue this command:

CREATE DATABASE PARTITION GROUP pg23 ON DBPARTITIONNUMS (2,3)

Other relevant partition group statements/commands are:

n

ALTER DATABASE PARTITION GROUP (statement to add or drop a partition in the group)

n

DROP DATABASE PARTITION GROUP (statement to drop a partition group)

n listed) LIST DATABASE PARTITION GROUPS (command to list all your partition groups; note that IBMTEMPGROUP is never 2.6.9 Buffer Pools in a DPF Environment Each different Figure buffer 2.11 than shows pool for in the buffer a other DPF pools environment objects, defined because holds across the data all data of only the cached from database the in the database partitions. buffer pools partition Interpreting is not where partitioned this the figure buffer as for the pool buffer figure is located. pools implies. is You can create a buffer pool in a partition group using the CREATE BUFFERPOOL statement with the DATABASE PARTITION partition statement GROUP clause. group. will create This In addition, means buffer that the pool size you bpool_1 have of the the in buffer partition flexibility pool group on to each define pg234, partition the which buffer in consists the pool partition on of the partitions specific group can partitions 2, be 3, and different. 4. defined The in following the

CREATE SIZE BUFFERPOOL 10000 bpool_1 DATABASE PARTITION GROUP pg234 EXCEPT ON DBPARTITIONNUM (3 TO 4) SIZE 5000

Partition and 4 will 2 have in partition a buffer group pool pg234 of size will 5,000 have pages. a buffer pool bpool_1 defined with a size of 10,000 pages, and Partitions 3

As same an buffer analogy, pool think name of it for as each if you partition were issuing but with the different CREATE sizes. BUFFERPOOL That is: statement on each partition separately, with the

n

On partition 2: CREATE BUFFERPOOL bpool_1 SIZE 10000

n

On partition 3: CREATE BUFFERPOOL bpool_1 SIZE 5000

n

On partition 4: CREATE BUFFERPOOL bpool_1 SIZE 5000

commands Note that we as use shown these will statements attempt to only create to clarify the same the buffer analogy; pool they on will all partitions. not work as It is written. not equivalent Executing to each using of the these DATABASE

PARTITION GROUP clause of the CREATE BUFFERPOOL statement.

Buffer the partitions pools can in those also be partition associated groups. to several partition groups. This means that the buffer pool definition will be applied to

2.6.10 Table Spaces in a Partitioned Database Environment You can create a table space in specific partitions, associating it to a partition group, by using the CREATE TABLESPACE actually statement statement be with storing the their IN DATABASE tables. In a PARTITION partitioned GROUP database clause. environment This allows with users three to servers, have flexibility one partition as to per which server, partitions the will

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 26 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

CREATE MANAGED TABLESPACE BY mytbls SYSTEM IN USING DATABASE ('/data') PARTITION GROUP pg234 BUFFERPOOL bpool_1

creates the table space mytbls, which spans partitions 2, 3, and 4 (assuming pg234 is a partition group consisting of these space example, partitions). would if In bpool_1 fail addition, if you was provide the created table conflicting space for partitions is associated partition 5 and information 6, with and buffer table between pool space bpool_1 the mytbls table defined was space created earlier. and the for Note partitions associated that creating 2, buffer 3, and a pool. table 4, you For would get an error message when trying to create this table space. 2.6.11 The Coordinator Partition In simple terms, the coordinator partition is the partition where the application connects to. In be are and general, thought different sending of each types replies. as a database of process It agents. can connection either (Linux One satisfy or of them, UNIX) has the a the or request corresponding thread coordinator itself (Windows) or agent, DB2 delegate that agent communicates performs the handling work DB2 to the with multiple work application the on application, subagents behalf connection. of to receiving the work application. An on agent requests the There can request. The CLIENT a coordinator, coordinator CONNECT_NODE so partition in Figure command of 2.11 a given we to do application set not the label partition is any the particular partition that is to where partition be the the coordinator as coordinator the coordinator partition. agent node. exists. Any partition If you You would use can the potentially like SET to know be more about DB2 agents and the DB2 process model, refer to Chapter 15, The DB2 Process Model. 2.6.12 Issuing Commands and SQL Statements in a DPF Environment Imagine physical that server you or have partition twenty would physical be quite servers, a task. with Fortunately, two database DB2 partitions provides on a command each. Issuing that individual executes on commands all database to each partitions.

2.6.12.1 The db2_all command

Use example, the db2_all to change command the db cfg when parameter you want LOGFILSIZ to execute for a command the database or SQL sample statement in all partitions, against all you database would use partitions. For

db2_all ";db2 UPDATE DB CFG FOR sample USING LOGFILSIZ 500"

When the semicolon (;) character is placed before the command or statement, the request runs in parallel on all partitions. Note In simultaneously. The partitioned rah and db2_all environments, The rah commands command the operating use works the system per same server, characters. command while the rah For db2_all more performs information command commands about works on the all per servers rah database command, partition. refer to your operating system manuals. In statements. partitioned environments, pureXML support is not yet available; therefore, this section does not mention XQuery

2.6.12.2 Using Database Partition Expressions

found more In a partitioned than in the one db2nodes.cfg database database, partition database file. This resides is partition particularly on expressions the same useful physical when can be you server, used have to because a generate large number the values same of based device database on or the path partitions partition cannot and number be when specified partition expressions. for all partitions. The You following can manually example specify illustrates a unique the use container of database for each partition database expressions. partition or use database

The following are sample contents of a db2nodes.cfg file (in a Linux or UNIX environment):

0 1 myservera myservera

1 0

2 3 myserverb myserverb

1 0

This shows two servers with two database partitions each. The command

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 27 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

CREATE TABLESPACE ts2 (file MANAGED '/data/TS2/container BY DATABASE USING $N+100' 5000)

creates the following containers:

n

/data/TS2/container100 on database partition 0

n

/data/TS2/container101 on database partition 1

n

/data/TS2/container102 on database partition 2

n

/data/TS2/container103 on database partition 3

You specify a database partition expression with the argument $N (note that there must be a space before $N in the represents in command). Table 2.2 the Table shows modulus 2.2 the shows result (the remainder other of resolving arguments of the a division). database for creating Assuming partition containers. the expression. partition Operators number are evaluated to be evaluated from left is 3, to the right, value and column %

Table 2.2: Database Partition Expressions

Database Partition Expressions

Example

Value

[blank]$N

$N

3

[blank]$N+[number]

$N+500

503

[blank]$N%[number]

$N%2

1

[blank]$N+[number]%[number]

$N+15%13

5

[blank]$N%[number]+[number]

$N%2+20

21

2.6.13 The DB2NODE Environment Variable In Section 2.3, The DB2 Environment, we talked about the DB2INSTANCE environment variable used to switch between partitions the instances db2nodes.cfg on in your your database DPF file for system. a server. system. By To default, The switch DB2NODE the the active active environment partition partition, is the change variable one defined the is used value with in of a the the similar DB2NODE logical way, port but variable number to switch of using zero between the (0) SET in command connections on from Windows any partition and the to export your database command after on Linux changing or UNIX. this variable, Be sure or to issue the change a terminate will not take command effect. for all Using you log the on settings to server for myserverb, the db2nodes.cfg any commands file shown you in execute Table 2.3, will you affect have partition four servers, 2, which each is the with one two with logical logical partitions. port zero If on that server, and the default coordinator partition for that server. Table Information 2.3: Sample Partition

Partition Server Name Logical Port 0 Myservera 0 1 Myservera   1 2 Myserverb  
Partition Server Name Logical Port 0 Myservera 0 1 Myservera   1 2 Myserverb  

Partition

Server Name

Logical Port

0 Myservera

0

1 Myservera

 

1

2 Myserverb

 

0

3 Myserverb

 

1

4 Myserverc

 

0

5 Myserverc

 

1

6 Myserverd

 

0

7 Myserverd

 

1

If you would like to make partition 0 the active partition, make this change on a Linux or UNIX system:

export db2 DB2NODE=0 terminate DB2NODE

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 28 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

Note You must issue the terminate command, even if there arent any connections to any partitions. Note that partition 0 is on server myservera. Even if you are connected to myserverb, you can make a partition on

myservera the active one. To determine which is your active partition, you can issue this statement after connecting to a

database:

db2 "values (current dbpartitionnum)"

2.6.14 Distribution Maps and Distribution Keys By distributes now you data should across have the a good partitions. grasp Figure of how 2.16 to set shows up a an DPF example environment. of this distribution. It is now time to understand how DB2

of this distribution. It is now time to understand how DB2 Figure 2.16: Distributing data rows

Figure 2.16: Distributing data rows in a DPF environment

single distribution entry for map single-partition is an internally database generated partition array groups. containing The 4,096 partition entries numbers for multipartition of the database database partition partition group groups are or specified in a round-robin fashion in the array.

physically A distribution stored. key You is a define column a distribution (or group of key columns) explicitly that using determines the CREATE the partition TABLE statement on which a with particular the DISTRIBUTE row of data BY is

clause.

conjunction data. When you create with a or distribution modify a database key and a partition hashing group, algorithm a distribution determine map which is associated database partition with it. A will distribution store a given map row in of

For the example in Figure 2.16, lets assume partition group pg0123 has been defined on partitions 0, 1, 2, and 3. An

associated distribution map is automatically created. This map is an array with 4,096 entries containing the values 0, 1, 2,

3, 0, 1, 2, 3

entry numbers). Lets also assume table mytable has been created with a distribution key consisting of columns col1, col2, number number and col3. where from For 0 each the to 4,095. row row, is the This to be distribution number stored. corresponds In key Figure column 2.16, to values one if the of are hashing the passed entries algorithm to in the the hashing had array returned that algorithm, contains an output which the value value returns of of the 7, an the partition output row would have been stored in partition p3.

a

A

(note that this is shown in Figure 2.16 as p0, p1, p2, p3, p0, p1, p2, p3

to distinguish them from the array

p2, p3, p0, p1, p2, p3 to distinguish them from the array Note and Prior PARTITIONING

Note and Prior PARTITIONING to DB2 9 the DISTRIBUTION KEY respectively. MAP and DISTRIBUTION KEY terms were known as PARTITIONING MAP 2.7 Case Study: DB2 with DPF Environment Now that you are familiar with DPF, lets review some of the concepts discussed using a simple case study.

load, using approximately Your company or your if DB2 test threefold, with is servers: expanding, DPF two you will SMP be are and required. wondering it servers recently You running acquired if your are not Linux current two too with other familiar single-partition four firms. processors with Since DB2 DB2 with the each. database amount DPF, The so of previous you server data decide will will DBA, be be to increased able play who around to has handle left by with the the it

company, Figure 2.17. had installed DB2 Enterprise with DPF on these servers. Fortunately, he left a diagram with his design, shown in

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 29 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

DB2 : Learning Visually with Examples, Second Edition Figure 2.17: DB2 Enterprise with DPF design Figure

Figure 2.17: DB2 Enterprise with DPF design Figure you note 2.17 that is database a combined mydb1 physical has been and logical dropped, design. so you When decide you to validate rebuild the this correctness database as of practice. the diagram The with instance your system, db2inst1 is still there, as are other databases. These are the steps you follow.

1. Open by db2start, two telnet as sessions, shown in one Figure for 2.18. each server. From one of the sessions you issue the commands db2stop followed

Listing 2.18: Running the db2stop and db2start commands

[db2inst1@aries db2inst1]$ db2stop 0 0 SQL1064N 10-18-2007 10-18-2007 DB2STOP 23:44:44 23:44:44 processing 0 2 0 0 was SQL1064N SQL1064N successful. DB2STOP DB2STOP processing processing was was successful. successful. [db2inst1@aries db2inst1]$ db2start 0 0 SQL1063N 10-18-2007 10-18-2007 DB2START 23:44:52 23:44:53 processing 3 2 0 0 was SQL1063N SQL1063N SQL1063N SQL1063N successful. DB2START DB2START DB2START DB2START processing processing processing processing was was was was successful. successful. successful. successful.

10-18-2007 23:44:43

10-18-2007 23:44:42

1 3

SQL1064N DB2STOP processing was successful.

SQL1064N DB2STOP processing was successful.

10-18-2007 23:44:51

10-18-2007 23:44:51

0 1

[db2inst1@aries db2inst1]$

23:44:51 10-18-2007 23:44:51 0 1 [db2inst1@aries db2inst1]$ partition from The first each once thing of them.

partition from The first each once thing of them. will you affect note is all that partitions. there is You no need also can to issue tell that these there two are commands four partitions, on each since partition; you received issuing a them message on any

2. Review the db2nodes.cfg file to understand the configuration of your partitions (see Figure 2.19). Listing 2.19: A sample db2nodes.cfg file

[db2inst1@aries sqllib]$ pwd

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 30 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

/home/db2inst1/sqllib

[db2inst1@aries sqllib]$ more db2nodes.cfg

0 1 aries.myacme.com aries.myacme.com 1 0

2 3 saturn.myacme.com saturn.myacme.com 0 1

[db2inst1@aries sqllib]$

The Using db2nodes.cfg operating system file is commands, stored in the you directory determine /home/db2inst1/sqllib. that the home directory for instance db2inst1 is /home/db2inst1. Figure 2.19 shows there are four partitions, two per server. The server host names are aries and saturn.

3. Create the database mydb1. Since you want partition 0 to be your catalog partition, you must issue the CREATE determine DATABASE which command partition from is partition currently 0. active You issue and the find statement out that partition db2 "values 3 is the (current active partition dbpartitionnum)" (see Figure 2.20). to Listing 2.20: Determining the active partition

[db2inst1@saturn db2inst1]$ db2 "values (current dbpartitionnum)"

1

-----------

3

1 record(s) selected.

dbpartitionnum)" 1 ----------- 3 1 record(s) selected. 4. Next, you change the DB2NODE environment variable to

4. Next, you change the DB2NODE environment variable to zero (0) as follows (see Figure 2.21):

DB2NODE=0 export db2 terminate DB2NODE

Listing 2.21: Switching the active partition, and then creating a database

[db2inst1@saturn [db2inst1@saturn db2inst1]$ db2inst1]$ export DB2NODE=0 DB2NODE DB20000I [db2inst1@saturn The TERMINATE db2inst1]$ command db2 completed terminate successfully.

SQL1611W [db2inst1@saturn No data was db2inst1]$ returned db2 by list Database applications System Monitor. SQLSTATE=00000 [db2inst1@saturn DB20000I The CREATE db2inst1]$ DATABASE db2 command create completed db mydb1 successfully. on /db2database

[db2inst1@saturn db2inst1]$ db2 connect to mydb1 Database Database server Connection Information = DB2/LINUX 9.1 = = DB2INST1 MYDB1

[db2inst1@saturn db2inst1]$ db2 "values (current dbpartitionnum)"

SQL authorization ID

Local database alias

1

-----------

0

1 record(s) selected.

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 31 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

[db2inst1@saturn db2inst1]$

In has the been CREATE created DATABASE locally on command all servers you so specify that the the data path, is /db2database spread across in them. this example, which is an existing path that

5. To the tablespaces confirm Catalog that database command partition partition 0 from is indeed each number partition. the field catalog under The partition, SYSCATSPACE the entry simply for the issue table mydb1 a list space database. db will directory be Alternatively, listed only command on issue the catalog and a list look for partition.

6. Create partition partition groups. group Remember pg23 on that partitions this does 2 not and list 3. IBMTEMPGROUP. Figure 2.22 shows how to accomplish this and how to list your

Listing 2.22: Creating partition group pg23

[db2inst1@saturn dbpartitionnum (2 db2inst1]$ to 3)" db2 "create database partition group pg23 on DB20000I The SQL command completed successfully. [db2inst1@saturn db2inst1]$ db2 "list database partition groups" DATABASE PARTITION GROUP

----------------------------

IBMDEFAULTGROUP PG23 IBMCATGROUP

3 record(s) selected.

[db2inst1@saturn db2inst1]$

3 record(s) selected. [db2inst1@saturn db2inst1]$ 7. Create and manage your buffer pools. Issue this statement

7. Create and manage your buffer pools. Issue this statement to create buffer pool BP23 on partition group pg23:

db2 "create bufferpool BP23 database partition group pg23 size 500" Figure 2.23 shows this statement. It also shows you how to associate this buffer pool to another partition group using

the ALTER BUFFERPOOL statement.

Listing 2.23: Managing buffer pools

[db2inst1@saturn size 500" db2inst1]$ db2 "create bufferpool BP23 database partition group pg23 DB20000I The SQL command completed successfully. [db2inst1@saturn IBMCATGROUP" db2inst1]$ db2 "alter bufferpool BP23 add database partition group DB20000I The SQL command completed successfully. [db2inst1@saturn db2inst1]$ db2 "select bpname, ngname from syscat.bufferpools" NGNAME

BPNAME

--------------------------------------------------------------------------------

IBMDEFAULTBP

-

BP23

PG23

BP23

IBMCATGROUP

3 record(s) selected.

[db2inst1@saturn db2inst1]$

3 record(s) selected. [db2inst1@saturn db2inst1]$ Reprinted for ibm\apurba.thakur@in.ibm.com, IBM Page 32 / 38

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 32 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

also To list shown your buffer in Figure pools 2.23. and associated partition groups, you can query the SYSCAT.BUFFERPOOLS catalog view, Note partition that group, a buffer and pool you can can be specify associated different with sizes any partition on the partitions group. Its if required. definition will be applied to all the partitions in the

8.

Create the table space mytbls1:

db2 "create managed tablespace by system mytbls1 using in ('/data') database partition bufferpool group bp23" pg23

9.

Create table table1 in table space mytbls1 with a distribution key of col1 and col2:

db2 "create table table1 (col1 int, col2 int, col3 char(10)) distribute in mytbls1 by (col1, col2)"

10.

Create the index index1. Note that this doesnt have any syntax specific to a DPF environment:

db2 "create index index1 on table1 (col1, col2)" The index will be constructed on each partition for its subset of rows.

11.

Test shows the an db2_all example command of this. to update the database configuration file for all partitions with one command. Figure 2.24

Listing 2.24: Using db2_all to update the db cfg file

[db2inst1@aries sqllib]$ db2 get db cfg for mydb1 | grep LOGFILSIZ [db2inst1@aries Log file size (4KB) sqllib]$ db2_all "db2 update db (LOGFILSIZ) cfg for mydb1 = 1000 using LOGFILSIZ 500" DB20000I aries.myacme.com: The UPDATE db2 DATABASE update db CONFIGURATION cfg for mydb1 command using LOGFILSIZ completed 500 successfully. completed ok DB20000I aries.myacme.com: The UPDATE db2 DATABASE update db CONFIGURATION cfg for mydb1 command using completed LOGFILSIZ successfully. 500 completed ok DB20000I saturn.myacme.com: The UPDATE db2 DATABASE update CONFIGURATION db cfg for mydb1 command using completed LOGFILSIZ successfully. 500 completed ok DB20000I saturn.myacme.com: [db2inst1@aries The UPDATE sqllib]$ db2 DATABASE update db2 CONFIGURATION get db cfg db cfg for for mydb1 command mydb1 using | completed grep LOGFILSIZ LOGFILSIZ successfully. 500 completed ok (LOGFILSIZ) = 500

[db2inst1@aries Log file size (4KB) sqllib]$

= 500 [db2inst1@aries Log file size (4KB) sqllib]$ And that ’ s it! In this case

And thats it! In this case study you have reviewed some basic statements and commands applicable to the DPF created also environment. used a database, the You db2_all reviewed a partition command the group, db2stop to update a buffer and a db2start database pool, a table configuration commands, space, a determined table file parameter. with a and distribution switched key, the and active an partition, index. You and

2.8 IBM Balanced Warehouse A performance. data warehouse Unbalanced, system is ill-planned composed configurations of CPUs (or processors), will waste a lot memory, of money and if disk. the system A balanced has mix is the key to optimal

n

Too many or too few servers

n

Too much or too little storage

n

Too much or too little I/O capacity and bandwidth

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 33 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

n Too much or too little memory To on a help prescriptive alleviate these and quality issues, approach and ensure through that the DB2 use customers of a proven build balanced highly performing methodology data for warehouses, data warehousing. IBM has This focused is called Figure the 2.25. IBM Balanced Warehouse (BW) (formerly known as Balanced Configuration Unit or BCU), and is depicted in

as Balanced Configuration Unit or BCU), and is depicted in Figure 2.25: IBM Balanced Warehouse These

Figure 2.25: IBM Balanced Warehouse

These software, The BW components applies in addition specifically are to the integrated IBM to DB2 hardware and data tested warehouses. and as other a preconfigured software It is composed components building of a block methodology that are for required data for warehousing deployment to build a data systems. of the warehouse. database The making manageability prescriptive use of approach of standardized, the data used warehouse. by end-to-end the BW eliminates stack tested the designs, complexity and of best database practices warehouse that increase design the and overall implementation quality and by

optimize database, This modular the you cost-effectiveness approach might also ensures start off and that with throughput there several is a of balanced of these the database. BW amount building While of disks, blocks you I/O might in a bandwidth, single start system off processing with image. one BW, power As if the you and database have memory a large to grows, you can simply add additional building blocks (BWs) to handle the increased data or users as shown in Figure 2.26.

the increased data or users as shown in Figure 2.26 . Figure 2.26: BW as building

Figure 2.26: BW as building blocks The main advantages of the BW are

n

best-of-breed IBM components selected for optimum price/performance

n

repeatable, scalable, consistent performance that can grow as business needs grow

n

a building prescriptive, a business fully validated intelligence and solution tested, successful best practices design that reduces the time and removes the risk of

2.9 Summary This and their chapter classification provided an as overview Data Definition of the Language DB2 core concepts (DDL), Data using Manipulation a big pictureLanguage approach. (DML), It introduced and Data SQL Control statements Language (DCL) statements. XQuery with XPath and the FLWOR expression were also introduced.

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 34 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

DB2 provided, commands such as were the command classified into to start two an groupssystem instance, db2start. commands and CLP commandsand several examples were

provided An interface by using is needed the DB2 to issue tools SQL available statements, with the XQuery product. statements, Two text-based and commands interfaces to were the mentioned, DB2 engine. the This Command interface Line is administration administration Processor (CLP) tooling. tools, and while the Command the Data Server Window. Administration The Control Control Center was was noted presented as being as the one next of the generation most important of graphical graphical This chapter also introduced the concepts of instances, databases, table spaces, buffer pools, logs, tables, indexes, and presented, and other database database including (db objects cfg) environment levels. in a single DB2 variables, partition has federation system. DB2 registry support The different variables, for queries levels and referencing of configuration configuration tables parameters for residing the DB2 in at other environment the instance databases were (dbm in the cfg) DB2 catalog was also family. partition, introduced. The chapter coordinator also node, covered and the distribution Database map Partitioning on a multipartition Feature (DPF) system. and The the IBM concepts Balanced of database Warehouse partition, (BW)

Two understand case studies the topics reviewed discussed the single-partition in the chapter. and multipartition environments respectively, which should help you

2.10 Review Questions

1. How are DB2 commands classified?

?

2. What is a quick way to obtain help information for a command?

?

3. What is the difference between the Information Center tool and simply reviewing the DB2 manuals?

?

4. What command is used to create a DB2 instance?

?

5. How many table spaces are automatically created by the CREATE DATABASE command?

?

6. What command can be used to get a list of all instances on your server?

?

7. What is the default instance that is created on Windows?

?

8. Is the DAS required to be running to set up a remote connection between a DB2 client and a DB2 server?

?

9. How can the DB2 environment be configured?

?

10. How is the local database directory populated?

?

11. Which of the following commands will start your DB2 instance?

?

A. startdb

B. db2 start

C. db2start

D. start db2

12. Which of the following commands will list all of the registry variables that are set on your server?

?

A. db2set -a

B. db2set -all

C. db2set -lr

D. db2set -ltr

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 35 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

13. Say using the databases you the are db2idrop running you had command, DB2 prior on to a Windows dropping after recreating the server instance? the with DB2 only instance, one hard which drive (C:). of the If following the DB2 commands instance is dropped will list

A. list databases

B. list db directory

C. list db directory all

D. list db directory on C:

14. If the list db directory on C: command returns the following:

Database Database name alias Comment Database Database directory release level Catalog Database Directory database partition entry type partition number number

= SAMPLE = = = SQL00001 SAMPLE a.00 = = = Home 0 = 0

?

?

which of the following commands must be run before you can access tables in the database?

A. catalog db sample

B. catalog db sample on local

C. catalog db sample on SQL00001

D. catalog db sample on C:

15. If inst1, there which are two of the DB2 following instances commands on your Linux allows server, you to inst1 connect and to inst2, databases and if your in the default inst2 DB2 instance? instance is

A. export inst2

B. export instance=inst2

C. export db2instance=inst2

D. connect to inst2

?

16. Which partitions of the on a following single server? DB2 registry variables optimizes interpartition communication if you have multiple

A. DB2_OPTIMIZE_COMM

B. DB2_FORCE_COMM

C. DB2_USE_FCM_BP

D. DB2_FORCE_FCM_BP

?

17. Which of the following tools is used to run commands on all partitions in a multipartition DB2 database?

A. db2_part

B. db2_all

C. db2_allpart

?

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 36 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

D. db2

18. Which of the following allows federated support in your server?

?

A. db2 update db cfg for federation using FEDERATED ON

B. db2 update dbm cfg using FEDERATED YES

C. db2 update dbm cfg using NICKNAME YES

D. db2 update dbm cfg using NICKNAME, WRAPPER, SERVER, USER MAPPING YES

19. Which environment variable needs to be updated to change the active logical database partition?

?

A. DB2INSTANCE

B. DB2PARTITION

C. DB2NODE

D. DB2PARTITIONNUMBER

20. Which partition? of the following statements can be used to determine the value of the current active database

?

A. values (current dbpartitionnum)

B. values (current db2node)

C. values (current db2partition)

D. values (current partitionnum)

Answers

1. They are classified in two categories: DB2 system commands and DB2 CLP commands.

2. For DB2 system commands use command -h. For DB2 CLP commands use db2 ? command.

3. The Information Center provides a fast search engine that lets you search all the manuals based on a keyword.

4. The db2icrt command creates a DB2 instance on the server where the command is run.

5. Every database has three default table spaces created automatically by DB2. These table spaces are:

n

SYSCATSPACE

n

TEMPSPACE1

n

USERSPACE1

6. The db2ilist command lists all instances that exist on a server, whether they are active or not.

7. on When the you server. install DB2 on a Windows server, the installation program will automatically create an instance named DB2

8. No. when The working DAS is with required the DSAC. only to allow the use of graphical tools for remote administration. The DAS is not required

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 37 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited

Understanding DB2 : Learning Visually with Examples, Second Edition

9. The DB2 environment can be configured by changing values of parameters in different areas:

n

Environment variables

n

DB2 registry variables

n

The Database Manager Configuration (dbm cfg) file and database configuration (db cfg) file

10. The system local database database directory directory can is be populated populated with with the the CREATE CREATE DATABASE DATABASE command command, (not and with with the the catalog catalog command). command. The

11. C. The db2start command starts the current DB2 instance.

12. B. The db2set -all command lists all of the currently configured registry variables.

13. D. the The instance command is dropped, list db and directory list all of the on databases C: will examine on that drive/filesystem. the local database directory, which is not removed when

14. specify D. You must the drive catalog or directory the database where before the local you database can connect directory to it. To exists. catalog In this the case database it is C:, in so this use situation, the command you must

catalog db sample on C:.

15. C. You must set the DB2INSTANCE environment variable to the instance you want to work with, in this case inst2, so

the command is export db2instance=inst2.

16. (FCM) D. The and DB2_FORCE_FCM_BP not to use the network. registry Note variable that this tells question DB2 does to use not shared apply memory to DB2 9.5 for interpartition since this parameter communication is discontinued have shared memory in that release segment because size restrictions. only 64-bit kernels of AIX ® operating systems are supported, and they do not

17. B. The db2_all command runs the specified command on all database partitions in the database.

18. B. Federated support is turned on using the dbm cfg parameter FEDERATED.

19. C. DB2NODE.

20. A. The CURRENT DBPARTITIONNUM special register provides this information.

Reprinted for ibm\apurba.thakur@in.ibm.com, IBM

Page 38 / 38 IBM Press, International Business Machines Corporation (c) 2008, Copying Prohibited