DB2 UDB - International Informix Users Group
Upcoming SlideShare
Loading in...5
×
 

DB2 UDB - International Informix Users Group

on

  • 451 views

 

Statistics

Views

Total Views
451
Views on SlideShare
451
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • This presentation will discuss DB2 UDB V8.2. Keith Gardenhire is a DB2 IT Specialist with the IBM Software Group. For the past 25 years he has been involved with DB2 is some fashion from working in SQL/DS Development (now called DB2 for VSE/VM), Change Team and Level II support as well as in direct field support DB2 on the mainframe . The past 7 years he has been an IBM Instructor for DB2 UDB on the Distributed platforms. His current position is DB2 IT Specialist for the IBM Software Group.
  • The presentation will cover the DB2 UDB v8.2 for the Distributed Platforms and basic database administration.
  • DB2 Personal Edition is a standalone database system. A user can only connect to the database server, when on the server. It is a full function database. No one can connect remotely to the database. DB2 UDB Express Edition is IBM’s lowest price fully functional relational database. DB2 UDB Workgroup Server Edition is the relational database server of choice for deployment in a departmental or workgroup or medium-sized business environment that has a reasonable number of internal users. WSE is licensed on a per-user model, designed to provide an attractive price point for medium-size installations while providing a full-function relational database server. DB2 WSE can be deployed in Linux, UNIX, and Windows server environments on systems with up to four CPUs. DB2 Workgroup Server Unlimited Edition offers a per-processor licensing model for relational database deployment in a departmental or workgroup or medium-sized business environment that has Internet users or number of users that makes per-processor licensing more attractive than the WSE per-user licensing model. DB2 WSUE can be deployed in Linux, UNIX, and Windows environments on systems with up to four CPUs. DB2 UDB Enterprise Server Edition has the option of the Data Partitioning Feature. This the parallel edition feature. DB2 UDB Enterprise Server Edition may scale up to 999 processors. DB2 UDB Enterprise Server Edition for Linux may scale up to 1024 processors. DB2 UDB Personal Developer Edition enables a developer to be able to create applications. Includes DB2 Connect personal edition, DB2 Personal Edition, IBM Developer Kit (Java Technology),DB2 Net Search Extender, DB2 Spatial Extender.
  • The DPF (Data Partitioning Feature) allows for a highly scalable system DB2 database system. The DPF is a license feature for the DB2 UDB Enterprise Server Edition. DB2 UDB V8.2 supports hashing. DB2 UDB V8.2 does not support range partitioning. When using the Data Partitioning Feature, you may not use the HADR (High Availability Disaster Recovery) feature.
  • An instance manages one or more databases. Multiple instances may be place on a server. The normal reason for more than one instance is for performance and security. If running the Data Partition Feature (DPF), you should have one instance per database. When installing on Windows a database instance named DB2 will be created. On UNIX the db2setup –install will create a database instance. An instance may managed one or more databases. A database may only be associated with one instance. The command db2ilist will list all the instances on a server.
  • CREATE DATABASE MUSICKEG is the command to create a DB2 UDB V8.2 database. A table space is the logical layer between the database and the disk drive. The table spaces created, when the database is created are: SYSCATSPACE, TEMPSPACE1 and USERSPACE1. System catalog tables are created in the table space SYSCATSPACE. TEMPSPACE is used for sorting (if the sorted data does not fit into sort heap). When a database is created, the system catalog tables with the schema name SYSIBM. The views of the system catalog tables will be created with the schema name SYSCAT. Certain system catalog table information may be updated. The views that may be updated have the schema name of SYSSTAT.
  • If you specify the alias name, the user will use that alias name for the connect statement. The database configuration file is created when the database is created. The table spaces SYSCATSPACE, TEMPSPACE1 and USERSPACE1 are created. The system catalog tables are created.
  • There are two types of table space management systems: Database and System. System managed table space is easier to maintain. Database managed space is slightly faster than System managed space when adding data to a table. The reason is that DMS table space will format data pages in advance. SMS managed space has significant performance improvements in DB2 UDB V8.1. SMS table space will acquire an extent at time on DB2 V8.1, where on previous release DB2 UDB obtained 1 page at a time. If you use SMS table space, the entire table must exist in the one table space. If you use DMS table space, the table may have the data portion in one table space, the index in a second table space and the large object portion in a third table space. Table space definition will set the page size. The default page size is 4K. Page sizes can be 4K, 8K, 16K and 32K. The maximum number of rows on a page is 255 rows. This is significant, if you have small row sizes. A table space may contain up to 64 GB of data, if the page size is 4K.
  • Table spaces may be managed by System requires a directory. The directory will be created. Table spaces managed by Database requires a file or raw device.
  • The table space named TS1 is an SMS table space. If the directory does not exist, it will be created. The table space named DMS01D is a DMS table space. Data will be placed in a file.
  • From the DB2 Command Line Processor the create table command is preceded by “db2”. Notice that on the Large Object columns BIO and PICTURE the NOT LOGGED option is used. If the column is updated, the update is not logged. This will save space on the log file. The table is divided over three table spaces. The data portion of the table is placed in the table space DMS01D. The index portion of the table spaces is placed in the table space DMS01I. The Large Object portion of the table space is placed in the table space DMS01L. A table may only be place in multiple table spaces, if the table spaces are DMS (Database Managed Space). A table may only be a total size 128GB. If you use the page size of 8K. If table is placed into a table space with 4K page size, the maximum size of the table is 64GB. You may only have 255 rows per page.
  • The script file will contain the create table statement. The option –tvf indicate –t terminate SQL statement when a semicolon is found. -v verbose echo the command to the terminal. -f use the following file If you need any other options, issue the command: db2 ? Options
  • The describe command will display the table characteristics. The describe command is able to show the index characteristics. db2 describe indexes for table table-name .
  • In this case there are two indexes. PK_ARTISTS is an index that was created for primary key definition and the index ARTISTS_COMPANY_IX, which allows for duplicate keys.
  • Populating data into tables. IMPORT inserts data into tables. LOAD utility used for loading large amounts of data is faster than the IMPORT utility. Export utility moves data from a table to a flat file. db2move is a utility that may move many tables at the same time.
  • The Import utility will take the data from a flat file and place it into table. Inserts will be used to place the data into the table. The inserts will be logged. Triggers, if they exist, will be executed. DB2 UDB V8.2 will allow Online IMPORT. This means that users may access the table, while the IMPORT utility is running.
  • The IMPORT utility will insert data into a table. The format of the input file is IXF (PC/Integrated Exchange format) used by DB2 only. DEL indicates a delimited ASCII format. The columns will be delimited by a comma. Character columns will be delimited by a double quote mark. ASC indicates an ASCII file with a column beginning and ending position of the data. If you use the ASC file type the METHOD L must be used to state the beginning and ending position. Example: IMPORT FROM ARTISTS.DAT OF ASC LOBS FROM C:LOBS MODIFIED BY LOBSINFILE METHOD L ( 40 43, 1 39, 50 69, 70 83, 84 98) MESSAGES IMPORT_ARTISTS.MSG INSERT INTO ARTISTS
  • Export data from a table(s) and place data into file. With the Export utility you can take data from more than one table. Any valid SELECT statement may be used. The SELECT statement may even be JOIN.
  • The 4 phases from load.
  • The Load command is used for placing large amounts of data into the table. When using the load command, exception tables should be created. The exception tables are identical to the original table. The exception table may have two additional columns: TS (Timestamp) and MSG (CLOB 32K). If you do not have an exception table and a row violates referential integrity, the LOAD will fail. Note: If you are running the DPF (Data Partitioning Feature), the exception table must be in the same partitions as the original table.
  • The LOAD utility supports using a cursor. This is a way to load data from tables that do not exist in the database. The nickname is a federated database concept. The nickname will refer to table in a separate database. The federated database concept allows access to non-IBM database stores.
  • db2move is the Database Movement Tool. db2move is a tool that allows the DBA to copy a large number of tables using one command. Tables will be exported in the PC/IXF format. The tables can be imported and exported into another DB2 database. The db2move tool will create a db2move.lst file that will contain the table name resolution file. Each table will have an tab.ixf file associated with the table data.
  • db2move can export only the tables with a specific schema name, table name, or who created the table. The db2move can also import the tables. If the table does not exist, the db2move utility is able to create the table if the import is done.
  • The Control Center is the major GUI (Graphical User Interface). In this case create a database using the Control Center. All Databases -> Create Database -> Standard The Control Center can be used to managed a database server on a UNIX, LINUX, Windows and z/OS platforms.
  • Decide what system to place the database. Give the database a name. Database name can be up to 8 characters.
  • Table space TS1 is managed by the system so a directory “smsmusickeg s1” will be created. Table space DMS01D is managed by the database so a file of 161 4K pages will be used. The table space DMS01I will be managed by the database and a file of 48 pages will be created.
  • Creating a table space using the Control Center. Open the Control Center. Expand the tree for the database you want to create the table space. In this case let us use the database MUSICKEG. Select the “+” to left of the database.
  • Create a new table space. Select the Table Space with the RMB (Right Mouse Button).
  • Give the table space a name. The type of a table space will be chosen. A regular table space is used to contain data. A Large table space may be used to contain Large Objects and index data. System Temporary table space is used for maintaining sorting data or joined data. User Temporary table space for creating temporary tables.
  • The creating of the table space allows you to either use SMS (System Managed Space) or DMS (Database Managed Space). SMS allows a pages to be allocated as needed. DMS has a specific predefined limit. If the DMS table space becomes full. no more pages can be allocated until the DBA (Database Administrator) increases the size of a table space. (This will be covered in detail later in the presentation.) At this point the size of the table space can be specified and the location of the table space containers.
  • The Command Editor is used to issue interactive commands. The Command Editor can also be used to run the Visual Explain tool to see the access path.
  • The Visual Explain tool may be invoked from the Command Editor, Control Center or Activity Monitor. Let’s take a simple query from the Command Editor. SELECT NAME, TITLE, TITLES.COMPANY, YEAR FROM ARTISTS, TITLES WHERE ARTISTS.ARTNO = TITLES.ARTNO AND NAME LIKE ‘Ra%’ ORDER BY NAME; In this particular case no indexes were used. Table scans were executed on the table TITLES and ARTISTS.
  • Added an index on the NAME column of the ARTISTS table. Notice a diamond shows above the ARTISTS table. This indicates an index is being used on the ARTISTS table. The timeron cost has decreased from the previous query. Rectangles indicate a table. Diamond indicates an index is being used.
  • Task Center is used to schedule tasks. This is very effective in setting up DBA tasks that require continuous running of the job. For example tasks that might be considered for the Task Center might be: REORGANIZATION of tables, running statistics for a table, online backup of a database.
  • The Journal shows certain activities that have been run against the databases. From the Journal the DBA can see the status of jobs run from the Task Center.
  • When the database is started, either by the first connect or using the “ACTIVATE DATABASE” command, the primary log files are allocated. The number of primary logs is defined by the database configuration parameter LOGPRIMARY. When LOGRETAIN = NO (Database Configuration parameter) and the primary log files are full, the secondary log files will be allocated. LOGPRIMARY indicates the number of log files that will be allocated when the database starts. LOGSECOND indicates the maximum number of secondary log files that can be allocated. If you set LOGSECOND to a -1, an infinite number of secondary log files can be allocated.
  • When LOGRETAIN = RECOVERY, log files are maintained. When the primary log files are used, additional log files will be created.
  • Backup in DB2 UDB V8.2 will allow the logs to backed up at the same time as the database. You may only include the logs only in an online backup. BACKUP DB database-name ONLINE to c:ackup INCLUDE LOGS This command will include the log files with the backup. If LOGRETAIN=NO, you may only do offline backups.
  • Offline backup no one can access the database during a backup. Online backup will allow users to be accessing the database at the time the backup is executing. If LOGRETAIN=RECOVERY, a table space(s) may be recovered from a full database backup. When the restore is finished, the database is left in a roll forward pending state. If the database configuration parameter LOGRETAIN = RECOVERY, the DBA (database administrator) may recover the database to a point in time. The RECOVER DATABASE command combines both RESTORE DATABASE and ROLLFORWARD DATABASE commands.
  • HADR allows for a standby database. The standby database is used, if the primary database is unavailable. The clients will be automatically rerouted to the standby database. To invoke the HADR feature update the database configuration. If the standby database does not hear from the primary database is 120 seconds (default), the standby database takes over. HADR is not available with the DPF (Data Partitioning Feature)
  • Let us cover a few simple performance and tuning options of using DB2.
  • The Configuration Advisor allows the DBA to answer several questions. DB2 UDB will then set the configuration parameters.
  • As with any performance configuration parameters your performance improvement may vary. Each person has there own personal preferences.
  • There is one default buffer pool. The buffer pool is named IBMDEFAULTBP and is 250 4K pages on a Windows operating system and 1000 4K pages on a UNIX operating system. When page is requested, DB2 will search the buffer pool first. If the page is not in the buffer pool, DB2 will issue a physical I/O request. Therefore it is imperative to keep pages, that are needed in the buffer pool. Suggestion: In an OLTP (Online Transaction Processing ) environment you would want high impact tables in a buffer pool by itself. For DSS (Decision Support Systems) one large buffer pool should suffice. The command “GET SNAPSHOT FOR TABLES ON database” will produce what tables are accessed the most. If you change page sizes from the default 4K page, make sure that a buffer pool is made with the same size.
  • A logical read occurs when DB2 attempts to find a page in the buffer pool. A physical read occurs, when the page requested is not in the buffer pool.
  • It is probably better to keep sort data in memory. Sort overflows indicate data to be sorted did not fit in memory. The command “GET SNAPSHOT FOR ALL ON database” will show how many sort overflows have occurred. The database configuration parameter SORTHEAP should be adjusted to eliminate a number of the sort heaps. If the SORTHEAP is not big enough, DB2 will overflow the sort into TEMPSPACE. Note: If you change a page size from the default size of 4K, you must also create TEMPORARY table space of that size.
  • A dynamic SQL statement is executed. The database manager will verify if the statement is in package cache (package cache lookup). If the SQL statement is not in package cache, the statement is compiled and placed in package cache (package cache insert). If there are no sections available in package cache, a package cache overflow will occur. When package cache overflows, it expands dynamically. You may flush package cache with the command: FLUSH PACKAGE CACHE DYNAMIC Package cache is allocated at database start up time. Look for the database parameter PCKCACHESZ (it is a calculated value of MAXAPPLS * 8).
  • By default a row is locked. The LOCKLIST is number of 4K pages, that will hold all the lock request blocks. MAXLOCKS determines the percentage of locklist that 1 user may hold. If this percentage is exceeded, the lock request blocks will updated into one table lock. Lock escalation normally indicates a problem. Changing the default row level locking for a table to table level, especially if the table is read only is a good idea.
  • A LOCKWAIT occurs when a user is waiting on an object in the database. This slide shows two users, DBAPOT and ADMIN, waiting for a resource held by user KGARDEN. From the Control Center select the instance named “DB2” with the RMB (Right Mouse Button). From the pop-up menu select the Applications (menu item). Highlight the user holding the lock and select the command button Show Lock Chains .
  • The Activity monitor (new to DB2 UDB V8.2) is able to assist in finding the high impact SQL statements. Visual Explain and the character explain tools are able to show the access path of a single SQL Statement. The Design Advisor is able to suggest indexes and MQT (Materialized Query Table), that may help in deciding what may improve performance of the SQL statement.
  • To get to this point Open the Control Center -> Select the database with the RMB (Right Mouse Button) -> Activity Monitor Determine the SQL Statement that is causing the problem. In this example select the Report: Dynamic SQL statements in the cache with the longest average execution time. From here you can select the SQL Statement and execute Visual Explain.
  • In this case an index was used for the table TITLES. Notice the diamond above the table DBAPOT.TITLES. This diamond indicates an index is being used. A table scan was run against the tables WAREHOUSE and ARTISTS. DB2 UDB has a cost based optimizer so it is important to have statistics up to date. If you double click on the tables (rectangle), the table statistics will be displayed.
  • Notice the STATS_TIME row.
  • There are many things that may affect performance. These are just a couple of tuning tips.
  • All these groups should be defined to the operating system. If the group is defined in the operating systems security, any userid in that group has the authority. The SYSMON_GROUP is new for DB2 UDB V8.1. Users in this group will be able issue GET DATABASE MANAGER MONITOR SWITCHES, GET MONITOR SWITCHES, GET SNAPSHOT, LIST ACTIVE DATABASES, LIST APPLICATIONS, RESET MONITOR SWITCHES and UPDATE MONITOR SWITCHES.
  • DB2 UDB Administration for the Oracle DBA For the Distributed Database on Linux, Windows, UNIX. Hands on Labs on Windows workstation. Date: July 12, 13, 2005 (Tuesday and Wednesday) Start Time: 09:00 A.M. End Time: 05:00 P.M. Location: IBM Technology Center 8401 Greensboro Drive McClean, VA 22102 Suite 120 (First Floor) Customers who would like to attend contact: Keith E. Gardenhire e-mail: [email_address] Phone: (301)803-1717 I am doing a 2 day class DB2 UDB V8.2 for the Oracle DBA. The class will cover Database Structure Discuss the differences between DB2 UDB and Oracle RDBMS data structures. Show what table spaces are created, when a DB2 UDB database is created. Discuss the database configuration parameters and the difference that Oracle uses for INIT.ORA file. Labs: Create the SAMPLE and a custom DB2 UDB database Lecture 1: Command Line Processor Lab: Using the DB2 Command Line Processor to examine instance and database configuration. List the tables that exist for a database Show the column characteristics for a table Use the Graphical User Interface (GUI) to display database manager configuration parameters and database configuration parameters. Lecture 2: Database Exploration Understand the database structure: Table Spaces, tables, indexes and system catalog tables. Discuss Referential Integrity constraints. Lab: Create the table spaces and tables using the DB2 Command Line Processor. Learn how to use script files to create database objects. Use the Task Center (GUI) to schedule a job to create the table spaces. If this job is successful, execute a second script to create tables. This exercise will demonstrate how to create and schedule jobs. Use the Journal to see the results of a previously executed task. Alter the tables and add the referential integrity. Lecture 3: Populate the Database Discussions on the Import and Load utilities. Discuss the differences between the two utilities. Lab: Populate the tables created in the previous exercise using the LOAD utility. Use the SET INTEGRITY command to correct the referential integrity constraint violations. Lecture 4: Security Discuss the basic security for DB2 UDB environment. Understand DB2 UDB uses group authority for SYSADM, SYSMAINT and SYSCTRL authority. A new group in DB2 UDB V8.2 SYSMON has been added. Discuss the reasons that this group is used. The students will discuss the GRANT and REVOKE authority commands. The implicit security will be discussed. Lecture 5: Explain Understand how to use the Visual and character explain tools to help in discovery of SQL statement performance problems. Lab: Take an SQL statement and determine what might be incorrect with the database structure (index, Materialized Query Tables, etc..), that is causing a performance problem. Lecture 6: Automatic maintenance DB2 UDB V8.2 allows for certain database maintenance be executed automatically. Learn how to have the RUNSTATS (update the table statistics), REORG (reorganization of a table), and database backups to run automatically. Lab: Using the Control Center (GUI) to set up a maintenance window and to have the REORG, RUNSTATS and database backup be executed during this maintenance window. Lecture 7: Recovery Discussions on the two types of logging: Circular and Archival modes Discussions on the two types of database backup: Offline and Online Recovery modes: Full database recovery, Partial database recovery (table space) and recovery to a point in time Database Configuration parameters that are used in recover will be discussed. Lab: Backup a database. Recover the database to a point in time. Lecture 8: Design Advisor The Design Advisor is a tool, that will assist the DBA (Database Administrator) in designing the proper database structure. Discuss how to capture SQL statements and run the SQL statements through the Design Advisor. Lab: Take 3 complex SQL statements and run through the Design Advisor. Take the results of the Design Advisor and place in the recommendations into the Task Center to run at a later time. Execute the Design Advisor using the DB2 Command Line Processor. Lecture 9: Health Center The Health Center is a new GUI tool for DB2 UDB V8. The Health Center captures alerts and is designed to send the alert to a user. Alerts can be set up by the DBA (Database Administrator) to be customize for a particular situation. Lab: Modify the alter configuration parameters to capture warnings when a table space gets to be 60 percent full. Modify the alter configuration parameters to capture errorss when a table space gets to be 70 percent full. Update the database manager configuration file to start the Health monitor. Lecture 10: Using the Activity Monitor The Activity Monitor, which is new for DB2 UDB V8.2, monitors the dynamic SQL Statements. The lecture will discuss dynamic versus static SQL statements. We will discuss how to capture SQL statements and generate reports. Lab: Execute 3 script files that will run 3 SQL statements. Use the Activity monitor to determine the slowest SQL statement. Use the Activity monitor to Explain the SQL statement. Run Statistics on the tables used by the SQL statement (SQL statement is a join) and Explain the SQL statement again and notice the differences in the total cost to run the SQL Statement. Create two new indexes and update the statistics on both tables. Run the Explain on the SQL statement and determine if the performance was improved. Lecture 11: Stored Procedures. Discuss the differences between Oracle PL/SQL and DB2 UDB SQL/Procedure Langauge. Show how to use the DB2 Development Center to create a simple stored procedure. Learn several SQL/Procedure Language statements. Discuss the structure of a Stored Procedure. Learn how to run Stored Procedure Debugger. Lab: Create a stored procedure, that will show how to build Basic Stored Procedure Structure Manage the SQLCODE and SQLSTATE variables Code the basic EXIT HANDLERS when a row is NOT FOUND. Define a CURSOR that will manage a result set. Code a nested FOR LOOP.
  • Lecture 3: Populate the Database Discussions on the Import and Load utilities. Discuss the differences between the two utilities. Lab: Populate the tables created in the previous exercise using the LOAD utility. Use the SET INTEGRITY command to correct the referential integrity constraint violations. Lecture 4: Security Discuss the basic security for DB2 UDB environment. Understand DB2 UDB uses group authority for SYSADM, SYSMAINT and SYSCTRL authority. A new group in DB2 UDB V8.2 SYSMON has been added. Discuss the reasons that this group is used. The students will discuss the GRANT and REVOKE authority commands. The implicit security will be discussed. Lecture 5: Explain Understand how to use the Visual and character explain tools to help in discovery of SQL statement performance problems. Lab: Take an SQL statement and determine what might be incorrect with the database structure (index, Materialized Query Tables, etc..), that is causing a performance problem. Lecture 6: Automatic maintenance DB2 UDB V8.2 allows for certain database maintenance be executed automatically. Learn how to have the RUNSTATS (update the table statistics), REORG (reorganization of a table), and database backups to run automatically. Lab: Using the Control Center (GUI) to set up a maintenance window and to have the REORG, RUNSTATS and database backup be executed during this maintenance window. Lecture 7: Recovery Discussions on the two types of logging: Circular and Archival modes Discussions on the two types of database backup: Offline and Online Recovery modes: Full database recovery, Partial database recovery (table space) and recovery to a point in time Database Configuration parameters that are used in recover will be discussed. Lab: Backup a database. Recover the database to a point in time. Lecture 8: Design Advisor The Design Advisor is a tool, that will assist the DBA (Database Administrator) in designing the proper database structure. Discuss how to capture SQL statements and run the SQL statements through the Design Advisor. Lab: Take 3 complex SQL statements and run through the Design Advisor. Take the results of the Design Advisor and place in the recommendations into the Task Center to run at a later time. Execute the Design Advisor using the DB2 Command Line Processor. Lecture 9: Health Center The Health Center is a new GUI tool for DB2 UDB V8. The Health Center captures alerts and is designed to send the alert to a user. Alerts can be set up by the DBA (Database Administrator) to be customize for a particular situation. Lab: Modify the alter configuration parameters to capture warnings when a table space gets to be 60 percent full. Modify the alter configuration parameters to capture errorss when a table space gets to be 70 percent full. Update the database manager configuration file to start the Health monitor. Lecture 10: Using the Activity Monitor The Activity Monitor, which is new for DB2 UDB V8.2, monitors the dynamic SQL Statements. The lecture will discuss dynamic versus static SQL statements. We will discuss how to capture SQL statements and generate reports. Lab: Execute 3 script files that will run 3 SQL statements. Use the Activity monitor to determine the slowest SQL statement. Use the Activity monitor to Explain the SQL statement. Run Statistics on the tables used by the SQL statement (SQL statement is a join) and Explain the SQL statement again and notice the differences in the total cost to run the SQL Statement. Create two new indexes and update the statistics on both tables. Run the Explain on the SQL statement and determine if the performance was improved. Lecture 11: Stored Procedures. Discuss the differences between Oracle PL/SQL and DB2 UDB SQL/Procedure Langauge. Show how to use the DB2 Development Center to create a simple stored procedure. Learn several SQL/Procedure Language statements. Discuss the structure of a Stored Procedure. Learn how to run Stored Procedure Debugger. Lab: Create a stored procedure, that will show how to build Basic Stored Procedure Structure Manage the SQLCODE and SQLSTATE variables Code the basic EXIT HANDLERS when a row is NOT FOUND. Define a CURSOR that will manage a result set. Code a nested FOR LOOP.

