Matakuliah Tahun : T0413 : 2009 Introduction to DB2 Pertemuan 1 The DB2 family system x (Intel), AMD, system p servers DB2 for Linux UNIX and Windows DB2 for z/OS DB2 for i5/OS Mainframe Bina Nusantara University (system z) DB2 for VSE and VM Midrange servers (system i) 3 DB2 History Year Achievement 1970 IBM invents the relational model and the SQL Language 1983 DB2 on the mainframe is born – First relational database 1993 DB2 for AIX is released 1996 DB2 Universal Database (UDB) version 5 is released 2006 DB2 9, the first hybrid database is released 2007 DB2 9.5 is released Bina Nusantara University 4 DB2Installation • Operating system user ID authority required: – Windows: • Part of the local administrators group on Windows (recommended), or • A Windows power user ID/Restricted User ID with elevated privileges feature – Linux: • Root user for full support. • Non-root users can also install but with some restrictions (eg: Only one instance can be created) • If problems during the installation, ensure operating system version and level requirements are met – http://www.ibm.com/software/data/db2/udb/sysreqs.html Bina Nusantara University 5 • DB2 Express-C 9.5 is very easy to install • Use the GUI-based installation (same Wizard in all platforms): – Windows: • <DB2 Imaged unzipped Directory>\EXP\image> setup.exe • Installs under: Program Files > IBM > SQLLIB – Linux: • <DB2 Image unzipped Directory>/disk1> ./db2setup • Installs under: opt/ibm/db2/V9.5 • Verify which version and fixpack level you have installed using: – db2level Bina Nusantara University 6 Uninstalling DB2 • Windows (as Admin) – Add/remove Programs • Linux (as root) – You may need to read more on the topics of “instances” later in this course to understand the following process: • Optional: Drop all databases. Database files remain intact on your file systems when you drop an instance without dropping databases first. • Stop the DB2 Administration Server. • Remove the Administration Server. • Stop DB2 instances. • Remove DB2 instances. • Remove DB2 products. – /opt/ibm/db2/V9.5/install> ./db2_deinstall -a – (Cannot use rpm) Bina Nusantara University 7 DB2 Server Editions Massively Parallel Processor (MPP) Cluster DB2 DB2 Data Warehouse Enterprise DB2 Enterprise with Database Partitioning Feature DB2 Data Warehouse Base DB2 Enterprise DB2 Workgroup DB2 Express DB2 Express-C DB2 Everyplace Bina Nusantara University 8 Database Workloads • The database workload can be one of the factors in determining which server edition you need. • There are 3 type of workloads: OLTP OLTP stands for online transaction processing. The OLTP type of workload implies short transactions performing simple SELECT, INSERT, UPDATE, and DELETE operations affecting a small number of rows. Indexes are commonly used, and access of the data is random. OLAP/DSS OLAP stands for online analytical processing and DSS for decision support systems. OLAP and DSS have similar types of workload, and they imply complex SELECT statements, normally using several JOIN operations. These are normally used for reporting in Data Warehouse/Business Intelligence operations. Access of the data is mainly sequential. Mixed A mixture of OLTP and OLAP workloads. Bina Nusantara University 9 How DB2 Server Editions are built DB2 Enterprise Edition DB2 Workgroup Edition DB2 Express Edition DB2 Express-C + Bina Nusantara University Extra functionality + Extra functionality + Extra functionality 10 DB2 Clients and drivers IBM Data Server Client DB2 for Linux, UNIX, Windows IBM Data Server Runtime Client DB2 Runtime Client Merge Modules for Windows IBM Data Server Driver for JDBC and SQLJ IBM Data Server Driver for ODBC and CLI IBM Data Server Driver for ODBC, CLI and .Net Bina Nusantara University DB2 for z/OS DB2 Connect for Linux, UNIX, Windows DB2 for i5/OS 11 The DB2 Information Center • The DB2 Information Center contains the DB2 online manuals. It also includes the manuals of products related to DB2. • It has a search field • It can be installed locally, or accessed through the internet • The internet version is the most up-to-date one. The URLs are: – V9: http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp – V9.5: http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/index.jsp • Most of the answers to your questions can be found from the DB2 Information Center! Bina Nusantara University 12 The DB2 Environment DB2 Commands & SQL/XML, Xquery Statements SQL/XML, Xquery Statements create bufferpool create tablespace create table alter bufferpool alter tablespace alter table select insert update delete ... Bina Nusantara University DB2 System Commands db2set db2start db2stop db2ilist db2icrt db2idrop ... DB2 CLP Commands db2 update dbm cfg catalog db list node directory create database list applications list tablespaces ... <sql statement> xquery < > DB2 Tools Command Line Tools Command Editor Command Line Processor Command Window Development Tools DB2 Developer Workbench Project Deployment Tool General Administration Tools Control Center Journal License Center Replication Center Task Center Information Information Center Check for DB2 Updates Monitoring Tools Event Analyzer Health Center Indoubt Transaction Manager Memory Visualizer Activity Monitor Setup Tools Configuration Assistant Configure DB2 .Net Data Provider Default DB2 Selection Wizard First Steps Register Visual Studio Add-ins DB2 Environment Instance 'myinst' Database Manager Configuration File (dbm cfg) Database MYDB1 Database Configuration File (db cfg) Port 13 The DB2 Environment DB2 Server (Linux/Windows) Instance DB2 Bina Nusantara University Port CREATING AN INSTANCE • Windows (as Admin) – db2icrt myinst • Linux (as root) – /home/db2inst1/instance> ./db2icrt -u db2fenc2 db2inst2 • db2fenc2 and db2inst2 must exist before hand. – To create an instance using the GUI: • /home/db2inst1/instance>./db2isetup • In this case, the user IDs are created for you. • Note if you run as non-root, you can only see the current configuration of existing instances. – Note: Running from db2inst1 home directory, which has soft links to /opt/ibm/db2/V9.5 (from which the same 14 commands could be run) DB2 Server (Linux/Windows) Instance DB2 Instance myinst Port Port Bina Nusantara University Port 15 Creating and connecting to a Database CREATE DATABASE mydb1 [AS dbalias] [ON drive (On Windows) / path (On Linux)] • NOTE: – If the database alias (dbalias) is not provided, it will use the same as the database name CONNECT TO dbalias [user userID using password] • NOTE: – userId/password are required for remote connectio Bina Nusantara University 16 DB2 Server (Linux/Windows) Instance DB2 Database MYDB1 Instance myinst Database MYDB1 Port Port Bina Nusantara University Port 17 DB2 Server (Linux/Windows) Instance DB2 Database MYDB1 SYSCATSPACE Bina Nusantara University Instance myinst Database MYDB1 SYSCATSPACE TEMPSPACE1 Port TEMPSPACE1 USERSPACE1 USERSPACE1 IBMDEFAULTBP IBMDEFAULTBP LOGS LOGS Port Port 18 The DB2 Administration Server (DAS) • Daemon process – In prior DB2 versions, it was a especial type of instance – Syntax of DAS commands are similar to instance commands • Must be running to allow for remote GUI administration of a DB2 server, other than that, not needed • Only one DAS per server – DAS created at installation. • On Windows it’s called: DB2DAS00 • On Linux it’s called: dasusr1 – On Linux dasusr1 maps to a Linux user Bina Nusantara University 19 DAS commands • Creating/dropping the DAS Windows (As admin) – db2admin create – db2admin drop Linux (As root) – /opt/ibm/db2/V9.5> ./dascrt –u <existing Linux user> – /opt/ibm/db2/V9.5> ./dasdrop • Starting/stopping the DAS (as the DAS user) – db2admin start – db2admin stop Bina Nusantara University 20 DB2 data server big picture admin server (DAS) My Server instance 2 instance 1 Database 1 One physical machine has: One Admin Server One or multiple Instances Bina Nusantara University Database 2 Database 1 Each Instance (Database Manager): Is a logical server context Can have one or more databases 21