Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scripting Pertemuan 4 Matakuliah: T0413 Tahun: 2009.

Similar presentations


Presentation on theme: "Scripting Pertemuan 4 Matakuliah: T0413 Tahun: 2009."— Presentation transcript:

1

2 Scripting Pertemuan 4 Matakuliah: T0413 Tahun: 2009

3 Bina Nusantara University 3 There are two general forms of scripting: –SQL scripts –Operating system (shell) scripts SQL Scripts –Simple to understand –Platform independent –Script parameters not supported Operating system scripts –Greater flexibility –Additional logic possibilities –Supports parameters/variables –Platform-dependent Scripting

4 Bina Nusantara University 4 Suppose the following commands are saved in a file called script1.db2 CONNECT TO EXPRESS; CREATE TABLE user1.mytable (col1 INTEGER NOT NULL, col2 VARCHAR(40), col3 DECIMAL(9,2)); SELECT * FROM user1.mytable FETCH FIRST 10 ROWS ONLY; COMMIT; A Basic SQL Script

5 Bina Nusantara University 5 An SQL script can be executed from the Command Editor or the DB2 Command Window/Linux shell To run the previous script from the command line (DB2 Command Window), you would use the following command: db2 –t –v –f script1.db2 –z script1.log -t indicates statements use the default statement termination character (semicolon) -v indicates verbose mode; causes db2 to output the command being executed -f indicates the following filename contains the SQL statements -z indicates the following message filename should be used for appending screen output for later analysis (optional, but recommended) Note: It is a good idea to delete these message files before the execution of DB2 scripts so that output from a previous script execution is not mixed with output from the current script execution Executing SQL Scripts

6 Bina Nusantara University 6 When a different statement termination character is needed A script containing SQL PL code needs to use a different statement termination character other than the default (semicolon) This is due to the fact that semicolons are used within SQL PL object definitions to terminate procedural statements Delimit the end of each SQL PL application object with a different statement termination character

7 Bina Nusantara University 7 When a different statement termination character is needed –e.g. CREATE PROCEDURE P1() declare x int; …. END! CREATE PROCEDURE P2() … END! When executing the script, inform DB2 that a different statement termination character is being used: db2 –td! –v –f procs.db2 –z procs.log

8 Bina Nusantara University 8 Suppose the following statements are saved in a file called create_database.bat set DBPATH=c: set DBNAME=PRODEXPR set MEMORY=25 db2 CREATE DATABASE %DBNAME% ON %DBPATH% AUTOCONFIGURE USING MEM_PERCENT %MEMORY% APPLY DB AND DBM db2 CONNECT TO %DBNAME% USER %1 USING %2 del schema.log triggers.log app_objects.log db2 set schema user1 db2 –t –v –f schema.db2 –z schema.log db2 –td@ -v –f triggers.db2 –z triggers.log db2 –td@ -v –f functions.db2 –z functions.log To execute this script from the command line, you would issue the following command: create_database.bat db2admin ibmdb2 Passwor d UserID A Simple Operating System (Shell) Script

9 Bina Nusantara University 9 DB2 Process Model – Threaded engine infrastructure

10 Bina Nusantara University 10 db2sysc –The main DB2 system controller or engine. In DB2 9.5, there is only one multi-threaded main engine process for the entire partition. All Engine Dispatchable Units (EDUs) are threads inside this process. Without this process, the database server cannot function. On Windows the process name is db2syscs. db2acd –The autonomic computing daemon. It is used to perform client side automatic tasks, such as health monitor, automatic maintenance utilities, and the admin scheduler. This process was formerly called db2hmon. It runs multiple threads that establish connections to the database engine to perform this work. db2wdog –The DB2 watchdog. The watchdog is the parent of the main engine process, db2sysc. It cleans up resources if the db2sysc process abnormally terminates, and spawns db2fmp processes as well as the health monitor process. db2vend –The fenced vendor process introduced in DB2 9.5 All vendor code runs in this process outside of the engine. db2fmp –Fenced processes that run user code on the server outside the firewall for both stored procedures and user defined functions. This process replaces both the db2udf and db2dari processes that were used in previous versions of DB2. Common Processes

11 Bina Nusantara University 11 db2sysc –The system controller thread. This thread is responsible for the start-up and shut- down and the management of the running instance. Its EDU name is the same as the process name of the main db2sysc process which spawned this thread. db2tcpcm –tcpip communication/listener db2agent –Coordinator agent that performs database operations on behalf of applications (at least 1 per connection, depending if Connection Concentrator is enabled). db2agntp –Active subagent spawned if INTRA_PARALLEL is set to YES. Will perform database operations for the application. db2agent will coordinate the work between the different db2agntp subagents. db2pfchr –DB2 asynchronous I/O data prefetcher (NUM_IOSERVERS) db2pclnr –DB2 asynchronous I/O data writer (NUM_IOCLEANERS) Common Threads

