DB2v9 Basic Architecture

Embed Size (px)

Citation preview

  • 8/3/2019 DB2v9 Basic Architecture

    1/30

    Information Management

    2006 IBM Corporation

    DB2 Technical WorkshopDB2 Basic Architecture

    Business Partner Technical EnablementInformation ManagementIBM Software Group

    It is important to understand the basic DB2 architecture and how it operates internally. While DB2 issimilar to other relational database systems, there are certain fundamental differences that you should beaware. The terminology used to describe the various features and objects in DB2 may sound similar to theterminology used by other databases, however it may refer to a completely different concept. It is thereforeimportant to pay close attention to what we are about to discuss. In this module, we introduce some of theDB2 tools and utilities, the DB2 process model, and the concept of instances and databases.

  • 8/3/2019 DB2v9 Basic Architecture

    2/30

    Information Management

    2

    DB2 GUI Tools

    Control Center

    Central point of administration

    Command Editor

    GUI wrapper for command line processor (CLP)

    Journal

    Central point for logging DB2 activities

    License Center Central point of DB2 license management

    Task Center Central point for scheduling database jobs

    Health Center Central point for DB2 health monitoring

    Memory Visualizer

    Performance Tools

    Storage Management

    Self-Tuning Memory Manager

    Visual Explain Event Monitors

    Memory Visualizer

    Event Analyser

    Indoublt transaction Manager

    Configuration Assistant Tool to configure the client A light-weight version of the Control Center

    Replication Center A GUI tool to set up and administer a replication

    environment and to run the Capture and Applyprograms

    Wizards Create database Create database objects (tables, views, etc.) Generate DDL Show SQL / Show Command, etc.

    Information Center Find information about tasks, reference material,

    troubleshooting, sample programs, and related Websites.

    Developer Workbench New development environment for building stored

    procedures, user-definde functions, and structureddata types.

    Also useful for creating XQuery statements,registering XML schemas, annotating XML Schemadocuments for shredding, SQLJ development, etc.

    Data Warehouse Manager Includes reporting, online analytical processing, and

    data mining applications.

    DB2 ships with both graphical user interface and command line tools, some of which are shown here.The most important tool you will probably use is Control Center, which is the central point ofadministration in DB2. From Control Center, you can perform administrative tasks such as taking abackup, creating a new table, and collecting database statistics. When you have a moment, we highly

    recommended taking a closer look at the all of the graphical tools shown here as they can significantlyincrease your productivity and lessen the burden of memorizing new command syntax. The majority ofthe functionality available in the GUI tools is also available from the command line. The command linesyntax typically gives you more freedom to customize the target operation in more detail.

  • 8/3/2019 DB2v9 Basic Architecture

    3/30

    Information Management

    3

    DB2 Command Line Processor (CLP)

    To access it on Windows, click on the DB2 Command Window or CommandLine Processor icons, on Linux and UNIX platforms, log into the system as theinstance owner and type db2 at the command prompt.

    3 modes of operation

    Interactive mode

    an input prompt appears: db2 =>

    db2 => connect to sample

    Command line mode

    invoke the interpreter by prefacing commands and SQL with 'db2'

    db2 connect to sample

    db2 "select * from employee"

    File input mode:

    execute CLP command with db2 -f

    db2 -tf createtab.db2

    The command line interface to DB2 is known as the Command Line Processor, or CLP. To open CLP fromWindows, navigate to Start>Program Files>IBM DB2>Command Line Tools>DB2 Command LineProcessor. On Linux and UNIX systems, it can be launched by logging on as the instance owner, and typing

    db2 at the operating systems command prompt.

    CLP can be run in three different modes:

    1. In the first, known as Interactive Mode, CLPs default prompt (db2=>) will appear on the screen awaitinginput. In this mode, you can enter any valid DB2 command such as CONNECT TO SAMPLE or SELECT *

    FROM SALES and subsequently execute the command by pressing the enter key.

    2. The second, is known as Command Line Mode, which allows you to interface directly with DB2 from theoperating system prompt by prefixing all database instructions with db2 so that they are not confused withan operating system command. You may need to put quotation marks around your command or statementso the operating system command interpreter ignores any special characters you might be using, such as theasterisk (*).

    It should be noted that on Windows platforms, if you want to run to CLP in command line mode, you mustissue the commands within a DB2 Command Window. A DB2 Command Window looks identical to aWindows Operating System Command Prompt, except that the DB2 environment has been initialized. You

    can open one by going to Start>Program Files>IBM DB2>Command Line Tools>DB2 Command Window.If you try to enter DB2 commands from a Windows Operating System Command Prompt, you will get anerror message that says Command Line Not Initialized.

    3. In the third mode, file input, you can direct the utility to a file containing a list of commands you want tosubmit. When using file input mode, prefix the db2 command is followed by a f and the name of the file.By default, DB2 expects each command to be terminated with a semi-colon (;) although this can be changed.Again, on Windows platforms, if you want to run to the Command Line Processor in file input mode, you mustissue the commands from a DB2 Command Window.

  • 8/3/2019 DB2v9 Basic Architecture

    4/30

    Information Management

    4

    To end interactive or command line mode and terminate the DB2backend process (db2bp):

    db2=> terminate

    db2 terminate

    To end the interactive mode, enter

    db2=> quit

    To execute OS commands, enter !

    db2=> !dir

    DB2 Command Line Processor (CLP)... continued

    When you connect to a database from the Command Line Processor, you will notice that a newprocess, called db2bp is started. This is a background process that maintains the connection to thedatabase. To terminate the database connection and kill this background process, use the terminatecommand.

    To exit the Command Line Processors interactive mode, enter quit. This returns you to a standardoperating system command prompt.

    While you are in interactive mode, you can issue operating system commands, such as ls or dir, ifyou prefix them with an exclamation mark (!).

  • 8/3/2019 DB2v9 Basic Architecture

    5/30

    Information Management

    5

    No. of retries to connect to backend (DB2BQTRY) = 60Request queue wait time (seconds) (DB2RQTIME) = 5Input queue wait time (seconds) (DB2IQTIME) = 5Command options (DB2OPTIONS) =

    Option Description Current Setting------ ---------------------------------------- ----------------a Display SQLCA OFF-c Auto-Commit ON-e Display SQLCODE/SQLSTATE OFF-f Read from input file OFF-l Log commands in history file OFF-n Remove new line character OFF-o Display output ON-p Display interactive input prompt ON-r Save output to report file OFF-s Stop execution on command error OFF

    -t Set statement termination character OFF-v Echo current command OFF-w Display FETCH/SELECT warning messages ON-x Suppress printing of column headings OFF-z Save all output to output file OFF

    LIST COMMAND OPTIONS

    CLP Command Line Options

    The DB2 Command Line Processor has several options that can be changed, such as whether auto-commit should be turned on, whether the current command should be echoed in the output, andwhether the contents of the SQLCA should be displayed in the output. To view the current values ofthese options, enter the command: LIST COMMAND OPTIONS.

    The resulting output shows each of the different options and their current values. The Option columnof the output shows the identifier that should be used to toggle the value the parameter. Note that onLinux and UNIX platforms, these identifiers are case sensitive. The Current Settings column shows aparameter values current status. On the next sl ide, we see these values can be changed.

  • 8/3/2019 DB2v9 Basic Architecture

    6/30

    Information Management

    6

    CLP Command Line Options continued

    To change default command optionse.g. set environment variable passed to CLP

    db2set db2options=+c (to turn auto commit off)

    To change command option for the current session

    e.g. to save output to file:

    UPDATE COMMAND OPTIONS USING z ON output.txt

    Access to history of commands (when you are in Interactive mode):

    db2=> history (or H, h)

    db2=> runcmd # (or R, r)

    Utilize a text editor (when you are in Interactive mode):

    db2=> edit (or E, e) Also see:

    http://www.ibm.com/developerworks/db2/library/techarticle/dm-0503melnyk/

    Lets look at some typical examples of changing CLP options.

    To change the value of these options so that they affect all future sessions, you can update a DB2registry variable called db2options. For example, if you wanted to turn the auto-commit option off,

    you would set the db2options registry variable using the following command: db2setDB2OPTIONS=+c. The plus (+) and minus(-) signs are used to toggle the values of the parameters.Be careful not to leave any spaces before or after the equal sign (=) in the db2set command. This is avery common mistake that will not update the registry variable correctly.

    If you only want to change an option value for the current session, you can use the UPDATECOMMAND OPTIONS command. When using this command, you must specify the parameter andthe value ON or OFF, depending on how you want i ts value to be set. In the above example, weupdate the z option, which determines whether output is logged. Since the z option logs all theoutput in a file, we must also specify the file name the output should be logged in.

    To see a history of previous commands you have issued in your session, you can enter history or

    just h for short. Listed with each previous command is a line number. You can use this number toreference and run a previous command again. To do that, use the runcmd command, and providethe reference number from the history list output.

    To edit the previous command submitted while in Interactive mode, use the edit or e command.This opens the command for editing. You also have the option to run the revised command when youare finished editing.

  • 8/3/2019 DB2v9 Basic Architecture

    7/30

    Information Management

    7

    DB2 Command Editor

    A GUI wrapper for command line processor (CLP)

    Command results are displayed. SQLresults are returned on the Query Resultstab. The access plan appears in graphical

    form on the Access Plantab.

    For those who prefer a GUI interface to the database, DB2 has Command Editor.

    Command Editor can essentially be thought of as a GUI wrapper for CLP. It has the traditional advantages of a

    GUI interface, such as toolbar buttons, simple editing, and the ability to save or print files. You can use the

    Command Editor to generate, edit and execute SQL statements and DB2 commands; work with the resultingoutput; and view a graphical representation of the access plan for explained SQL statements.

    The Command Editor can be launched in multiple ways. It can be opened in a separate window by clicking its

    icon on the IBM DB2 Windows group for Command Tools, or from within Control Center via the drop downTools menu as well as embedded in a Control Center window by a right-click on any query-able object andselecting the Query option. [DEMO]. If you choose, the executable can be run directly from a operatingsystem command prompt by typing db2ce.

    The Command Editor appears as a three-tab window:

    On the Commands tab, you enter DB2 commands and SQL statements. Command results are displayed in thebottom output area. The results of multiple SQL queries or queries executed as part of a script are alsodisplayed in the output area. The result set of a single SQL query is returned on the Query Results tab.

    You can also generate the access plan for SQL statements in the Commands tab. Access plans appears ingraphical form on the Access Plan tab.

    The Query Results tab contains the result set of a single SQL query. Results are displayed in an editable table.

    The Access Plan tab shows a graphical representation of the access plan for explainable SQL statements (for

    example, SELECT, INSERT, and UPDATE statements). An access plan shows how DB2 will fetch the datafrom disk and return a result set, while also showing the associated cost.

  • 8/3/2019 DB2v9 Basic Architecture

    8/30

    Information Management

    8

    One physical machine has:

    One Administration Server

    One or multiple instances

    My Server

    instance

    1

    Database 1 Database 2 Database 1

    Admin Server

    (DAS)

    Each instance (database manager):

    Is a logical server context

    Can have one or more databases

    The DB2 Server Picture

    instance

    2

    To help us understand the DB2 Server lets picture a typical DB2 Environment.

    The outer blue rectangle depicts the physical hardware of a server.

    Every system with DB2 installed has one background process known as the DB2 AdministrationServer, or DAS. The main purpose of DAS is to provide remote administration support. It isrequired if you want to use many of the functions of the GUI client tools. For the most part, simplybeing aware of its existence is sufficient. You can let it run in the background and forget about it. Ifyou are having problems administering the server from a client, ensure that the DAS process isrunning. Each physical server has only one DAS process.

    DB2 also has the concept of an instance. An instance is the set of processes, disk and memoryallocations which provide database services. You can also think of an instance as a container fordatabases. One instance can be used to provide services to one or more databases. A singlemachine can have one or more instances. Each instance is independent of other instances, and hasits own set of configurable parameters.

    A database is the set of files which contain the actual data. You can create multiple databases inside

    of an instance. Each database is independent and does not share its configuration, system catalogsor transaction logging mechanism. You cannot query across multiple databases, unless you utilize aDB2 technique known as Federation.

    By default the DB2 installation will automatically create the DAS process and a default instance. Nodatabase is created by default.

    We will describe instances and databases in more detail later in the Workshop.

  • 8/3/2019 DB2v9 Basic Architecture

    9/30

    Information Management

    9

    A background process to support instance administration

    dasusr1 on UNIX (default)

    DB2DAS service on Windows (default)

    Only one DAS process per server machine

    Required for:

    Network database discovery

    Remote administration

    Tools Catalog task scheduling

    Stopping and starting

    DB2 Administration Serverdb2admin {stop | start}

    DB2 Administration Server Process (DAS)

    The DB2 Administration Server should always be running. However, you can manually stop and startit from a DB2 command window by using the db2admin command.

    Note that on UNIX and Linux platforms, you need to log onto the system as the DAS owner in order to

    have administration privilege to stop and start the process.

    In addition to providing remote administration support, the DAS is also used to carry out user-definedautomated tasks such as backups and statistics collection. It is also used to support network databasediscovery in which DB2 clients can broadcast a message over the network to "discover" whatdatabases exist. Servers without a running DAS process cannot respond to such broadcasts.

  • 8/3/2019 DB2v9 Basic Architecture

    10/30

    Information Management

    10

    The DAS process can also be stopped and started from the services panel in Windows

    DAS

    DB2 Admin Server (Windows)

    The DAS process on Windows can also be stopped and started from the Windows services panel.Right click on the DAS process, called DB2DAS00 and select Stop. To start it, right-click on it againand choose Start.

  • 8/3/2019 DB2v9 Basic Architecture

    11/30

    Information Management

    11

    Hostmachine

    DB2 Registry

    new features, platformspecific optimizations

    special optimizations

    DatabaseManager

    configuration

    DBM CFG

    DatabaseConfiguration

    DB CFG

    Database

    Instance

    DB2 Profile Registry

    The DB2 Environment has a set of configurable items stored in what is know as the DB2 ProfileRegistry.

    This should not to be confused with the Windows Registry. DB2s Profile Registry could be describedas a set of persistent variables which retain their settings regardless of system reboots and database

    restarts. Registry settings are used to control database server features as well as platform-specificand other special optimizations.

  • 8/3/2019 DB2v9 Basic Architecture

    12/30

    Information Management

    12

    A place to specify environment or platform specific settings

    e.g. settings for RAID, optimizer paths not yet fully integrated, communicationprotocols, environment specific performance enhancements

    Settings can be applied to various levels

    Environment Instance

    Global (all instances)

    db2set

    db2set -all

    db2set -lr

    db2set =

    list all currentlyset variables

    list all availablevariables forplatform

    list variables setfor instance

    set a registryvariable

    DB2 Profile Registry (db2set)

    DB2 Profile Registry settings are different than the Database Manager and Database configurationparameters. DBM and DB Config parameters are platform independent and are consistent acrossWindows and UNIX platforms. There are often platform specific optimizations or advanced featureswhich the DB2 server can leverage and they are typically configured and activated using the Registry.

    To view the current registry settings, use the db2set command. There are additional flags you canadd to that command to filter the output. For example, the -all flag shows all the registry variables thatare currently set. The -lr flag lists every available registry variable that can be set for the currentplatform.

    To set or change one of the registry parameters, use the db2set command, followed by theparameter name, the equal sign (=), then the new value. Ensure that you do not leave a space oneither side of the equal sign or else your change will not take effect.

    Registry variables can be set and applied at various levels. You can set them globally so that theyapply to all instances. They can be set for a specific instance. Or they can be set at an environment

    level, which means that they are set outside of DB2 using the set command in Windows, or theexport command in Linux and UNIX.

    A commonly set registry variable is DB2COMM. This variable tells DB2 what communication protocolsit should be using to listen for connections. To enable DB2 to listen for TCP/IP connections, you wouldissue the command: db2set DB2COMM=tcpip. This is done by default during the DB2 installationprocess if the installer detects a TCP/IP configuration. To unset a registry variable, set it, but do notspecify a value on the right side of the equals sign.

    With very few exceptions, the instance must be restarted before the Registry setting takes effect.

  • 8/3/2019 DB2v9 Basic Architecture

    13/30

    Information Management

    13

    An instance is also known as a Database Manager (DBM)

    Manages the system resources assigned to it

    Can be independently stopped or started

    Has its own set of processes

    Has its own configuration file (DBM CFG)

    security plan

    performance

    communications

    Example:

    One instance for development, another for QA testing.Both instances are fully independent.

    Instance Concepts

    An instance is a logical server environment needed to create and work with databases. An instance isalso frequently referred to as a database manager, or DBM.

    Instances are a collection of processes which provide access to database(s). If you have more than

    one instance created on a machine, each instance acts as an independent server environment whichcan be stopped and started without affecting other instances.

    Each instance also has its own configuration file, which is called the Database Manager Configurationfile, or DBM CFG. In DB2, various settings are controlled at the instance level, such as security,communications, and certain performance attributes. All databases contained in the instance inherit allof the instances configuration and share the instances resources.

    You might be asking yourself why you would want to have more than one instance on your server.There are different reasons for doing this. For example, you might want to have one instance set up foryour developers, and another instance set up for your testers. That way, if the testers crash theirinstance while they are doing testing work, it will not affect the developers instance. Another reasonmight be that you dont want two databases to inherit the same instance configuration settings. A good

    example of this is the TCP/IP port that applications will be using to connect to the database. This portis defined at the instance level, meaning that two databases contained in the same instance will bothbe listening for connections on the same port. If you wanted the databases to listen for connections ondifferent ports, you would need to put them in their own instances and set the correct port number foreach.

  • 8/3/2019 DB2v9 Basic Architecture

    14/30

    Information Management

    14

    Database Manager Configuration File (DBM CFG)

    Hostmachine

    DB2 Registry

    new features, platformspecific optimizations

    special optimizations

    DatabaseConfiguration

    DB CFG

    Database

    InstanceDatabaseManager

    configuration

    DBM CFG

    This diagram depicts the scope of the Database Manager configuration. If you created two instanceson the same machine, each would have its own set of DBM CFG parameters that could be configured.It should be noted that while the configuration of the Database Manager affects all databases withinthe instance they do not establish a hierarchy of parameters, as we shall see, DBM CFG parameters

    are unique instance-only settings.

  • 8/3/2019 DB2v9 Basic Architecture

    15/30

    Information Management

    15

    Instance - Stopping and Starting

    It is sometimes necessary to stop and restart an instance

    example: after changing a non-dynamic parameter in the DBM CFG

    db2stop [force]

    db2startor

    If you change a non-dynamic instance configuration parameter, you have to stop and restart theinstance for the change to take effect.

    From the command line, this can be done using the db2stop and db2start commands.

    Before an instance can be stopped, all applications must disconnect. If you want to stop the instanceimmediately, forcing off all applications thus terminating their associated processes, you can use thedb2stop force command.

    An instance can also be stopped in the Control Center by right-clicking on the instance object andselecting either Stop or Start.

  • 8/3/2019 DB2v9 Basic Architecture

    16/30

    Information Management

    16

    showparameters update

    parameters

    get dbm cfg [show detail]update dbm cfg using

    DBM CFG

    Many parameters are dynamic (take effect immediately).

    Changes to other parameters may require an instancerestart.

    The Database Manager configuration can be viewed or modified using the command line, or throughControl Center

    From the command line, you can enter the GET DBM CFG command to view the current parameter

    values. Adding the SHOW DETAIL keywords to the command shows both the current and delayedvalue of the parameters. The delayed value is the value that will take effect after stopping, then re-starting the instance.

    To update a parameter, you can use the UPDATE DBM CFG command. The syntax of thiscommand is shown on the slide. Substitute the actual parameter name for

    and the new value for. For example, to update the port number that databases will listen to connections on, to port50009, you would use the command: update dbm cfg using svcename 50009.

    Many parameters can be changed dynamically and will take effect immediately. However, if aparameter is not dynamic, the instance must be restarted for the change to take effect. To see if achanged parameter was dynamic, use the get dbm cfg show detail command and check if thedelayed value matches the current value. If they do not match, an instance restart is required for the

    new value to take effect.

    To view or update the database manager configuration from Control Center, right-click the targetinstance in the object tree pane and select Configure Parameters. A list of configurable parameterswill then be shown in a new window. Click the box with the three dots () beside the parameter toupdate the value.

  • 8/3/2019 DB2v9 Basic Architecture

    17/30

    Information Management

    17

    Databases Concepts

    A collection of tables and related objects

    Each database includes

    system catalog tables (database meta data)

    a database configuration file (DB CFG)

    a recovery log

    Databases are isolated from each other (object independent)

    A database is a collection of tables (including the data) and related objects such as indexes, views,triggers, functions, and stored procedures. Each database also has its own system catalog tableswhich contain meta data that describes the content of the database. A database also has its ownconfiguration file and recovery log.

    Databases are isolated and independent from each other to the extent of database objects and data.For example, two databases do not share the same system catalog tables or recovery log. However, ifthe databases exist in the same instance, they share the same instance processes.

  • 8/3/2019 DB2v9 Basic Architecture

    18/30

    Information Management

    18

    Database Configuration File (DB CFG)

    Hostmachine

    DB2 Registry

    new features, platformspecific optimizations

    special optimizations

    Database

    Configuration

    DB CFG

    Database

    InstanceDatabaseManagerconfiguration

    DBM CFG

    This diagram depicts the scope of the database configuration. Each database defined in an instancewill have its own configuration file. For example, if there are two databases in an instance, there willbe one database manager configuration file for the instance parameter settings and two databaseconfiguration files, one for each database.

  • 8/3/2019 DB2v9 Basic Architecture

    19/30

    Information Management

    19

    Parameters include:

    location of database logs

    defaults for query optimization

    size of memory for lock management

    etc.

    Many parameters are dynamic. Others may require that all applications

    disconnect. Non-dynamic changes to take effect after all applications disconnect and

    the first application re-connects

    get db cfg for [show detail]

    update db cfg for using

    showparameters

    updateparameters

    DB CFG from Command Line

    Database Configuration parameters control things such as the placement of log files, defaults for queryoptimization, and the amount of memory allocated for the lock list or sorting.

    The database configuration file, or DB CFG, is viewed by using the GET DB CFG FOR command.

    For example, to view the database configuration for a database named sample, you would use thecommand get db cfg for sample.

    To update a parameter, use the UPDATE DB CFG FOR command. For example, to increase theamount of memory used for locking, you would update the value of the LOCKLIST parameter to 20004K pages using the command: UPDATE DB CFG FOR SAMPLE USING LOCKLIST 2000.

    Many parameters are dynamic and will take effect immediately. If a parameter is not dynamic, thedatabase must be restarted for the change to take effect. The instance does not need to be stopped, itcan remain running, but the database will need all applications to disconnect and all databaseprocesses be deactivated. If the database was previously activated with the ACTIVATE DATABASEcommand, the DEACTIVATE DATABASE command must be issued. Otherwise, a database will nolonger be active once the last application is terminated.

    Once again, to see if a changed parameter was dynamic, use the optional keywords SHOW DETAILwhen displaying the db cfg parameters and check if the delayed value matches the current value.

  • 8/3/2019 DB2v9 Basic Architecture

    20/30

    Information Management

    20

    DB CFG from Control Center

    To view or update the configuration from the Control Center: right-click the target database in theobject tree and select Configuration Parameters. A list of parameters will then be shown in a newwindow. Click the box with the three dots () beside the parameter to update its value.

    In the example shown here, we right-clicked on an database called SAMPLE and selected theConfigure Parameters option.

    You should also take note of the menu item "Configuration Advisor". This menu item helps youautomatically configure a database by guiding you through a Wizard that uses an interview-style to askquestions about your database and its workload. Configuration Advisor will then use your answers tocompute parameter values and provide recommendations on their setting.

  • 8/3/2019 DB2v9 Basic Architecture

    21/30

    Information Management

    21

    Some DBM and DB configuration parameters support the valueAUTOMATIC. If set to automatic, DB2 will automatically adjust theparameter to reflect current resource requirements.

    DBM configuration parameter that supports AUTOMATIC:

    instance_memory - Amount of memory reserved for the instance

    DB configuration parameter that supports AUTOMATIC:

    database_memory - Size of database shared memory

    maxappls - Maximum number of active applications

    AUTOMATIC DBM and DB Configuration Parameters

    Certain database manager and database configuration parameters accept a value of AUTOMATIC.If you set a parameter to this value, DB2 automatically calculates the optimal value to use, based oncurrent resource usage.

    The database manager parameter INSTANCE_MEMORY controls the amount of memory reserved forthe instance. All the databases defined in the instance get their memory from this area.

    The database configuration parameter DATABASE_MEMORY specifies the minimum amount ofshared memory that is reserved for a database. It does not include the database manager sharedmemory or the application group memory.

    The database configuration parameter MAXAPPLS defines the maximum number of concurrentapplications that can be connected to the database. When this value has been reached, an error isreturned to any new application that tries to connect indicating that the maximum number has beenexceeded.

  • 8/3/2019 DB2v9 Basic Architecture

    22/30

    Information Management

    22

    Database Objects

    Table A collection of data logically arranged in columns and rows

    View A representation of the data in tables

    Index An ordered set of keys each pointing to a row in a table

    Schema All DB2 objects have a two part name and the schema is the first half of that name

    e.g.: BOB.STAFF A schema is an identifier that helps group database objects together.

    Schemas can be either implicit or explicit when accessing an object.

    Database Application Objects Sequences

    Triggers User-Defined Functions (UDFs)

    Stored Procedures

    DB2 allows you to create a variety of objects in a database. The objects created in one database aretotally independent from those in another.

    As an experienced database user, you should already be familiar with tables, views, indexes, triggers,

    user-defined functions, and stored procedures. If you do not come from an Oracle background, aSequence Object is used to generate unique, sequential numbers. They are typically used togenerate primary key values. (Sequence objects are not tied to a specific table, unlike IDENTITYcolumns. DB2 supports both sequence objects and IDENTITY columns).

    In DB2, the term schema applies to a somewhat different concept than other database products. Insome databases, a schema is associated with a database user. However, DB2 does not have theconcept of database users. All users are defined in an external security facility which is usually theoperating system. A schema in DB2 is simply the first part of a two-part name for an object. Whenyou connect to a database, by default, the user ID will be used as the schema and prefixed to allreferenced objects.

    For example, suppose that a user called BOB connects to a database and creates a table named T1.

    If BOB did not specify a schema with the table name, DB2 will create the table as BOB.T1. Similarly, ifBOB tries to SELECT from the STAFF table using a SQL statement like SELECT * FROM STAFF,DB2 is actually going to re-write the statement as SELECT * FROM BOB.STAFF, since all objectsmust be qualified with a schema.

    BOB can also explicitly create or reference an object in a different schema. For example, BOB mightissue the SQL statement SELECT * FROM JIM.STAFF. Since BOB explicitly specified a schema inthis case, DB2 does not use the default schema. This example also highlights the fact that two tablesnamed STAFF can co-exist as long as they both reside in different schemas.

    What is the point of this? You should be aware that regardless whether you specify a schema or not,DB2 always creates and references database objects using a schema name. If you do not provide

    one, a default one is automatically used. There is more to schemas than the simple introduction weprovided here. You have the ability to control whether a user can create, alter, or drop objects in aschema, as well as whether a user can create a brand new schema name on-the-fly. We defer adiscussion of these topics until later in the Workshop.

  • 8/3/2019 DB2v9 Basic Architecture

    23/30

    Information Management

    23

    ftp://ftp.software.ibm.com/ps/products/db2/info/vr9/pdf/letter/en_US/db2d3e90.pdf Chapter 8 DB2 Process Model

    DB2 Architecture and Process Model

  • 8/3/2019 DB2v9 Basic Architecture

    24/30

    Information Management

    24

    more info: http://www.ibm.com/developerworks/db2/library/techarticle/0304chong/0304chong.html

    Common Processes

    db2agent

    Coordinator agent that performs database operations on behalf of applications (at least 1per connection, depending if Connection Concentrator is enabled).

    db2sysc database instance process (one per INSTANCE)

    db2tcpcm tcpip communication/listener

    db2agntp

    Active sub-agent, spawned if INTRA_PARALLEL (DBM CFG parameter) is set to YES,and performs database operations for the application. The db2agent process willcoordinate the work between the different db2agntp subagents.

    db2pfchr

    DB2 asynchronous I/O data prefetcher (NUM_IO_SERVER) BP prefetchers

    db2pclnr

    DB2 asynchronous I/O data writer (NUM_IOCLEANER) BP page cleaners

    The db2sysc process is the system controller. This is the central process that manages andcoordinates all instance activities.

    The db2tcpcm process is a listener for TCPIP connection requests.

    The db2agent process acts as a coordinator between DB2 and the application. All applicationrequests are sent to the db2agent process, which in turn will delegate the work to other DB2processes.

    The db2agntp process is a sub-agent that is only spawned if intra-partition parallelism is enabled.Several of these sub-agents can work on a task in parallel, then return their results to the db2agentwhich initiated the request. When intra parallelism is disabled, there is only one db2agent servicing theapplication so there is no need for coordinating agent.

    The db2pfchr is a pre-fetcher for retrieving data from disk before it is actually needed. DB2 candetect when data might be needed, prior to the actual instruction to fetch, and will asynchronously

    spawn 1 or more of these processes to fetch the data.

    The db2pclnr is a page cleaner, responsible for writing dirty pages in memory back to disk. Thisprocess also acts asynchronously so that DB2 does not have to wait for a page to be written out to diskif it needs room to bring in a new one.

    Again, for more information about these processes and others, consult the URL at the bottom of theslide.

  • 8/3/2019 DB2v9 Basic Architecture

    25/30

    Information Management

    25

    A query is divided into parts,each being executed inparallel across multipleservers.

    Data

    DatabasePartition

    SELECT...FROM...

    Data

    DatabasePartition

    Data

    DatabasePartition

    Data

    DatabasePartition

    Inter-partition Parallelism (ESE with DPF)

    DB2 also supports inter-partition parallelism. This applies to a partitioned, sometimes called clustered,DB2 environment. Large databases can be partitioned across multiple physical and/or logical serversfor increased parallelism. Using DB2 Enterprise Server Edition with the Database Partitioning Featurea database to be partitioned across as many as a 1000 nodes.

    Inter-partition parallelism and the partitioning of a DB2 database is completely transparent toapplications.

    For example, consider an SQL statement such as SELECT SUM (col1) FROM T1

    With this type of query, each partition can perform a summation of the column, independent of theother partitions, and only for its part of the data. Once each partition completes its task, DB2 performsone final summation and returns the value to the application.

  • 8/3/2019 DB2v9 Basic Architecture

    26/30

    Information Management

    26

    Data

    Database Partition

    SELECT...FROM...

    A query is divided into parts,each being executed inparallel.

    Intra-partition Parallelism

    DB2 supports intra-partition parallelism. This means that within a database, DB2 is able to break upcomplex queries into smaller instructions and satisfy the request with parallel processing. Inotherwords, a single server side process has the ability to spawn multiple sub-processes to resolve aquery. These sub-processes can take advantage of multiple CPUs on the server machine, thus further

    increasing the performance gains of parallelism.

  • 8/3/2019 DB2v9 Basic Architecture

    27/30

    Information Management

    27

    Data DataDataData

    SELECT...FROM...

    AND divided into parts, eachbeing executed in parallel

    A query CAN BE divided intoparts being executed inparallel across multipleservers.

    Inter AND Intra-partition parallelism !!!

    And finally DB2's architecture can take advantage of both inter and intra partition parallelism atthe same time. In other words, for a given query, DB2 can break it up across each node in apartitioned database environment, then, within each partition, divide up the work amongst multiple sub-agents to resolve the query with even greater parallelism.

  • 8/3/2019 DB2v9 Basic Architecture

    28/30

    Information Management

    28

    Database

    Global Memory

    Database Manager

    Shared Memory

    Database

    Global Memory

    Application

    Global Memory

    Application

    Global Memory

    Agent

    Private Memory

    Agent

    Private Memory

    [1]

    [1]

    [1]

    [numdb]

    [maxappls]

    [maxagents]

    Types of Memory used by DBM

    This diagram depicts the high level memory architecture used by DB2. At the top, there is databasemanager, or instance, shared memory. This memory is allocated when the instance is started. Allother memory is allocated from, or attaches to, this area.

    Database global memory and application global memory are allocated when a database is activated.A database is activated when an application connects to it, or the ACTIVATE DATABASE command isissued.

    Database Global Memory is shared by all applications that use the database and can be quite largebecause it includes a database's primary data cache, known as buffer pools.

    Application Global Memory is only allocated in partitioned database environments, where the instanceconfiguration parameter called INTRA_PARALLEL is set to YES, or when the ConnectionConcentrator is enabled. It is used to allow agent processes to share their "work". Allocation of agentprivate memory is performed whenever a DB2 agent process is spawed.

    Agent private memory does not get allocated at database activation. Agent private memory is a list of

    addresses that can be used for private memory allocations when needed.

    On the next slide, we'll drill-down a li ttle bit deeper into each of these memory areas.

  • 8/3/2019 DB2v9 Basic Architecture

    29/30

    Information Management

    29

    Audit buffer size

    (audit_buf_sz)

    Monitor heap

    (mon_heap_sz)

    Database Manager Shared Memory

    (including FCM)

    (app_ctl_heap_sz)

    Application Global Memory

    Agent stack

    (agent_stack_sz)

    DRDA heap

    (drda_heap_sz)

    Statistics heap

    (stat_heap_sz)

    UDF memory

    (udf_mem_sz)

    Sort heap

    (sortheap)

    Statement heap

    (stmtheap)

    Application

    heap

    (applheapsz)

    Query heap

    (query_heap_sz) Java heap

    (java_heap_sz)

    Client I/O block

    (rqrioblk)

    Agent Private Memory

    (remote)

    Application support layer heap

    (aslheapsz)

    Client I/O block

    (rqrioblk)

    Agent/Application Shared Memory

    (local)

    Database heap

    (dbheap)

    Utility heap

    (util_heap_sz)

    Backup buffer

    (backbufsz)

    Restore buffer

    (restbufsz)

    Package cache

    (pckcachesz)

    Log buffer

    (logbufsz)

    Catalog cache

    (catalogcache_sz)

    Bufferpools

    (buffpage)

    Extended memory cache

    Locklist

    (locklist)

    Database Global Memory

    DB2 Memory Model

    This diagram illustrates each memory area in detail . Without dwelling too much on each area ofmemory, here is an example of how to interpret each box.

    The box labeled "Catalog Cache (CATALOGCACHE_SZ)" is an area of memory allocated from

    "Database heap (DBHEAP), which in turn is allocated from Database Global Memory.

    If you wanted to make the Catalog Cache very large, you might have to first increase the DatabaseHeap. From the diagram, you can see that the parameters to modify in this case are DBHEAP andCATALOGCACHE_SZ.

    Every memory area shown here its corresponding parameter name shown in parentheses.Parameters are located in either the Database Manager or Database configuration files.

    For detailed information about the Database Manager or Database configuration parameters, refer toChapter 13 of the DB2 Administration Guide: Performance.

  • 8/3/2019 DB2v9 Basic Architecture

    30/30

    Information Management

    30

    Additional Resources

    DB2 developerWorks:Everything You Wanted to Know About DB2 Universal Database Processeshttp://www.ibm.com/developerworks/db2/library/techarticle/0304chong/0304chong.html

    DB2 Administration Guide: Performance (Highly recommended)Chapter 13 - "Configuring DB2Appendix A - DB2 Registry and Environment Variables

    DB2 v9 DocumentationChapter 8 DB2 Process Modelftp://ftp.software.ibm.com/ps/products/db2/info/vr9/pdf/letter/en_US/db2d3e90.pdf

    All DB2 Product documentation is available from:http://www-306.ibm.com/software/data/db2/udb/support/manualsv9.html

    More info:http://www.ibm.com/developerworks/db2/library/techarticle/0304chong/0304chong.html

    This slide lists the additional resources mentioned earlier. We recommend consulting them if you wantto learn about these topics in more detail.