DB2 UDB - International Informix Users Group DB2 UDB - International Informix Users Group Presentation Transcript

  • DB2 UDB the Basics Keith E. Gardenhire [email_address]
  • Introduction
    • DB2 UDB V8.2
    • Basic Database Administration
  • Products DB2 Personal Edition DB2 Workgroup Server Edition DB2 Enterprise Server Edition DB2 Workgroup Server Unlimited Edition DB2 UDB Express Edition
  • Data Partitioning Feature
  • Instance
    • Manages one or more databases
    • Must have root or Administrator Authority to create
    • db2icrt is used to create an instance
    • db2idrop is used to drop an instance
    • db2iupdt is used to update the instance
    db2icrt -u fencedusr instance_name db2start will start an instance db2stop will stop an instance
  • Creating the Database
    • Create db database-name
    • Creates three table spaces
    • Creates System Catalog Tables
  • Create Database Command
    • CREATE DATABASE dbname AS alias_name
  • Table Space Logical layer between Hardware and Database Comprised of one or more containers A container is a file or a directory REGULAR CREATE TABLESPACE name LARGE SYSTEM TEMPORARY USER MANAGED BY SYSTEM system-containers DATABASE database-containers
  • System Containers SMS Containers USING (‘container string’) DMS Containers USING (FILE ‘container string’ number of pages) (DEVICE ‘container string’ number of pages)
  • Table Space Example CREATE TABLESPACE TS1 MANAGED BY SYSTEM USING (‘/home/inst01/database/ts1’) CREATE TABLESPACE DMS01D MANAGED BY DATABASE USING (FILE ‘C:DMSDATABASEDMS01D’ 1000)
  • Create Tables Command Line db2 create table ARTISTS ( ARTNO SMALLINT NOT NULL, NAME VARCHAR(40), COMPANY CHAR(20), BIO CLOB (10K) NOT LOGGED, PICTURE BLOB (2700K) NOT LOGGED ) IN DMS01D INDEX IN DMS01I LONG IN DMS01L
  • Create Table Script File create table warehouse (itemno smallint, warehousename char(20), qty integer ) in dms03d; The script file cr_warehouse contains the above info db2 –tvf cr_warehouse
  • Table Characteristics Describe command db2 describe table ARTISTS Column Type Type name schema name Length Scale Nulls --------------- --------- ------------------ -------- ----- ------ ARTNO SYSIBM SMALLINT 2 0 No NAME SYSIBM VARCHAR 40 0 Yes COMPANY SYSIBM CHARACTER 20 0 Yes BIO SYSIBM CLOB 20480 0 Yes PICTURE SYSIBM BLOB 2764800 0 Yes
  • Describe Indexes
  • Moving Data
  • Moving Data
    • IMPORT
    • EXPORT
    • LOAD
    • db2move
  • Import / Export File Import Export
  • IMPORT utility IMPORT FROM filename OF IXF DEL ASC LOBS FROM lob-path MODIFIED BY options MESSAGES INSERT INTO table-name INSERT_UPDATE REPLACE REPLACE_CREATE
  • Export EXPORT TO file OF IXF MESSAGES message-file DEL WSF select statement
  • LOAD
    • Load Loads data, collects index keys
    • Build creates the indexes
    • Delete Delete unique key violations place into exception tables.
    • Index Copy – copy indexes from temp table space
  • LOAD Command LOAD FROM filename OF IXF ASC DEL LOBS FROM lob-path MODIFIED BY options MESSAGES message-file INSERT INTO table-name REPLACE RESTART TERMINATE
  • LOAD from Cursor Create nickname sales for another database SAMPLE table SALES Create nickname employee for another database SAMPLE table EMPLOYEE DECLARE C1 CURSOR FOR SELECT SALES.SALES_PERSON, LASTNAME, FIRSTNME FROM SALES, EMPLOYEE WHERE SALES_PERSON = EMPLOYEE.LASTNAME LOAD FROM C1 OF CURSOR INSERT INTO LOCAL_SALES
  • db2move db2move.lst table.ixf DB2MOVE
  • db2move syntax db2move database-name import export load tc table-creators tn table-name sn schema-names ts table space-names
  • GUI Tools Using Graphical User Interface
  • Using the Control Center
  • Control Center – Create Database
  • Examples of Table Space CREATE TABLESPACE TS1 MANAGED BY SYSTEM USING (‘C:SMSMUSICKEGTS1’) CREATE TABLESPACE DMS01D MANAGED BY DATABASE USING (FILE ‘C:DMSMUSICKEGDMS01D’ 161) EXTENTSIZE 8 PREFETECHSIZE 8 CREATE TABLESPACE DMS01I MANAGED BY DATABASE USING (FILE ‘C:DMSMUSICKEGDMS01I’ 48) EXTENTSIZE 4 PREFETCHSIZE 4
  • Table Space Using GUI
  • Table Space Using GUI (2)
  • Table Space Using GUI (3)
  • Table Space Using GUI (4)
  • Command Editor
  • Visual Explain
  • Visual Explain
  • Task Center
  • Journal
  • RECOVERY
  • Recovery
    • Defining logs
    • Recovery of database
    • Recovery of a table space
    • Offline versus Online
  • Database Recovery LOGRETAIN = NO
  • Database Recovery LOGRETAIN = RECOVERY
  • Backup
    • If LOGRETAIN = Recovery you may backup table space or database
    • If LOGRETAIN = NO you may only backup database
    • BACKUP DB database-name ONLINE to C:ackup
    • INCLUDE LOGS
  • Recovery
    • If LOGRETAIN = NO, you may only recover the database
    • If LOGRETAIN = RECOVERY, you may recover a table space or a database from a full database backup
  • Modes of Recovery
    • Offline
    • Online
    • RESTORE DB database-name FROM file TAKEN AT time
    • ROLLFORWARD DATABASE database-name
    • TO isotime AND STOP
    • END OF LOGS
  • HADR – High Availability Disaster Recovery
  • Performance and Tuning
  • Performance and Tuning
    • Database Configuration parameters
    • Database Structure
    • SQL Statements
  • Database Configuration parameters
  • Configuration Parameters
  • Buffer Pool
  • Monitoring Buffer Pool Hit Ratio
    • db2 get snapshot for bufferpools on database-name
    • Bufferpool name = IBMDEFAULTBP
    • Database name = MUSICKEG
    • Database path = C:DB2NODE0000SQL00002
    • Input database alias = MUSICKEG
    • Snapshot timestamp = 05/04/2005 13:11:37.329018
    • Buffer pool data logical reads = 336
    • Buffer pool data physical reads = 129
  • Sort Heap
    • Sorts are done in sortheap
    • If no space for sort data is moved to TEMPSPACEn
    • GET SNAPSHOT FOR ALL ON database
  • Package Cache
    • Dynamic SQL statements
  • LOCK
    • Locks are held to prevent loss of data
    • Lock Row / Table / Table Space
    • LOCKLIST
    • MAXLOCKS
    • ALTER TABLE table-name LOCKSIZE TABLE
  • Show Locks
  • SQL Statements
    • Determine which statement is causing the majority of problems
    • Determine what might be causing the problem
    • Testing the solution
  • SQL Activity Monitor
  • Visual Explain
  • Table Statistics
  • Performance Summary
    • Buffer pools
    • Numerous Database Configuration parameters
    • SQL Statement Tuning
  • Security
  • Security
    • Security is used at the operating system level
    • Table access is through the database
  • Instance Level
    • SYSADM_GROUP
    • SYSCTRL_GROUP
    • SYSMAINT_GROUP
    • SYSMON_GROUP
  • GRANT / REVOKE
    • GRANT access to an object/program
    • REVOKE access to an object/program
    • GRANT SELECT ON TABLE ARTISTS TO USER1
  • Summary
    • The Relational Database can be simple or complex
    • The database structure is simple, Table spaces, Tables, etc.
    • Recovery is straight forward
    • Database maintenance can be automated
    • Tuning the database is a life long endeavor
  • DB2 UDB Proof of Technology
    • July 12, 13 DB2 UDB Administration Proof of Technology
    • IBM – McClean Tec
    • 8401 Greensboro Drive
    • McClean, VA 22102
    • Suite 120 First Floor
    • WebSphere Information Integrator July 14, 2005
    • Contact: Keith E. Gardenhire
    • [email_address]
  • DB2 UDB Proof of Technology Con’t