12 Bina Nusantara University 12 DB2 Memory Model

13 Bina Nusantara University 13 Real memory cache for table/index data Reduces direct sequential I/O –Promotes asynchronous reading (pre-fetching) and writing Allocates memory in units of 4K,8K,16K and 32K pages At least one buffer pool required per database At least one matching bufferpool for a table space based on page size Buffer Pool Basics

14 Bina Nusantara University 14 Control Center > (expand) All Databases folder > (right-click) Buffer Pools folder > Create Creating a Buffer Pool

15 Bina Nusantara University 15 Buffer Pool Name Page Size Number of Pages Area for Block- based Buffer Pools When Buffer Pool Is Created Create Buffer Pool Dialog

16 Bina Nusantara University 16 A place to store tables - abstracts the details of physical storage Composed of one or more "containers" (files, directories, or raw devices) Characteristics –page size of 4KB, 8KB, 16KB, or 32KB Must correspond to a buffer pool with same page size –extent size the number of pages written to one container before writing to the next –pre-fetch size the number of pages read data when pre-fetching is performed –buffer pool the buffer pool to use as cache Table Space Basics

17 Bina Nusantara University 17 REGULAR –for user tables –example: USERSPACE1 LARGE –optionally separate out LOB data into its own table space. –Use also for XML. TEMPORARY –SYSTEM TEMPORARY used by DB2 for internal operations, such as sorts example: TEMPSPACE1 –USER TEMPORARY Used for User Defined Global Temporary tables (in-memory) Often confused with system temporary table spaces Table Space Types

18 Bina Nusantara University 18 MANAGED BY SYSTEM –System Managed Storage (SMS) –Easy to manage –Containers: are file system directories space not pre-allocated, files grow dynamically fixed at creation time (containers cannot be added later) –Cannot split index and LOB data across different table spaces MANAGED BY DATABASE –Database Managed Storage (DMS) –Containers: Pre-allocated files or raw devices –If raw devices, data is written directly without O/S caching containers can be added/dropped/resized –Can place index, table and LOB data in separate table spaces Table Space Management

19 Bina Nusantara University 19 MANAGED BY AUTOMATIC STORAGE –Intended as a “single point of storage management” for table spaces –Create a database and associate a set of storage paths with it –No explicit container definitions are provided –Containers automatically created across the storage paths –Growth of existing containers and addition of new ones completely managed by DB2 –Redefine those storage paths during a database RESTORE Table Space Management

20 Bina Nusantara University 20 –CREATE DATABASE DB1 AUTOMATIC STORAGE YES –CREATE DATABASE DB3 ON /data/path1, /data/path2 –CREATE TABLESPACE TS2 MANAGED BY AUTOMATIC STORAGE –CREATE TEMPORARY TABLESPACE TEMPTS –CREATE USER TEMPORARY TABLESPACE USRTMP MANAGED BY AUTOMATIC STORAGE –CREATE TABLESPACE TS1 INITIALSIZE 500 K INCREASESIZE 100 K MAXSIZE 100 M Automatic Storage Examples

21 Bina Nusantara University 21  "This is a 4K table space with an extent size of 8 and uses 3 raw containers" ƒTranslation: DMS table space. 4K page size. 32K of data is written to one disk before writing to the next. (4K x 8 pages per extent = 32K)  Tables do not share extents  00 3 6 9 12 01 4 7 10 2 5 8 11 Extents Striped across containers Table2 Table1 Pages and Extents

22 Bina Nusantara University 22 Creating a Table Space Control Center > (expand) All Databases folder > (right-click) Table Spaces folder > Create

23 Bina Nusantara University 23 Inter-query Parallelism –Multiple queries running at the same time Intra-query Parallelism –Intra-partition parallelism Turned on by the INTRA_PARALLEL dbm cfg parameter –Inter-partition parallelism Query parallelism

24 Bina Nusantara University 24 Intra-partition Parallelism

25 Bina Nusantara University 25 Inter-partition Parallelism (DPF option in EE)

26 Bina Nusantara University 26 Inter and Intra partition parallelism !


Download ppt "Scripting Pertemuan 4 Matakuliah: T0413 Tahun: 2009."

Similar presentations


Ads by Google