100% found this document useful (1 vote)
37 views

(Ebook) Foundation Db2 and Python: Access Db2 with Module-Based API Examples Using Python by W. David Ashley ISBN 9781484269411, 1484269411 - The ebook in PDF and DOCX formats is ready for download

The document provides information on various ebooks available for instant download at ebooknice.com, focusing on topics such as Db2 and Python, dynamic web pages with Python, and data analytics. Each ebook entry includes the title, author, ISBN, and a link for purchase. Additionally, it outlines the structure and content of the book 'Foundation Db2 and Python' by W. David Ashley, detailing its chapters and topics covered.

Uploaded by

flaviophetla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
37 views

(Ebook) Foundation Db2 and Python: Access Db2 with Module-Based API Examples Using Python by W. David Ashley ISBN 9781484269411, 1484269411 - The ebook in PDF and DOCX formats is ready for download

The document provides information on various ebooks available for instant download at ebooknice.com, focusing on topics such as Db2 and Python, dynamic web pages with Python, and data analytics. Each ebook entry includes the title, author, ISBN, and a link for purchase. Additionally, it outlines the structure and content of the book 'Foundation Db2 and Python' by W. David Ashley, detailing its chapters and topics covered.

Uploaded by

flaviophetla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

Instant Ebook Access, One Click Away – Begin at ebooknice.

com

(Ebook) Foundation Db2 and Python: Access Db2 with


Module-Based API Examples Using Python by W. David
Ashley ISBN 9781484269411, 1484269411

https://ebooknice.com/product/foundation-db2-and-python-
access-db2-with-module-based-api-examples-using-
python-33794994

OR CLICK BUTTON

DOWLOAD EBOOK

Get Instant Ebook Downloads – Browse at https://ebooknice.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

(Ebook) Foundation Db2 and Python: Access Db2 with Module-Based API Examples Using
Python by W. David Ashley ISBN 9781484269428, 148426942X

https://ebooknice.com/product/foundation-db2-and-python-access-db2-with-module-
based-api-examples-using-python-33967966

ebooknice.com

(Ebook) Foundation Dynamic Web Pages with Python: Create Dynamic Web Pages with
Django and Flask by David Ashley ISBN 9781484263389, 9781484263396, 1484263383,
1484263391

https://ebooknice.com/product/foundation-dynamic-web-pages-with-python-create-
dynamic-web-pages-with-django-and-flask-22417576

ebooknice.com

(Ebook) Foundations of PyGTK Development: GUI Creation with Python by W. David


Ashley, Andrew Krause ISBN 9781484241783, 9781484241790, 1484241789, 1484241797

https://ebooknice.com/product/foundations-of-pygtk-development-gui-creation-
with-python-7319602

ebooknice.com

(Ebook) Up and Running with DB2 on Linux by IBM ISBN 9780738485317, 0738485314

https://ebooknice.com/product/up-and-running-with-db2-on-linux-42975650

ebooknice.com
(Ebook) Understanding DB2(R): Learning Visually with Examples (2nd Edition) by Raul
F. Chong, Xiaomei Wang, Michael Dang, Dwaine R. Snow ISBN 9780131580183, 0131580183

https://ebooknice.com/product/understanding-db2-r-learning-visually-with-
examples-2nd-edition-1480140

ebooknice.com

(Ebook) Advanced Data Analytics Using Python: With Machine Learning, Deep Learning
and NLP Examples by Mukhopadhyay, Sayan ISBN 9781484234495, 1484234499

https://ebooknice.com/product/advanced-data-analytics-using-python-with-machine-
learning-deep-learning-and-nlp-examples-55670484

ebooknice.com

(Ebook) Practical Explainable AI Using Python: Artificial Intelligence Model


Explanations Using Python-based Libraries, Extensions, and Frameworks by Pradeepta
Mishra ISBN 9781484271575, 1484271572

https://ebooknice.com/product/practical-explainable-ai-using-python-artificial-
intelligence-model-explanations-using-python-based-libraries-extensions-and-
frameworks-36684612

ebooknice.com

(Ebook) Up and Running With DB2 for Linux by IBM Redbooks, Whei-Jen Chen ISBN
9780738427676, 0738427675

https://ebooknice.com/product/up-and-running-with-db2-for-linux-1383072

ebooknice.com

(Ebook) Supervised Learning with Python: Concepts and Practical Implementation Using
Python by Vaibhav Verdhan ISBN 9781484261569, 1484261569

https://ebooknice.com/product/supervised-learning-with-python-concepts-and-
practical-implementation-using-python-24688908

ebooknice.com
Foundation
Db2 and Python
Access Db2 with Module-Based API
Examples Using Python

W. David Ashley
Foundation Db2
and Python
Access Db2 with Module-Based API
Examples Using Python

W. David Ashley
Foundation Db2 and Python
W. David Ashley
Austin, TX, USA

ISBN-13 (pbk): 978-1-4842-6941-1 ISBN-13 (electronic): 978-1-4842-6942-8


https://doi.org/10.1007/978-1-4842-6942-8

Copyright © 2021 by W. David Ashley


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Celestin Suresh John
Development Editor: James Markham
Coordinating Editor: Divya Modi
Cover designed by eStudioCalamar
Cover image designed by Pixabay
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza,
Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@
springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole
member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc
is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/978-­1-­4842-­6941-­1. For more
detailed information, please visit http://www.apress.com/source-­code.
Printed on acid-free paper
This book is dedicated to teachers everywhere, but especially
all those who had me as a student.
Table of Contents
About the Author��������������������������������������������������������������������������������������������������� xiii

About the Technical Reviewer���������������������������������������������������������������������������������xv

Chapter 1: Introduction to Db2��������������������������������������������������������������������������������� 1


What Is a Relational Database?���������������������������������������������������������������������������������������������������� 3
The Relational Model��������������������������������������������������������������������������������������������������������������� 3
Domains���������������������������������������������������������������������������������������������������������������������������������� 4
Keys and Indexes��������������������������������������������������������������������������������������������������������������������� 4
Relationships��������������������������������������������������������������������������������������������������������������������������� 4
Transactions���������������������������������������������������������������������������������������������������������������������������� 5
Stored Procedures������������������������������������������������������������������������������������������������������������������� 5
Constraints������������������������������������������������������������������������������������������������������������������������������ 6
Normalization�������������������������������������������������������������������������������������������������������������������������� 6
SQL������������������������������������������������������������������������������������������������������������������������������������������������ 6
Data Definition Language (DDL)����������������������������������������������������������������������������������������������� 7
Data Query Language (DQL)���������������������������������������������������������������������������������������������������� 7
Data Control Language (DCL)��������������������������������������������������������������������������������������������������� 7
Data Manipulation Language (DML)���������������������������������������������������������������������������������������� 7
The ibm_db Project����������������������������������������������������������������������������������������������������������������������� 8
Summary�������������������������������������������������������������������������������������������������������������������������������������� 8

Chapter 2: Installing Db2������������������������������������������������������������������������������������������ 9


My Development Environment������������������������������������������������������������������������������������������������������ 9
Installation Prerequisites������������������������������������������������������������������������������������������������������������ 10
Planning the Db2 Install�������������������������������������������������������������������������������������������������������������� 11
Installing Db2������������������������������������������������������������������������������������������������������������������������������ 12

v
Table of Contents

Db2 Post-install Tasks����������������������������������������������������������������������������������������������������������������� 19


Installing the Db2 Sample Database������������������������������������������������������������������������������������������� 20
Summary������������������������������������������������������������������������������������������������������������������������������������ 21

Chapter 3: Db2 Management���������������������������������������������������������������������������������� 23


Db2 Instances����������������������������������������������������������������������������������������������������������������������������� 23
db2ilist����������������������������������������������������������������������������������������������������������������������������������� 25
Instance Environment Commands����������������������������������������������������������������������������������������� 25
Creating an Instance������������������������������������������������������������������������������������������������������������� 26
Arranging a Communication Port and Host for an Instance�������������������������������������������������� 26
Updating an Instance������������������������������������������������������������������������������������������������������������� 27
Upgrading an Instance���������������������������������������������������������������������������������������������������������� 28
Dropping an Instance������������������������������������������������������������������������������������������������������������ 29
Using Other Commands with an Instance����������������������������������������������������������������������������� 29
Databases����������������������������������������������������������������������������������������������������������������������������������� 30
Db2 Catalog Views����������������������������������������������������������������������������������������������������������������� 31
Locking Event Monitor����������������������������������������������������������������������������������������������������������� 31
Tablespace Information��������������������������������������������������������������������������������������������������������� 32
Storage Group Control Files��������������������������������������������������������������������������������������������������� 33
Global Configuration File������������������������������������������������������������������������������������������������������� 33
History Files��������������������������������������������������������������������������������������������������������������������������� 33
Logging Files������������������������������������������������������������������������������������������������������������������������� 33
Automated Storage Containers���������������������������������������������������������������������������������������������� 33
Creating a Database�������������������������������������������������������������������������������������������������������������� 34
Listing Databases������������������������������������������������������������������������������������������������������������������ 35
Activating a Database������������������������������������������������������������������������������������������������������������ 36
Deactivating a Database�������������������������������������������������������������������������������������������������������� 36
Connecting to a Database����������������������������������������������������������������������������������������������������� 36
Dropping a Database������������������������������������������������������������������������������������������������������������� 36
Tables������������������������������������������������������������������������������������������������������������������������������������������ 37
Table Types���������������������������������������������������������������������������������������������������������������������������� 39
Built-in Data Types���������������������������������������������������������������������������������������������������������������� 39

vi
Table of Contents

Creating a Table��������������������������������������������������������������������������������������������������������������������� 41
Alter a Table��������������������������������������������������������������������������������������������������������������������������� 43
Other Table SQL Statements�������������������������������������������������������������������������������������������������� 43
Dropping a Table�������������������������������������������������������������������������������������������������������������������� 44
Summary������������������������������������������������������������������������������������������������������������������������������������ 44

Chapter 4: Database Physical Design��������������������������������������������������������������������� 45


Phase 1: Data Gathering and Normalization������������������������������������������������������������������������������� 46
Data Gathering����������������������������������������������������������������������������������������������������������������������� 46
Data Normalization���������������������������������������������������������������������������������������������������������������� 48
Business Rules���������������������������������������������������������������������������������������������������������������������� 51
Phase 2: Physical Design of the Database���������������������������������������������������������������������������������� 51
Backups��������������������������������������������������������������������������������������������������������������������������������� 52
Summary������������������������������������������������������������������������������������������������������������������������������������ 53

Chapter 5: Db2 Utilities������������������������������������������������������������������������������������������� 55


Backup Command����������������������������������������������������������������������������������������������������������������������� 56
What Is a Backup?����������������������������������������������������������������������������������������������������������������� 56
Backup Verification���������������������������������������������������������������������������������������������������������������� 57
Advanced Backup Options����������������������������������������������������������������������������������������������������� 57
Backup Syntax����������������������������������������������������������������������������������������������������������������������� 57
Export Command������������������������������������������������������������������������������������������������������������������������� 59
Command syntax������������������������������������������������������������������������������������������������������������������� 60
Usage Notes�������������������������������������������������������������������������������������������������������������������������� 60
Import Command������������������������������������������������������������������������������������������������������������������������ 61
Command Syntax������������������������������������������������������������������������������������������������������������������ 61
Load Command��������������������������������������������������������������������������������������������������������������������������� 62
Command Syntax������������������������������������������������������������������������������������������������������������������ 62
Restore Command���������������������������������������������������������������������������������������������������������������������� 63
Command Syntax������������������������������������������������������������������������������������������������������������������ 64
Summary������������������������������������������������������������������������������������������������������������������������������������ 65

vii
Table of Contents

Chapter 6: Business Rules and Constraints������������������������������������������������������������ 67


NOT NULL Attribute��������������������������������������������������������������������������������������������������������������������� 67
Primary Key��������������������������������������������������������������������������������������������������������������������������������� 68
Indexes���������������������������������������������������������������������������������������������������������������������������������������� 69
Foreign Keys������������������������������������������������������������������������������������������������������������������������������� 70
CHECK and Unique Constraints��������������������������������������������������������������������������������������������������� 71
DEFAULT Constraint��������������������������������������������������������������������������������������������������������������������� 72
Triggers��������������������������������������������������������������������������������������������������������������������������������������� 72
Summary������������������������������������������������������������������������������������������������������������������������������������ 76

Chapter 7: Writing Good SQL for Db2���������������������������������������������������������������������� 77


Relational Theory������������������������������������������������������������������������������������������������������������������������ 77
Reduce Passes Through Data����������������������������������������������������������������������������������������������������� 78
Using Indexes to Increase Performance������������������������������������������������������������������������������������� 81
Sorting and Grouping������������������������������������������������������������������������������������������������������������������ 81
Programs Containing SQL����������������������������������������������������������������������������������������������������������� 82
Use Db2 Utilities Where Possible������������������������������������������������������������������������������������������������ 83
Db2 Functions����������������������������������������������������������������������������������������������������������������������������� 84
Multiple Ways to Code SQL��������������������������������������������������������������������������������������������������������� 86
Summary������������������������������������������������������������������������������������������������������������������������������������ 86

Chapter 8: Python and ibm_db������������������������������������������������������������������������������� 87


Your First Python ibm_db Program��������������������������������������������������������������������������������������������� 89
Using Parameter Markers������������������������������������������������������������������������������������������������������ 96
More on Parameter Markers�������������������������������������������������������������������������������������������������� 98
Producing Multiple Reports with Parameter Markers��������������������������������������������������������� 100
Using Parameter Markers Without Binding Variables���������������������������������������������������������� 103
Joining Tables���������������������������������������������������������������������������������������������������������������������� 106
Inserts, Updates, and Deletes���������������������������������������������������������������������������������������������� 109
Some Other ibm_db APIs����������������������������������������������������������������������������������������������������� 112
Creating Database Objects�������������������������������������������������������������������������������������������������� 116

viii
Table of Contents

Obtaining Attributes of an Existing Table����������������������������������������������������������������������������� 120


Obtaining Attributes of a Result Set������������������������������������������������������������������������������������ 126
ibm_db_dbi and Python������������������������������������������������������������������������������������������������������������ 130
Where Is the ibm_db Module Going?���������������������������������������������������������������������������������������� 133
The ibm_db_dbi Module������������������������������������������������������������������������������������������������������ 134
The Django Database Interface������������������������������������������������������������������������������������������� 134
The SQLAlchemy Adapter���������������������������������������������������������������������������������������������������� 135
The Alembic Adapter����������������������������������������������������������������������������������������������������������� 136
The Future��������������������������������������������������������������������������������������������������������������������������� 137
Summary���������������������������������������������������������������������������������������������������������������������������������� 137

Appendix A: Python ibm_db API��������������������������������������������������������������������������� 139


i bm_db APIs������������������������������������������������������������������������������������������������������������������������������ 139
ibm_db.active���������������������������������������������������������������������������������������������������������������������� 139
ibm_db.autocommit������������������������������������������������������������������������������������������������������������ 140
ibm_db.bind_param������������������������������������������������������������������������������������������������������������ 141
ibm_db.callproc������������������������������������������������������������������������������������������������������������������� 143
ibm_db.client_info��������������������������������������������������������������������������������������������������������������� 144
ibm_db.close����������������������������������������������������������������������������������������������������������������������� 146
ibm_db.column_privileges�������������������������������������������������������������������������������������������������� 147
ibm_db.columns������������������������������������������������������������������������������������������������������������������ 148
ibm_db.commit������������������������������������������������������������������������������������������������������������������� 151
ibm_db.conn_error�������������������������������������������������������������������������������������������������������������� 152
ibm_db.conn_errormsg������������������������������������������������������������������������������������������������������� 153
ibm_db.connect������������������������������������������������������������������������������������������������������������������� 154
ibm_db.createdb����������������������������������������������������������������������������������������������������������������� 157
ibm_db.createdbNX������������������������������������������������������������������������������������������������������������� 158
ibm_db.cursor_type������������������������������������������������������������������������������������������������������������ 159
ibm_db.dropdb�������������������������������������������������������������������������������������������������������������������� 160
ibm_db.exec_immediate����������������������������������������������������������������������������������������������������� 160
ibm_db.execute������������������������������������������������������������������������������������������������������������������� 162

ix
Table of Contents

ibm_db.execute_many�������������������������������������������������������������������������������������������������������� 163
ibm_db.fetch_tuple������������������������������������������������������������������������������������������������������������� 165
ibm_db.fetch_assoc������������������������������������������������������������������������������������������������������������ 166
ibm_db.fetch_both�������������������������������������������������������������������������������������������������������������� 167
ibm_db.fetch_row��������������������������������������������������������������������������������������������������������������� 168
ibm_db.field_display_size��������������������������������������������������������������������������������������������������� 169
ibm_db.field_name������������������������������������������������������������������������������������������������������������� 169
ibm_db.field_num��������������������������������������������������������������������������������������������������������������� 170
ibm_db.field_precision�������������������������������������������������������������������������������������������������������� 172
ibm_db.field_scale�������������������������������������������������������������������������������������������������������������� 173
ibm_db.field_type���������������������������������������������������������������������������������������������������������������� 174
ibm_db.field_width������������������������������������������������������������������������������������������������������������� 174
ibm_db.foreign_keys����������������������������������������������������������������������������������������������������������� 175
ibm_db.free_result�������������������������������������������������������������������������������������������������������������� 178
ibm_db.free_stmt���������������������������������������������������������������������������������������������������������������� 179
ibm_db.get_option�������������������������������������������������������������������������������������������������������������� 179
ibm_db.next_result������������������������������������������������������������������������������������������������������������� 181
ibm_db.num_fields�������������������������������������������������������������������������������������������������������������� 183
ibm_db.num_rows�������������������������������������������������������������������������������������������������������������� 184
ibm_db.pconnect����������������������������������������������������������������������������������������������������������������� 185
ibm_db.prepare������������������������������������������������������������������������������������������������������������������� 187
ibm_db.primary_keys���������������������������������������������������������������������������������������������������������� 188
ibm_db.procedure_columns������������������������������������������������������������������������������������������������ 190
ibm_db.procedures������������������������������������������������������������������������������������������������������������� 192
ibm_db.recreatedb�������������������������������������������������������������������������������������������������������������� 194
ibm_db.result���������������������������������������������������������������������������������������������������������������������� 194
ibm_db.rollback������������������������������������������������������������������������������������������������������������������� 195
bm_db.server_info�������������������������������������������������������������������������������������������������������������� 196
ibm_db.set_option��������������������������������������������������������������������������������������������������������������� 199
ibm_db.special_columns���������������������������������������������������������������������������������������������������� 201

x
Table of Contents

ibm_db.statistics����������������������������������������������������������������������������������������������������������������� 203
ibm_db.stmt_error�������������������������������������������������������������������������������������������������������������� 206
ibm_db.stmt_errormsg������������������������������������������������������������������������������������������������������� 206
ibm_db.table_privileges������������������������������������������������������������������������������������������������������ 207
ibm_db.tables���������������������������������������������������������������������������������������������������������������������� 209
Summary���������������������������������������������������������������������������������������������������������������������������������� 210

Index��������������������������������������������������������������������������������������������������������������������� 211

xi
About the Author
W. David Ashley is a technical writer for Skillsoft where he
specializes in open source, particularly Linux. As a member
of the Linux Fedora documentation team, he recently led
the Libvirt project documentation and wrote the Python
programs included with it. He has developed in 20 different
programming languages during his 30 years as a software
developer and IT consultant, including more than 18 years at
IBM and 12 years with American Airlines.

xiii
About the Technical Reviewer
Sourav Bhattacharjee is a senior technical member for
Oracle Cloud Infrastructure. As part of IBM Watson Health
Lab, he has developed many scalable systems, published a
few research papers, and applied some patents to USPTO. He
has an ample amount of hands-on experience in Python,
Java, machine learning, and many database systems. He
earned his master’s degree from the Indian Institute of
Technology, Kharagpur, India.

xv
CHAPTER 1

Introduction to Db2
Welcome to this introduction to Db2. Since you are here, you are likely looking for a
place to get started with Db2. Our hope is that this book will be that first step you are
looking for. This book is meant to be an introduction to the Db2 environment and to
the Python interface. The first half of the book will cover Db2 at a level that should be of
interest to both administrators and programmers. It will cover many aspects of Db2 that
you will make use of in either of the two roles. The last half of the book will concentrate
on using the Python programming language to interface to Db2. While mainly oriented
to programmers, administrators will find it useful as well for some of their everyday
tasks.
Db2 has a long history and is the first relational database implementation. It was
first proposed by Edgar Frank “Ted” Codd in a paper titled “A Relational Model of Data
for Large Shared Data Banks” in 1969 while working at the IBM’s San Jose Research
Laboratory in California. In the next four years, IBM researchers worked to create a
system based on the principles described in Codd’s paper (called System R). During
this time, it became obvious that a new language was needed to interact with the new
system. Codd wrote a new paper “A Data Base Sublanguage Founded on Relational
Calculus,” which became the basis for the new language called DSL/Alpha. This quickly
went through some name changes but eventually ended up being called SQL, short for
Structured Query Language.
Eventually there was an effort in the 1970s to port DSL/Alpha to the 370 mainframe
environment. It was renamed to Database 2 in 1982. The next year it was made available
to the public with another name change, DB2. This was a limited release but was highly
regarded by the customers that evaluated it. The customers actually pushed IBM to
deliver DB2 to a wider set of customers. IBM was somewhat reluctant because they were
trying to hold on to their IMS/DB market share. But eventually the customers won out,
and DB2 began to spread to other platforms including OS/2, AIX/RS6000, and Windows.

1
© W. David Ashley 2021
W. D. Ashley, Foundation Db2 and Python, https://doi.org/10.1007/978-1-4842-6942-8_1
Chapter 1 Introduction to Db2

Over the next two decades, the product went through a number of name changes
and several platform code bases. Recently with the release of version 11.1, IBM
rebranded the entire product line and brought the code bases into a small number of
code bases. The following set of products are now the standard offerings:

• Db2 (formerly DB2 LUW)

• Db2 for z/OS (formerly DB2 for z/OS)

• Db2 Hosted (formerly DB2 on Cloud)

• Db2 on Cloud (formerly dashDB for Transactions)

• Db2 Event Store (a new in-memory database for event-driven


transaction processing)

• Db2 Warehouse on Cloud (formerly dashDB)

• Db2 Warehouse (formerly dashDB Local)

• IBM Integrated Analytics System (a new system platform that


combines analytic performance and functionality of the IBM
PureData System with IBM Netezza)

The code bases for today’s Db2 offerings share a common code base that makes
porting the code to another hardware/software platform a relatively easy process. The
SQL code base has been standardized so that it is the same across all platforms, making
moving to another platform an easy task from a programming perspective.
There is also a current movement in programming applications with embedded
SQL. These types of applications are very hard to port from one platform to another
without major code modifications. Instead, IBM is moving (where possible) to an API
that can be called to process SQL statements and make use of programming language
variables for values to be added to the SQL statement. This is the methodology used for
Python that we will explore later in this book.
In the past, Db2 was considered to be too large for most applications. But as personal
computers have become a lot more powerful and then databases used by even a small
number of people have become extremely large, Db2 has become more attractive in the
management of this data. Also, the pricing model of Db2 on these platforms has become
more competitive. So if you need the performance and the ability to manage large
amounts of data, Db2 can be a very attractive product.

2
Chapter 1 Introduction to Db2

What Is a Relational Database?


A relational database is actually hard to define because no relational database system in
today’s market actually implements E. F. Codd’s 12 rules defining the relational model.
Instead, commercial relational databases implement only about seven to nine of those
rules. This is enough to make their products commercially useful without the burden of
implementing the other rules. In fact, the other rules would not be useful to most database
users, so it is questionable whether or not they will ever be implemented in a commercial
product. In fact, most commercial database vendors actually extend the relational model
by adding entities that are not really tables, such as BLOBs (which we will discuss later).

The Relational Model


Roughly, relational databases implement the concept of entities expressed as rows
and columns. A customer records table would have a single row representing a single
customer. The columns (or tuples) of the table would contain attributes of that customer.
Each column would contain a single attribute and would have a defined data type for
restricting the type of information it can contain. A typical customer address table might
be implemented as shown in Table 1-1.

Table 1-1. Sample Customer Table


CUSTNO FNAME LNAME STREET STATE ZIP

000000001 Bugs Bunny 1201 Looney Lane CA 77777


000000002 Marvin Martian 2342 Mars Avenue MA 30143
000000003 Daffy Duck 5462 Termite Terrace CA 77745
000000004 Elmer Fudd 23 Hunter Cove CA 77732

This table is a good example because it shows the kind of relationships that can
be expressed in a relational database. The CUSTNO column holds a unique customer
number for each customer (or row). The column is the primary key for this table. The
FNAME and LNAME identify the first and last names of the customer. The STREET is
the address to be used for billing the customer. The STATE column is the U.S. state the
address is located. The ZIP column identifies the mailing zip code.

3
Chapter 1 Introduction to Db2

D
 omains
Domains (or attributes) limit the data in a column to a particular type. For instance, the
data might be an integer of a particular type, a monetary value, a character string of fixed
or variable length, a date or time value, or some other domain that has been defined.

K
 eys and Indexes
The STATE column in Table 1-1 is a foreign key – that is, a primary key in another table.
A rule can be set up so that when you add a new row to the customer table, the system
checks that the value in your proposed STATE field is a valid entry in the state table. If it is
not, the record will not be inserted, and an error will be generated. Keys are also known
as indexes. When you create a primary key in a table, a special index table is created to
hold valid keys. This table is like any other table in the system; it can be queried, added
to, and deleted from. Thus, all the valid keys can be inserted into and maintained in the
table, and it can be maintained just like any other table. Only the special rules make the
index table special.

R
 elationships
All of this shows just some of the kinds of relationships that can be created (or derived)
to properly maintain a set of tables. There are probably other kinds of customer tables
that could be created like a table to maintain customer credit ratings, a customer
shipping address table, a customer contacts table, etc. All of these are specialized entities
that have relationships with the other customer tables. This is what a relational database
is all about. The idea is to express a relationship with data organized so the data is only
stored where needed and hopefully only one time.
Relationships allow the user to create customized reports that can express custom
views of the data from the database. At first glance these reports may look like they have
no relation to the data contained in the database, but they can give insights to the data
not easily possible by other means.

4
Chapter 1 Introduction to Db2

Transactions
Another aspect of relational databases is support for transactions. This means providing
a locking mechanism that can allow data to be modified while others are reading the
data or modifying other data at the same time. This is known as the ACID test, which is
an acronym for the following tests:

• Atomicity defines all the elements that make up a complete database


transaction. This might make up one or more SQL statements.
• Consistency defines the rules for maintaining data points in the
correct state after a transaction. This is usually done through an SQL
statement such as COMMIT or ROLLBACK.

• Isolation keeps the effect of a transaction invisible to others until


it is committed, to avoid confusion. This refers to the ability of the
database to keep multiple changes to a database from corrupting the
integrity of the database.

• Durability ensures that data changes become permanent once the


transaction is committed. This is done by ensuring that writes are
made to all modified tables prior to committing the transaction.

Stored Procedures
A relational database typically implements stored procedures. These are programs
stored in the database to implement special processing under several circumstances.
These procedures usually involve business logic that needs to be implemented the
same across all the database users. In many cases, only the stored procedure has the
proper permissions to modify, insert, delete, or access the data being manipulated. This
prevents users from making modifications to the data if they do not have the correct
permissions.

5
Chapter 1 Introduction to Db2

Constraints
Another property of relational databases are constraints. These make it possible to
further restrict an attribute. For instance, a column might be defined as an integer. But
the range of numbers might actually need to be constrained to a particular range. This is
what a constraint provides.
Constraints can come in many forms and are used for a number of purposes. They
are stored within the database and used when adding or modifying data.

Normalization
Normalization is another attribute of a relational database. This design process reduces
the number of nonatomic values and the duplication of data throughout the database,
thus preventing anomalies and loss of integrity. The process is known as normalization.
The process of normalization is performed by the administrator, usually during the
creation of the database. Users are not usually involved in this activity.

SQL
Within the first few years of creating the first relational database, it became very obvious
that something was needed to actually manipulate the data in a relational database. The
language was invented at IBM by Donald D. Chamberlin and Raymond F. Boyce in the
early 1970s. It was originally known as SEQUEL, but that name was trademarked and it
was changed to Structured Query Language (SQL). SQL was later standardized by ANSI,
but each relational database product extended it as needed to conform to their product
or hardware platform.
SQL is divided into four categories of statements:

• Data Definition Language (DDL)

• Data Query Language (DQL)

• Data Control Language (DCL)


• Data Manipulation Language (DML)

Most SQL books spend most of their resources on the DML part of SQL, but the other
parts are just as important, especially to the database administrator.

6
Chapter 1 Introduction to Db2

Data Definition Language (DDL)


The Data Definition Language subset consists of the CREATE, DROP, ALTER, and
TRUNCATE statements. These statements manipulate (or reorganize) the data in the
database.
The CREATE statement creates new entities in the database. This can include
tables, indexes, views, and procedures. Many database systems include character sets,
collations, transactions, and assertions as well.
The DROP statement removes entities from the database. These include all the
entities that can be created with the CREATE statement. Some databases include the
users as an entity that can be dropped.
The ALTER statement can alter an existing entity, such as adding a new column to a
table.
The TRUNCATE statement removes all data from a table or index. It is much faster
than the DELETE SQL statement.

Data Query Language (DQL)


The Data Query Language subset consists of only the SELECT statement. This is used for
all queries of information in the database. The syntax of the SELECT statement will be
covered later in Chapter 7.

Data Control Language (DCL)


The Data Control Language subset consists of the GRANT and REVOKE statements.
These statements grant and revoke privileges to and from users of the database.
The database system specifies the type of privileges that a user can be granted.
Some database systems, such as SQLite, depend on the operating system’s privilege
mechanism and thus do not support the GRANT and REVOKE statements.

Data Manipulation Language (DML)


The Data Manipulation Language subset consists of the INSERT, UPDATE, and DELETE
statements. Some systems also include the SELECT statement in this subset, but since
SELECT does not make changes to the data, this would seem an odd place to place the
SELECT statement.

7
Chapter 1 Introduction to Db2

The INSERT statement adds new rows into a table. This new data may also
automatically alter the content of a view of the table data.
The UPDATE statement alters one or more rows in an existing table (and any view
dependent on the table). The statement does not add new rows to a table, it only alters
existing data.
The DELETE statement removes rows from a table (and any view dependent on the
table).

The ibm_db Project


The ibm_db project was started sometime in 2007 with the first code commits to
GitHub on February 9, 2008. The project was a joint effort between IBM and the Python
community to create a programming interface to Db2 and Informix from Python.
Informix had been purchased by IBM around this same time, and this was part of the
project to integrate Informix into the Db2 line of products. Since then the project has
undergone steady progress with some recent major fixes.
By establishing the project on GitHub, it was thought that with community support
the project would not only improve with time but would benefit from community
participation. This has proven to be the case with many community volunteers
contributing to the project throughout the project lifetime.
Over time, the ibm_db_dbi module was added to the project, and new projects
were introduced based on the ibm_db module to support other Python projects. These
projects include ibm_db_django, ibm_db_alembic, and ibm_db_sa.
For more information, see Chapter 8.

S
 ummary
This chapter has presented some of the basic concepts that make up a relational
database and the SQL that supports it. This information is common to almost all
relational databases.

8
CHAPTER 2

Installing Db2
This chapter covers installing Db2 on Linux and Windows. Both environments use
the same installer to perform installation and creation of userids and permissions.
The installation process is pretty easy and straightforward, but there are a number of
questions you might have before you start the installation that are not answered by the
install program. We will try to cover those questions as we come to them.

My Development Environment


My development environment is not your typical Windows home system. It consists of
two Linux servers, one Windows client, and two Linux client workstations. The Linux
servers are not typical workstations but actual dedicated servers that are usually used in
small business settings. I will try to describe each system so you have some idea of what
my environment is like.
The first system is a Lenovo ThinkSystem ST250 server with four 2 TB drives
installed. It has 32 GB of memory and a six-core Xeon CPU. This is my main server and
hosts all my files. It is visible to the Internet through my firewall via the Apache Web
Server. The operating system is Fedora 32. It is also hosting my Windows files via Samba
as well as hosting a number of Virtual Machines (VMs) via libvirt. This is the system that
hosts my main Db2 databases.
The second system is Lenovo ThinkStation P320 with 256 GB of SSD and a 1 TB drive
with 32 GB of memory and a six-core/six-thread Xeon CPU. This is my development
server and actually changes configuration about twice a year. It currently runs CentOS
Linux 8.2. This machine also hosts my test Db2 environment.
The third machine is my Windows 10 workstation. It is connected to the first Linux
system via a shared drive (Samba) on the server. This is where I do most of my writing as
well as Windows development and testing.

9
© W. David Ashley 2021
W. D. Ashley, Foundation Db2 and Python, https://doi.org/10.1007/978-1-4842-6942-8_2
Chapter 2 Installing Db2

The fourth system is a Lenovo ThinkCentre M920 with 256 GB of SSD and a 1 TB
drive with 16 GB of memory. It has an i7 CPU. This is my development workstation
where I test all my Linux development and remote access to servers. The operating
system is Fedora 32.
The fifth system is a Lenovo ThinkPad T580 with 256 GB of SSD, 16 GB of memory,
and an i7 CPU. It runs Fedora 32 and usually serves as my travel machine but also as an
auxiliary test device.

I nstallation Prerequisites
Before you even start the Db2 install program, there are a number of prerequisites that
need to be met before you can successfully install everything. Our install environment
for this book is CentOS 8.2. The prerequisites for this OS should be the same for RHEL
8.2, but may be different for other Linux environments. Windows environments have
their own prerequisites, but they are similar to the Linux prerequisites.
The first thing we need is the Db2 install program and support files. To get the free
version of Db2, just go to

www.ibm.com/account/reg/us-en/signup?formid=urx-33669

This gets you to the account registration page. You can either log in with an existing
userid or create a new one. After you are logged in, the website will present you a
preferences page. Select your preferences and select the Continue button. On the
next web page, select the download you need. Unless you need them, just ignore the
pureScale support downloads. Once the download is complete, move the downloaded
file to a safe location and then unzip or untar it. This will create a new subdirectory in the
current directory with the install files exploded inside.

Caution! Do not move the downloaded file to the directory you intend to place
databases. You will have a mess of files on your hands when you create your first
database.

At the time this book was written, the version of Db2 that was available was version
11.5.4. Older free versions of Db2 are not made available when IBM introduces a new
version.

10
Chapter 2 Installing Db2

Now that you have your evaluation version of Db2, you are probably wondering what
its limitations are. The evaluation version does not ever expire. It has no limitation on
the number of databases. The one and only limitation is the total size of all databases,
currently limited to 100 GB. This is more than enough space to perform your own
evaluation of the software unless you are trying to test a very large system. If that is your
plan, IBM will be more than glad to help with a production version of Db2 and even
some engineers.
At this point, we are now ready to find out what our prerequisites are. To do this,
simply run the install program. This program is located in the untarred subdirectory
we previously created. The expanded directory is named server_dec. To run the install
program, just run the following commands:

$ cd server_dec
$ ./db2setup

If prerequisites are needed by Db2, the install program will list them and then exit.
Be sure to read everything output by the install program. On our CentOS 8.2 system, it
listed two prerequisites:

• libpam.so* (32-bit)

• libstdc++.so.6 (32-bit)

“Wait. Why does Db2 need 32-bit libraries?” you ask. Db2 is a collection of a bunch
of products, some of which have not changed in a decade or more. Rather than possibly
introducing new bugs into the system, IBM has chosen to keep the older version of
some of these products. Thus, these prerequisite libraries are needed to support those
products.
Use your system’s software installer to install the prerequisite packages. For Linux,
this will be either the dnf or yum programs for RPM-based packages. Once you have the
prerequisites installed, you are ready to proceed to really installing Db2. But before we
do that, we need to do a little planning.

Planning the Db2 Install


Before we get to the install, we need to understand what the result of the install will be so
we can plan ahead and avoid surprises afterward. There are two major points to cover in
this area.

11
Chapter 2 Installing Db2

The first result of the install is that you will have two new userids created on the
target machine. The default names of these IDs are db2inst1 and db2fenc1. The
db2inst1 ID will have some files stored in its home directory, and you need to make
sure there is enough space to accommodate them. There are a limited number of files,
but you should make sure you are prepared for them. The db2fenc1 ID only has a very
limited number of files stored in its home directory.
The second result is not really a result of the install. It is more a default that is set
as a result of the install. This item is the location where databases will be installed. The
default location for databases is in the db2inst1 home directory! THIS IS NOT WHERE
YOU WANT TO STORE DATABASES! You are probably going to store them on a different
drive/location. We will discuss this point again after we cover the install process and
before we create the sample database.
There are also a few minor points that are a result of the install, but we will cover
those as we get to them.

I nstalling Db2
We are now ready to install Db2. This process must be done by the root (on Linux)
or admin (on Windows) user, so start by becoming the root/admin user. On Windows
you will need to log out and log back in as the admin user. On Linux just perform the
following command:

$ su - root

After this you need to change to the directory where you placed the expanded files of
the Db2 download package. Then run the db2setup install package:

$ cd server_dec
$ ./db2setup

If you have installed all the prerequisites, this should show you the Welcome page
(Figure 2-1).

12
Chapter 2 Installing Db2

Figure 2-1. Db2 Install Welcome Page


After you click the New Install button, the next window appears to allow you to select
a product to install (Figure 2-2).

Figure 2-2. Db2 Install Choose a Product Page


13
Chapter 2 Installing Db2

This page has a number of products that you can select. The first product is Db2
Server, and this is the product we will install. The second product is Db2 with pureScale,
which we did not download. The third product is Db2 Connect Server, which is used
for distributed databases. The fourth product is Db2 Connect Client, which is used for
building compiled code that includes SQL statements. The last product is Db2 Runtime
Client, which is used for running compiled code from the Db2 Connect Client version.
At this point you should select the top item in the list, Db2 Server Editions. The
version number may be different if you downloaded a newer version of Db2. The other
selections are not important at this point in time. After clicking the Next button, the next
page will appear.

Figure 2-3. Db2 Install Configuration Page

14
Chapter 2 Installing Db2

The Configuration page allows you to select either a Typical or a Custom install. At
this point, select a Typical install. You must also check the box to agree to the IBM terms
before you proceed. When finished, click the Next button and the next page shown in
Figure 2-4 will appear.

Figure 2-4. Db2 Install Instance Owner Page

You can check out the Custom install option for some items you may want to change.
Most users just perform a Typical install.
The Instance Owner page allows you to create the account that will own the first
instance of Db2 and the group name of the new user. Just leave the db2inst1 information
as it appears and then enter the password and confirmation for the new account. This
is the account that will have new files installed in its home directory. When you have
entered in the new password and confirmed it for the account, click Next and the page
shown in Figure 2-5 will be displayed.

15
Chapter 2 Installing Db2

Figure 2-5. Db2 Install Fenced User Page

The db2fenc1 user will run user-defined functions and stored procedures outside the
address space of the Db2 database. Enter the db2fenc1 password and confirm it. When
finished, click Next which will dosplay the page in Figure 2-6.

16
Chapter 2 Installing Db2

Figure 2-6. Db2 Install Response File and Summary Page

The next page is the Response File and Summary page. The response file is a part of
the installation set of files, so it does not have to be created. Click the Finish button to
start the install of Db2 as shown in Figure 2-7.

17
Chapter 2 Installing Db2

Figure 2-7. Db2 Install Progress Page


The two status bars keep track of the progress of the installation of all components.
When finished, you will automatically be taken to next page (Figure 2-8).

Figure 2-8. Db2 Install Finished Page


18
Chapter 2 Installing Db2

When the installation is complete, this is the page that will be shown. You can choose
to review the post-install steps, review the log file, or just click the Finish button to exit
the install.
At this point, the Db2 installation steps are complete, and we are ready to look at the
post-install tasks that will need to be considered.

Note With Ubuntu Linux, the Db2 instance owner and fenced user that are
created by the Db2 install are assigned the Dash shell by default. This can cause
scripts that begin with the line #!/bin/bash to stop working. If you want to use Bash
as the default shell when you log into either of these users, execute the command
csh -s /bin/bash username (where username is the name of the Db2 instance
owner or fenced user) before doing anything else.

Db2 Post-install Tasks


There are a few tasks that need to be performed after the Db2 install has completed:

1. Try to log into the db2fenc1 userid using the password you set
from the db2setup command. Correct any problems you may find.

2. Try to log into the db2inst1 userid using the password you set
from the db2setup command. Correct any problems you may
find. You should note the location of the sqllib directory and its
contents as you may need to become familiar with them. This may
or may not be a link to another location.

3. If you do not want databases stored in the db2inst1 directory


tree, then now is the time to change that location. Log in as the
db2inst1 userid and run the following command:

$ db2 update dbm cfg using dftdbpath /your/db/path

This will update the path in the Db2 configuration so that all databases belonging to
db2inst1 will be stored in the new location.
At this point, we are now finished with our post-install tasks, and we are ready to
proceed to installing the sample database.

19
Chapter 2 Installing Db2

Installing the Db2 Sample Database


Db2 comes with a default database named sample. This database, although small, is
comprehensive enough to show how a database should be constructed and is useful for
demonstrating an array of possible SQL commands. This book uses the sample database
extensively for demonstrating Db2 concepts, SQL usage, and Python programming
examples.
To install the sample database, follow these steps.
Log into the db2inst1 userid:

$ su - db2inst1

The Db2 database instance needs to be started, so that is our next step:

$ db2start

Now we can actually install the sample database. This command will take a few
minutes, so be patient:

$ db2sampl -force -sql

The -force option ensures that if the database is already installed, it will be overlaid
with the default content. The -sql option tells Db2 not to install the XML data into the
database.
Now we can connect to the database and test it:

$ db2 connect to sample

If successful, you should see some output that looks something like this:

  Database Connection Information

Database server        = DB2/LINUXX8664 11.5.0.0


SQL authorization ID   = DB2INST1
Local database alias   = SAMPLE

Now we can run a test SQL command to query the database:

$ db2 "select * from department"

20
Chapter 2 Installing Db2

Important Be sure to include quotes around the text that follows db2. If the
quotes are omitted, the operating system will try to process the command
incorrectly, and an error will result.

You should see a total of 14 records displayed if everything works as expected. We


can now terminate our connection to the database with the following command:

$ db2 connect reset

If successful, our connection to the database is now terminated.

Summary
This chapter has presented the steps to installing and verifying the installation of Db2.
Be sure to read the Caution, Note, and Important sections presented in the chapter as
they have valuable information for some operating systems.

21
CHAPTER 3

Db2 Management
The management of Db2 is not an easy affair. It is not like any open source relational
database. It is a little like Oracle, but there are differences. This is because Db2 for Linux,
Unix, and Windows is a lot like maintaining a mainframe database, just on a smaller and
easier scale. While there are many tools to help manage the Db2 environment contained
in the product itself, the key to proper management is understanding the architecture
of the product and how it manages hardware resources. Without this knowledge, it
is easy to get into trouble and overextend the hardware of the machine. With proper
management, a single piece of hardware can manage either a few large databases or
many smaller ones without stretching the resources on the machine too far.
This chapter will give you enough knowledge so that you can set up the Db2
environment properly without overburdening you with facts that have few, if any,
consequences.

D
 b2 Instances
Instances are the top-level architectural structure in Db2. When you installed Db2, you
created the first Db2 Instance, which had the default name of db2inst1. This is also the
Instance that holds the sample database we installed in the previous chapter.
Any number of databases can be installed in an Instance. But it is possible to
overload an Instance and cause performance problems. This is because Db2 sets aside
a fixed number of processes and threads for each Instance, and it does not dynamically
add or remove resources during the active lifetime of an Instance. You must stop the
instance, adjust the number of resources, and then restart the Instance. Of course, the
databases owned by the Instance will have to be stopped and restarted as well. That
is the key: stopping and starting an Instance can have impacts on availability and the
contained databases. If you are continually stopping and restarting Instances, your
users will not be very happy with your management skills.

23
© W. David Ashley 2021
W. D. Ashley, Foundation Db2 and Python, https://doi.org/10.1007/978-1-4842-6942-8_3
Chapter 3 Db2 Management

Instances are easy to describe, but harder to justify. You have to know some history
to be able to properly understand where they came from as well as why they even exist.
Instances were first introduced just after the year 2000. Their justification came as the
databases on multi-drive machines started to become very large. They were so large
and had so many users that the network interface became a bottleneck in processing
database requests. It seems that the machines now far outpaced the network in being
able to handle database requests. Db2 had plenty of idle time while it waited on the
network interface to process the next request. This was in the days when the fastest
common networks were only 10 MB capacity. What was needed was a way to divide the
databases among multiple network ports. Thus, instances were born.
Instances were not only given their own network port, they were also given their
own processes, threads, and semaphores. Thus, if a database crashed for any reason, it
would only disrupt the databases within the containing Instance. The other Instances
and databases would continue to run normally while the database administrator dealt
with the downed Instance.
Instances can be used in many ways by the database administrator, but the most
common use is to prevent network port congestion. The second most common use is to
separate sets of databases from each other for security purposes. Since each Instance
has its own set of administrators and users, this helps to enforce security between
Instances.
One other attribute of an instance is that it has no physical presence on your disk
system, or at least not much of one. It is very hard to point to a place in the disk system
and say, “This is where an instance resides.” There are a few files created with the
instance, but these do not describe where the instance is. You should just think of it as
a logical entity and not a physical one.
There is a set of commands that administrators can use to manage instances. The
following are some example Db2 commands that manage Instances.

Note All the commands used in this chapter can be run in one of two ways. They
can be run by logging into the db2inst1 user, or they can be run by using the
sudo db2inst1 prefix to the command.

24
Chapter 3 Db2 Management

db2ilist
This command lists all the Instances that are available on a system:

db2ilist

Output:

db2inst1
db2inst2
db2inst3

Instance Environment Commands


These commands are useful to work with arrangement of instances in the Db2 CLI.
The following command obtains the current instance:

db2 get instance

Output:

The current database manager instance is : db2inst1

To start or stop the database manager of an instance on Db2 UDB, the following
command is executed for the current instance:

set db2instance=db2inst1

Using this command, you can start an Instance. Before this, you need to run “set
instance”:

db2start

Output:

SQL1063N DB2START processing was successful

This command is used to stop the current Instance:

db2stop

Output:

SQL1064N DB2STOP processing was successful.

25
Chapter 3 Db2 Management

Creating an Instance
Let us see how to create a new Instance.
If you want to create a new Instance, you need to log in with root. An Instance ID is
not a root ID or a root name.
Here are the steps to create a new Instance:
Step 1: Create an operating system user for an Instance.

useradd -u <ID> -g <group name> -m -d <user location> <user name> -p <password>

Example:

useradd -u 1000 -g db2iadm1 -m -d /home/db2inst2 db2inst2 -p db2inst2

Step 2: Go to the Db2 Instance directory as a root user to create a new Instance.
Location:

cd /opt/ibm/db2/v10.1/instance

Step 3: Create an instance using the following syntax.

./db2icrt -s ese -u <inst id> <instance name>

Example:

./db2icrt -s ese -u db2inst2 db2inst2

Output:

DBI1446I The db2icrt command is running, please wait.


....
.....
DBI1070I Program db2icrt completed successfully.

Arranging a Communication Port and Host for an Instance


Edit the /etc/services file and add the port number. In the following syntax, “inst_name”
indicates the Instance name, and “inst_port” indicates the port number of the
Instance:

db2c_<inst name> <inst_port>/tcp

26
Chapter 3 Db2 Management

Example:

sudo - db2c_db2inst2 50001/tcp

Syntax 1: Update configuration with the service name. In the following syntax,
“svcename” indicates the Instance service name, and “inst_name” indicates the
Instance name.

db2 update database manager configuration using svcename db2c_&<inst_name>

Example 1: Updating DBM configuration with variable svcename with value “db2c_
db2inst2” for Instance “db2inst2”

db2 update database manager configuration using svcename db2c_db2inst2

Output,:

DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed


successfully.

Syntax 2: Set the “tcpip” communication protocol for the current Instance.

db2set DB2COMM=tcpip

Syntax 3: Stop and start the current Instance to get updated values from database
manager configuration.

db2stop
db2start

Updating an Instance
You can update an instance using the following command,:

db2iupdt

This command is used to update the Instance within the same version release.
Before executing this command, you need to stop the Instance database manager using
the “db2stop” command. The following syntax “inst_name” indicates the previously
released or installed Db2 server Instance name, which you want to update to a newly
released or installed Db2 server version.

27
Chapter 3 Db2 Management

Syntax 1: To update an instance in normal mode

db2iupdt <inst_name>

Example:

./db2iupdt db2inst2

Syntax 2: To update an Instance in debugging mode

db2iupdt -D <inst_name>

Example:

db2iupdt -D db2inst2

Upgrading an Instance
You can upgrade an instance from a previous version of a Db2 copy to a newly installed
version of a Db2 copy:

db2iupgrade

On a Linux or UNIX system, this command is located in the DB2DIR/instance


directory. In the following syntax, “inst_name” indicates the previous version of the Db2
Instance, and “inst_username” indicates the currently installed version of a Db2 copy
for the Instance user:

db2iupgrade -d -k -u <inst_username> <inst_name>

Example:

db2iupgrade -d -k -u db2inst2 db2inst2

Command parameters:

-d : Turns debugging mode on

-k : Keeps the pre-upgrade Instance type if it is supported in the


Db2 copy, from which you are running this command

If you are using the super user (su) on Linux for the db2iupgrade command, you
must issue the “su” command with the “-” option.

28
Chapter 3 Db2 Management

Dropping an Instance
You can drop or delete an instance, which was created by the “db2icrt” command:

db2idrop

On Linux and UNIX operating systems, this command is located in the DB2_
installation_folder/instance directory.
Syntax:

db2idrop -u <inst_username> <inst_name>

Example:

./db2idrop -u db2inst2 db2inst2

Using Other Commands with an Instance


The following is the command to find out which Db2 instance we are working on now.
Syntax 1:

db2 get instance

Output:

The current database manager instance is:  db2inst1

Syntax 2:

db2pd -inst | head -2

Example:

db2pd -inst | head -2

Output:

Instance db2inst1 uses 64 bits and DB2 code release SQL10010

Syntax 3:

db2 select inst_name from sysibmadm.env_inst_info

29
Chapter 3 Db2 Management

Example:

db2 select inst_name from sysibmadm.env_inst_info

Output:

INST_NAME  --------------------------------------
db2inst1
1 record(s) selected.

Syntax 4:

db2set db2instdef=<inst_name> -g

Example:

db2set db2instdef=db2inst2 -g

Databases
Databases are the next level of manageable objects in Db2. Every database is contained
inside of a single Instance, but there can be multiple databases contained inside an
Instance.
The database has no communications interface to the outside world. Instead,
the Instance controls communications between each contained database and the
outside world. This reduces the redundancy of the communication code when multiple
databases are owned by the Instance.
A database contains a large group of objects that together make up both the
administration and the storage locations for the database. A partial list of these objects is
as follows:

• The database catalogs

• The global deadlock files

• Tablespace information

• Storage group control files

• Temporary tablespaces

• Global configuration file

30
Chapter 3 Db2 Management

• History files

• Logging files

• Automated storage containers

Each one of these objects will be discussed at length in the following sections and in
Chapter 4 later in this book.

Db2 Catalog Views


The Db2 catalog tables are used to hold information about all the database tables, views,
indexes, and other entities contained in the database. Each database contains its own
catalog tables, and they are not shared with any other database.
The catalog tables are extremely important and should only be updated by the Db2
system. To that end, you can no longer even read the catalog tables. Instead, the system
creates a read-only view of each table. To read a catalog table, you must use the view; you
cannot read the catalog tables directly.
The current 11.x release of Db2 contains 140 catalog views plus 9 other views
containing statistical information. Many of these views contain very useful information
for both administrators and advanced users. Thus, the catalog views are read-only for
everyone who has control privileges to that portion of the database. For instance, if a
user has no read permissions on a database table, information on that table will not be
available to the user in catalog views.
For more detailed information on catalog views, see the IBM documentation at

www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.
doc/doc/r0008443.html

This documentation details the complete layout of each view with additional
information about all possible values for many columns.

Locking Event Monitor


New in Db2 11 is the locking event monitor. This replaces the deprecated deadlock
event monitor. The old monitor had many deficiencies, which caused some deadlocks
to not be detected. The new logging event monitor is much better at detecting deadlocks
as they occur instead of waiting for some kind of deadlock timeout. It provides a more
robust system to users and administrators.
31
Chapter 3 Db2 Management

Deadlock information can be written to two different database tables, but it is always
in binary format. Choosing between these two tables can be tricky, so careful thought
should be given to your choice. By using SQL to query the table, the system will interpret
the binary data and translate to a supported language such as English.
Enabling the locking event monitor is automatic when you execute the CREATE
statement for it. The following statement will enable the locking event monitor:

create event monitor for locking

When a deadlock is detected, the following information is collected in the event log:

• The lock that resulted in the event

• The application holding the lock that resulted in the lock event

• The applications that were waiting for or requesting the lock that
resulted in the lock event

• What the applications were doing during the lock event

T ablespace Information
Tablespaces are used to contain database tables. When a database is created, three
tablespaces are created automatically. The first tablespace, SYSCATSPACE, contains the
database catalog and views. The second tablespace, USERSPACE1, is the default space
used to hold the database tables. The third, TEMPSPACE1, is used to hold temporary
tables for query results. All these tablespaces are created by default in the location
specified when the Db2 system was installed.
There is a lot of information on tablespaces, and this book has an entire chapter
devoted to that topic. See Chapter 4 for more information.
The basic command for obtaining tablespace information is as follows:

mon_get_tablespace (tblsp_name, member)

If the tblsp_name is NULL or an empty string, then all tablespaces will be returned.
The member specifies the member number of the tablespace. If it is –1, the current
member information is returned. If it is –2, then all member information is returned. If
NULL is specified, it is the same as specifying –1.

32
Chapter 3 Db2 Management

Storage Group Control Files


Storage groups are an intermediate level between the database and its tablespaces. You
use storage groups to group together tablespaces. This allows a whole set of tablespaces
to reside in the same location. A database can have many storage groups spread across
any number of disk devices.
Unless you specify otherwise, a default storage group is created when you create a
database. All of the tablespaces will reside in that storage group. See Chapter 4 for more
information.

Global Configuration File


The global configuration file is created by an administrator. It is used to set backup
procedures for the Db2 system. See the IBM documentation for more information.

H
 istory Files
History files are instance specific and are stored in the same place as the instance
information. They contain some global information on the instance like the last start and
stop times and other sometimes useful data. The number of these files can change from
release to release, so refer to your release-specific documentation for more information.

L ogging Files
The logging files are specific to a database and store information logged by the Db2
system. The number and types of the files will be specific to your database configuration.

Automated Storage Containers


These are discussed at length in Chapter 4. A default storage container is created when a
database is created.

33
Another Random Scribd Document
with Unrelated Content
"He said it was all over the village that you were going to marry
him."
"I—I didn't think it had got round so soon," said the widow,
nervously.
"So soon! Why, you don't mean to say there's anything in it,
mother?" said Frank, impetuously.
"I hope it won't displease you very much, Frank," said Mrs. Hunter,
in embarrassment.
"Is it true? Are you really going to marry that man?"
"He didn't ask me till this afternoon, and, of course, it took me by
surprise, and I said so, but he urged me so much that I finally
consented."
"You don't love him, mother? I am sure you can't love such a man as
that."
"I never shall love any one again in that way, Frank—never any one
like your poor father."
"Then why do you marry him?"
"He doesn't ask me to love him. But he can relieve me of a great
many cares and look after you."
"I don't want anybody to look after me, mother—that is, anybody
but you. I hate Mr. Craven!"
"Now that is wrong, Frank. He speaks very kindly of you—very kindly
indeed. He says he takes a great interest in you."
"I am sorry I cannot return the interest he professes. I dislike him,
and I always have. I hope you won't be angry, mother, if I tell you
just what I think of him. I think he's after your property, and that is
what made him offer himself. He is poor as poverty, though I don't
care half so much for that as I do for other things."
"No, Frank; you are mistaken there," said credulous Mrs. Hunter,
eagerly. "He is not poor."
"How do you know?"
"He told me that he had twenty thousand dollars' worth of mining
stock out West somewhere, besides owning a house in New York."
Frank looked astonished.
"If he has as much property as that," he said, "I don't see what
makes him come here. I don't believe his business brings him in
three hundred dollars a year."
"That's the very reason, Frank. He has money enough, and doesn't
mind if business is dull. He generously offered to pay—or was it help
pay?—the expenses of your education; but I told him that you didn't
need it."
"If I did, I wouldn't take it from him. But what you tell me surprises
me, mother. He doesn't look as if he was worth five hundred dollars
in the world. What made him tell you all this?"
"He said that some people would accuse him of being a fortune-
hunter, and he wanted to convince me that he was not one."
"It may be a true story, and it may not," said Frank.
"You are really very unjust, Frank," said his mother. "I don't pretend
to love Mr. Craven, and he doesn't expect it, but I am sure he has
been very kind, and he takes a great deal of interest in you, and you
will learn to know him better."
"When you are married to him?"
"Yes."
"Mother," exclaimed Frank, impetuously, "don't marry this man! Let
us live alone, as we have done. We don't want any third person to
come in, no matter who he is. I'll take care of you."
"You are only a boy, Frank."
"But I am already fifteen. I shall soon be a man at any rate, and I
am sure we can get along as well as we have done."
Mrs. Hunter was not a strong or a resolute woman, but even women
of her type can be obstinate at times. She had convinced herself,
chiefly through Mr. Craven's suggestion, that the step she was about
to take was for Frank's interest, and the thought pleased her that
she was sacrificing herself for him. The fact that she didn't fancy Mr.
Craven, of course heightened the sacrifice, and so Frank found her
far more difficult of persuasion than he anticipated. She considered
that he was but a boy and did not understand his own interests, but
would realize in future the wisdom of her conduct.
"I have given my promise, Frank," she said.
"But you can recall it."
"It would not be right. My dear Frank, why can you not see this
matter as I do? I marry for your sake."
"Then, mother, I have the right to ask you not to do it. It will make
me unhappy."
"Frank, you do not know what is best. You are too young."
"Then you are quite determined, mother?" asked Frank, sadly.
"I cannot draw back now, Frank. I—I hope you won't make me
unhappy by opposing it."
"I won't say another word, mother, since you have made up your
mind," said Frank, slowly. "When is it going to be?"
"I do not know yet. Mr. Craven wants it to be soon."
"You will let me know when it is decided, mother?"
"Certainly, Frank."
He left the room sad at heart. He felt that for him home would soon
lose its charms, and that he would never get over the repugnance
which he felt against his future step-father.
CHAPTER IV.
MR. CRAVEN'S FOUR-LEGGED ENEMY.

Mr. Craven sought his office in a self-complacent mood.


"By Jove!" he said to himself, "I'm in luck. It's lucky I thought to tell
her that I was rich. I wish somebody would come along and buy that
Lake Superior mining stock at five cents on a dollar," he soliloquized,
laughing softly; "and if he'd be good enough to let me know
whereabouts that house in New York is, I should feel very much
obliged. However, she believes it, and that's enough. No, on the
whole, it isn't quite enough, for I must have some ready money to
buy a wedding suit, as well as to pay for my wedding tour. I can't
very well call upon Mrs. Craven that is to be for that. Once married,
I'm all right."
The result of these cogitations was that having first secured Mrs.
Hunter's consent to a marriage at the end of two months, he went
to New York to see how he could solve the financial problem.
He went straightway to a dingy room in Nassau Street, occupied by
an old man as shabby as the apartment he occupied. Yet this old
man was a capitalist, who had for thirty years lent money at
usurious interest, taking advantage of a tight money market and the
needs of embarrassed men, and there are always plenty of the latter
class in a great city like New York. In this way he had accumulated a
large fortune, without altering his style of living. He slept in a small
room connected with his office, and took his meals at some one of
the cheap restaurants in the neighborhood. He was an old man, of
nearly seventy, with bent form, long white beard, face seamed with
wrinkles, and thick, bushy eyebrows, beneath which peered a pair of
sharp, keen eyes. Such was Job Green, the money-lender.
"Good morning," said Mr. Craven, entering his office.
"Good morning, Mr. Craven," answered the old man. He had not met
his visitor for a long time, but he seldom forgot a face. "I haven't
seen you for years."
"No, I'm living in the country now."
"In the country?"
"Yes, in the town of Shelby, fifty miles from the city."
"Aha! you have retired on a fortune?" inquired the old man,
waggishly.
"Not yet, but I shall soon, I hope."
"Indeed!" returned Job, lifting his eyebrows as he emphasized the
word. "Then you find business better in the country than in the
city?"
"Business doesn't amount to much."
"Then how will you retire on the fortune, Mr. Craven? I really should
like to know. Perhaps I might move out there myself."
"I don't think, Mr. Green," said Craven, with his soft smile, "you
would take the same course to step into a fortune."
"And why not?" inquired the old man, innocently.
"Because I am to marry a rich widow," said Mr. Craven.
"Aha! that is very good," said Job, laughing. "Marrying isn't exactly
in my line, to be sure. Who is the lucky woman?"
"I will tell you, Mr. Green, for I want you to help me in the matter."
"How can I help you? You don't want money if you are going to
marry a fortune," said Job, beginning to be suspicious that this was
a story trumped up to deceive him.
"Yes, I do, and I will tell you why. She thinks I am rich."
"And marries you for your money? Aha! that is very good," and the
man laughed.
"I told her I owned twenty thousand dollars' worth of stock in a Lake
Superior mine."
"Very good."
"And a fifteen-thousand-dollar house in this city."
"Oh, you droll dog! You'll kill me with laughing, Mr. Craven; I shall
certainly choke," and old Job, struck with the drollness of regarding
the man before him as a capitalist, laughed till he was seized with a
coughing spell.
"Well, well, Craven, you're a genius," said Job, recovering himself.
"You wouldn't—ha! ha!—like to have me advance you a few
thousand on the mines, would you now, or take a mortgage on the
house?"
"Yes, I would."
"I'll give you a check on the bank of Patagonia, shall I?"
"I see you will have your joke, Mr. Green. But I do want some
money, and I'll tell you why. You see I am to be married in two
months, and I must have a new suit of clothes, and go on a wedding
tour. That'll cost me two or three hundred dollars."
"Ask Mrs. Craven for the money."
"I would, if she were Mrs. Craven, but it won't do to undeceive her
too soon."
"You don't expect me to furnish the money, Craven, do you?"
"Yes, I do."
"What security have you to offer?"
"The security of my marriage."
"Are you sure there is to be a marriage?" demanded Job, keenly.
"Tell me, now, is the rich widow a humbug to swindle me out of my
money? Aha! Craven, I have you."
"No, you haven't, Mr. Green," said Craven, earnestly. "It's a real
thing; it's a Mrs. Hunter of Shelby; her husband died two years ago."
"How much money has she got?"
"Sixty thousand dollars."
"What, in her own right?"
"Why, there's a son—a boy of fifteen," said Mr. Craven, reluctantly.
"Aha! Well how much has he got of this money?"
"I'll tell you the plain truth, Mr. Green. He is to have two-thirds when
he comes of age. His mother has the balance, and enjoys the
income of the whole, of course providing for him till that time."
"That's good," said Job, thoughtfully.
"Of course, what she has I shall have," added Craven. "To tell the
truth," he continued, smiling softly, "I shan't spoil the young
gentleman by indulgence when he is my step-son. I shan't waste
much of his income on him."
"Perhaps the mother will raise a fuss," suggested Job.
"No, she won't. She's a weak, yielding woman. I can turn her round
my finger."
"Well, what do you want then?"
"I want three hundred and fifty dollars for ninety days."
"And suppose I let you have it?"
"I will pay you five hundred. That will allow fifty dollars a month for
the loan."
"But you see, Craven, she might give you the slip. There's a risk
about it."
"Come to Shelby yourself, and make all the inquiries you see fit.
Then you will see that I have spoken the truth, and there is no risk
at all."
"Well, well, perhaps I will. If all is right, I may let you have the
money."
Two days afterward the old man came to Shelby, stipulating that his
traveling expenses should be paid by Craven. He inquired around
cautiously, and was convinced that the story was correct. Finally he
agreed to lend the money, but drove a harder bargain than first
proposed—exacting six hundred dollars in return for his loan of three
hundred and fifty. It was outrageous, of course, but he knew how
important it was to Mr. Craven, and that he must consent.
Frank, according to his determination, said not a word further to his
mother about the marriage. He avoided mentioning Mr. Craven's
name even. But an incident about this time, though Frank was quite
innocent in the matter, served to increase Mr. Craven's dislike for
him.
He had spent the evening with Mrs. Hunter, and was about to leave
the house when a watch-dog, which Frank had just purchased,
sprang upon him, and, seizing him by the coat-tails, shook him
fiercely.
Mr. Craven disliked dogs, and was thoroughly frightened. He gave a
loud shriek, and tried to escape, but the dog held on grimly.
"Help, help!" he shrieked, at the top of his voice.
Frank heard the cry from the house, and ran out.
At this juncture he managed to break away from the dog, and made
a rush for the garden wall.
"Down, Pompey! Ain't you ashamed of yourself?" said Frank, sternly,
seizing the dog by the collar.
"I am very sorry, Mr. Craven," he added.
Mr. Craven turned wild with rage, and his soft voice trembled as he
said:
"Really, Frank, it is hardly fair to your visitors to keep such a fierce
animal about."
"He didn't know you, sir. To-morrow I will make you acquainted, and
then there will be no danger of this occurring again."
"I really hope not," said Craven, laughing rather discordantly.
"I hope he hasn't bitten you, sir."
"No, but he has torn my coat badly. However, it's of no consequence.
Accidents will happen."
"He takes it very well," thought Frank, as Mr. Craven said good-
night. But it was by a strong effort that his future step-father had
done so.
"Curse the dog!" he said to himself, with suppressed passion. "After
I am married and fairly settled down, I will shoot him. Thus I will
spite the boy and revenge myself on the brute at the same time."
CHAPTER V.
MR. CRAVEN'S RETURN.

Mr. Craven called the next day, as usual. Frank apologized again for
Pompey's rude treatment of the evening previous, and, as far as he
could, established friendly relations between the parties. Pompey,
who had nothing vicious about him, and was only anxious to do his
duty, looked meek and contrite, and Mr. Craven, to all appearance,
had quite forgiven him.
"Good dog!" he exclaimed, patting Pompey's head. "Say no more
about it, Frank," he said, in his usual soft voice; "it was only an
accident. I foresee that Pompey and I will be excellent friends in
future."
"I hope your coat isn't much torn, sir."
"It can easily be repaired. It isn't worth mentioning. Is your mother
at home."
"Yes, sir. Walk in."
"He behaves very well about it," thought Frank. "He may be a better
man than I thought. I wish I could like him, as he is to be my step-
father; but I think there are some persons it is impossible to like."
So the time passed, and the wedding-day drew near. Frank did not
consider it honorable to make any further objection to the marriage,
though he often sighed as he thought of the stranger who was
about to be introduced into their small circle.
"Mother will seem different to me when she is that man's wife," he
said to himself. "I shall love her as much, but she won't seem to
belong to me as much as she did."
In due time the wedding was celebrated. Mrs. Hunter wished it to be
quiet, and Mr. Craven interposed no objection. Quiet or not, he felt
that the substantial advantages of the union would be his all the
same. Mrs. Hunter looked a little nervous during the ceremony, but
Mr. Craven was smiling and suave as ever. When he kissed his wife,
saluting her as Mrs. Craven, she shuddered a little, and with
difficulty restrained her tears, for it reminded her of her first
marriage, so different from this, in which she wedded a man to
whom she was devoted in heart and soul.
The ceremony took place at eleven o'clock, and the newly-wedded
pair started on a tour as previously arranged. So for two weeks
Frank and Katy O'Grady were left alone in the house. Katy was a
privileged character, having been in the family ever since Frank was
a baby, and she had no hesitation in declaring her opinion of Mr.
Craven.
"What possessed the mistress to marry such a mane specimen of a
man, I can't tell," she said.
"I don't like him myself," said Frank; "but we must remember that
he's my mother's husband now, and make the best of him."
"And a mighty poor best it will be," said Katy.
"There you go again, Katy!"
"I can't help it, shure. It vexes me intirely that my dear mistress
should throw herself away on such a man."
"What can't be cured must be endured, you know. You mustn't talk
that way after Mr. Craven comes back."
"And what for will I not. Do you think I'm afraid of him?" asked Katy,
defiantly. "If he is a man, I could bate him in a square fight."
"I don't know but you could, Katy," said Frank, glancing at the
muscular arms and powerful frame of the handmaiden; "but I really
hope you won't get into a fight," he added, smiling. "It wouldn't look
well, you know."
"Then he'd better not interfare wid me," said Katy, shaking her head.
"You must remember that he will be master of the house, Katy."
"But he sha'n't be master of Katy O'Grady," said that lady, in a very
decided tone.
"I don't suppose you'll have much to do with him," said Frank.
He sympathized with Katy more than he was willing to acknowledge,
and wondered how far Mr. Craven would see fit to exercise the
authority of a step-father. He meant to treat him with the respect
due to his mother's husband, but to regard him as a father was very
repugnant to him. But he must be guided by circumstances, and he
earnestly hoped that he would be able to live peacefully and
harmoniously with Mr. Craven.
Days passed, and at length Frank received a dispatch, announcing
the return home.
"They will be home to-night, Katy," he said.
"I'll be glad to see your mother, shure," said Katy, "but I wish that
man wasn't comin' wid her."
"But we know he is, and we must treat him with respect."
"I don't feel no respect for him."
"You must not show your feelings, then, for my mother's sake."
At five o'clock the stage deposited Mr. and Mrs. Craven at the gate.
Frank ran to his mother, and was folded in her embrace. Then he
turned to Mr. Craven, who was standing by, with his usual smile,
showing his white teeth.
"I hope you have had a pleasant journey, sir," he said.
"Thank you, Frank, it has been very pleasant, but we are glad to get
home, are we not, my dear?"
"I am very glad," said Mrs. Craven, thankfully, and she spoke the
truth; for though Mr. Craven had been all attention (he had not yet
thought it prudent to show himself in his true colors), there being no
tie of affection between them, she had grown inexpressibly weary of
the soft voice and artificial smile of her new husband, and had
yearned for the companionship of Frank, and even her faithful
handmaiden, Katy O'Grady, who was standing on the lawn to
welcome her, and only waiting till Frank had finished his welcome.
"How do you do, Katy," said her mistress.
"I'm well, mum, thankin' you for askin', and I'm mighty glad to see
you back."
"I hope you are glad to see me also, Katy," said Mr. Craven, but his
soft voice and insinuating smile didn't melt the hostility of Miss
O'Grady.
"I'm glad you've brought the mistress home safe," she said, with a
low bow; "we've missed her from morning till night, sure; haven't
we, Master Frank?"
"I see she isn't my friend," thought Mr. Craven. "She'd better change
her tune, or she won't stay long in my house."
He had already begun to think of himself as the sole proprietor of
the establishment, and his wife as an unimportant appendage.
"I hope you have some supper for us, Katy," said he, not choosing at
present to betray his feelings, "for I am quite sure Mrs. Craven and
myself have a good appetite."
"Mrs. Craven!" repeated Katy, in pretended ignorance. "Oh, you
mean the mistress, sure."
"Of course I do," said Mr. Craven, with a frown, for once betraying
himself.
"Supper is all ready, ma'am," said Katy, turning to Mrs. Craven. "It'll
be ready as soon as you've took off your things."
When they sat down to the table, Frank made a little mistake. He
had always been accustomed to sit at the head of the table,
opposite his mother, and on the frequent occasions of Mr. Craven's
taking a meal there during the engagement, the latter had taken the
visitor's place at the side.
So to-night, without thinking of the latter's new relations to him,
Frank took his old place. Mr. Craven noticed it, and soft and
compliant as he was, he determined to assert his position at once. "I
believe that is my place," he said, with an unpleasant smile.
"Oh, I beg pardon," said Frank, his face flushing.
"You forgot, I suppose," said Mr. Craven, still smiling.
"Yes, sir."
"You'll soon get used to the change," said his step-father, as he
seated himself in the chair Frank had relinquished.
Mrs. Craven looked a little uncomfortable. She began to realize that
she had introduced a stranger into the family, and that this would
interfere to a considerable extent with their old pleasant way of
living.
No one seemed inclined to talk except Mr. Craven. He seemed
disposed to be sociable, and passed from one subject to another,
regardless of the brief answers he received.
"Well, Frank, and how have you got along since we were away?" he
asked.
"Very well, sir."
"And you haven't missed us then?"
"I have missed my mother, and should have missed you," he added
politely, "if you had been accustomed to live here."
"And how is Pompey?" asked Mr. Craven, again showing his teeth.
"The same as usual. I wonder he was not out on the lawn to receive
you and my mother."
"I hope he wouldn't receive me in the same way as he did once,"
said Mr. Craven, again displaying his teeth.
"No danger, sir. He didn't know you then."
"That's true, but I will take care that he knows me now," said Mr.
Craven, softly.
"I think he will remember you, sir; he is a good dog, and very
peaceable unless he thinks there are improper persons about."
"I hope he didn't think me an improper person," said Mr. Craven.
"No fear, sir."
Frank wondered why Mr. Craven should devote so much time to
Pompey, but he was destined to be enlightened very soon.
CHAPTER VI.
THE DIFFICULTY OF KILLING A DOG.

If Frank supposed that Mr. Craven had forgotten or forgiven


Pompey's attack upon him, he was mistaken. Within a week after Mr.
Craven had been established as a permanent member of the
household, Katy, looking out of the kitchen window, saw him
advancing stealthily to a corner of the back yard with a piece of raw
meat in his hand. He dropped it on the ground, and then, with a
stealthy look around, he withdrew hastily.
"What is he doin', sure?" said the astonished Katy to herself; then,
with a flash of intelligence, she exclaimed, "I know what he manes,
the dirty villain! The meat is p'isoned, and it's put there to kill the
dog. But he shan't do it, not if Katy O'Grady can prevint him."
The resolute handmaid rushed to the pantry, cut off a piece of the
meat meant for the morrow's breakfast, and carrying it out into the
yard, was able, unobserved by Mr. Craven, to substitute it for the
piece he had dropped. This she brought into the kitchen, and lifting
it to her nose, smelled it. It might have been Katy's imagination, but
she thought she detected an uncanny smell.
"It's p'isoned, sure!" she said. "I smell it plain; but it shan't harm
poor Pomp! I'll put it where it'll never do any harm."
She wrapped it in a paper, and carrying it out into the garden, dug a
hole in which she deposited it.
"Won't the ould villain be surprised when he sees the dog alive and
well to morrow morning?" she said to herself, with exultation.
Fifteen minutes later, Mr. Craven, from an upper window, had the
satisfaction of seeing the dog greedily eating what he supposed
would be his last meal on earth.
"That'll fix him!" he muttered, smiling viciously. "He won't attack me
again very soon. Young impudence will never know what hurt the
brute. That's the way I mean to dispose of my enemies."
Probably Mr. Craven did not mean exactly what might be inferred
from his remarks, but he certainly intended to revenge himself on all
who were unwise enough to oppose him.
Mr. Craven watched Pompey till he had consumed the last morsel of
the meat, and then retired from the window, little guessing that his
scheme had been detected and baffled.
The next morning he got up earlier than usual, on purpose to enjoy
the satisfaction of seeing his four-footed enemy stretched out stiff
and stark. What was his astonishment to see the dog jumping over a
stick at the command of his young master. Had he suddenly seen
Pompey's ghost (supposing dogs to have ghosts), he could scarcely
have been more astonished or dismayed.
"Goodness gracious! that dog must have a cast-iron constitution!" he
said to himself. "There was enough strychnine on that meat to kill
ten men. I don't understand it at all."
"He looks as if his grandmother had died and left him nothin' at all in
her will," said Katy to herself, slyly watching him out of the window.
"The ould villain's disappinted sure, and it's Katy O'Grady he's got to
thank for it, if he only knew it."
"Good morning, sir," said Frank, for the first time noticing the
presence of Mr. Craven.
"Good morning, Frank," replied his step-father, opening his mouth
with his customary smile. "Pompey seems lively this morning."
"Yes, sir. I am teaching him to jump over this stick."
"Good dog!" said Mr. Craven, patting him softly.
"Oh, the ould hypocrite!" ejaculated Katy, who had slyly opened the
window a trifle and heard what he said. "He tries to p'ison the poor
creeter, and thin calls him good dog."
Mr. Craven meanwhile was surveying Pompey curiously.
"I certainly saw him eat the meat," he said to himself, "and I am
sure it was tainted with a deadly poison. Yet here the dog is alive
and well, after devouring every morsel of it. It is certainly the most
curious case I ever heard of."
Mr. Craven went into the house, and turned to the article on
strychnine in an encyclopædia, but the statements he there found
corroborated his previously formed opinion as to the deadly
character and great strength of the poison. Pompey must certainly
be an extraordinary dog. Mr. Craven was puzzled.
Meanwhile Katy said to herself:
"Shall I tell Master Frank what Mr. Craven tried to do? Not yit. I'll
wait a bit, and while I'm waitin' I'll watch. He don't suspect that Katy
O'Grady's eyes are on him, the villain!"
It may not be considered suitable generally for a maid-of-all-work to
speak of her employer as a villain; but then Katy had some grounds
for her use of this term, and being a lady very decided in her
language, it is not singular that such should have been her practice.
Notwithstanding the apparent superiority of Pompey's constitution to
the deadliest poison, Mr. Craven's murderous intent was by no
means laid aside. He concluded to try another method of getting him
out of the way. He had a pistol in his trunk, and he resolved to see if
Pompey was bullet-proof as well as poison-proof.
Three days later, therefore, when Frank was at school, and Mrs.
Craven was in attendance at the house of a neighbor, at a meeting
of the village sewing-circle, Mr. Craven slipped the pistol into his
pocket and repaired to the back yard, where Pompey, as he
anticipated, was stretched out in the sun, having a comfortable nap.
"Pompey," said Mr. Craven, in a low tone, "come here. Good dog."
Pompey walked up, and, grateful for attention, began to fawn upon
the man who sought to lure him to death.
"Good dog! Fine fellow!" repeated Mr. Craven, stroking him.
Pompey seemed to be gratefully appreciative of the kindness.
Low and soft as were his tones—for he did not wish to attract any
attention—Mr. Craven was overheard. Katy O'Grady's ears were
sharp, and at the first sound she drew near to the window, where,
herself unobserved, she was an eye and ear witness of Mr. Craven's
blandishments.
"What is the ould villain doin' now?" she said to herself. "Is he going
to thry p'isonin' him again?"
But no piece of meat was produced. Mr. Craven had other intentions.
"Come here, Pompey," said he, soothingly; "follow me, sir."
So saying, he rose and beckoned the dog to follow him.
Pompey rose, stretching his limbs, and obediently trotted after his
deadly foe.
"Where's he takin' him to?" thought Katy. "He manes mischief, I'll be
bound. The misthress is gone, and Master Frank's gone, and he
thinks there ain't nobody to interfere. Katy O'Grady, you must go
after him and see what he's up to."
Katy was in the midst of her work, but she didn't stop for that. She
had in her hand a glass tumbler, which she had been in the act of
wiping, but she didn't think to put it down. Throwing her apron over
her head, she followed Mr. Craven at a little distance. He made his
way into a field in the rear of the house. She went in the same
direction, but on the other side of a stone wall which divided it from
a neighboring field. From time to time she could catch glimpses,
through the loosely laid rocks, of her employer, and she could
distinctly hear what he was saying.
"My friend Pompey," he said, with a smile full of deadly meaning,
"you are going to your death, though you don't know it. That was a
bad job for you when you attacked me, my four-footed friend. You
won't be likely to trouble me much longer."
"What's he going to do to him?" thought Katy; "it's not p'ison, for he
hasn't got any meat. May be it's shootin' him he manes."
Mr. Craven went on.
"Poison doesn't seem to do you any harm, but I fancy you can't
stand powder and ball quite so well."
"Yes, he's goin' to shoot him. What will I do?" thought Katy. "I'm
afraid I can't save the poor creetur's life."
By this time Mr. Craven had got so far that he considered it very
unlikely that the report of the pistol would be heard at the house. He
stopped short, and, with a look of triumphant malice, drew the pistol
from his pocket. Pompey stood still, and looked up in his face.
"How can he shoot the poor creetur, and him lookin' up at him so
innocent?" thought Katy. "What will I do? Oh, I know—I'll astonish
him a little."
Mr. Craven was just pointing the pistol at Pompey, when Katy flung
the tumbler with force against his hat, which rolled off. In his fright
at the unexpected attack, the pistol went off, but its contents were
lodged in a tree near by, and Pompey was unhurt.
Mr. Craven looked around him with startled eyes, but he could not
see Katy crouching behind the wall, nor did he understand from
what direction the missile had come.
CHAPTER VII.
MISS O'GRADY'S VICTORY.

Crouching behind the stone wall, Katy enjoyed the effect of what she
had done. She particularly enjoyed the bewildered look, of Mr.
Craven, who, bare-headed, looked on this side and on that, unable
to conjecture who had thrown the missile.
Pompey, unconscious of the danger he had escaped, walked up to
the tumbler and smelt of it. This attracted the attention of Mr.
Craven, who stooped and picked it up. His bewilderment increased.
If it had been a stone, he would have understood better, but how a
tumbler should have found its way here as a missile was
incomprehensible.
It slowly dawned upon him that the person who threw it must be
somewhere near. Then again, on examining it further, he began to
suspect that it was one of his wife's tumblers, and he jumped to the
conclusion that it was Frank who threw it.
"If it is he, I'll wring his neck!" he murmured, revengefully. "I mean
to find out."
"Pompey," he said, calling the dog, "do you see this tumbler?"
Pompey wagged his tail.
"Who threw it?"
Pompey looked up, as if for instructions.
"Go find him!" said Mr. Craven, in a tone of command.
The dog seemed to understand, for he put his nose to the ground
and began to run along, as if in search.
"Oh, murther! What if he finds me?" thought Katy, crouching a little
lower. "Won't he be mad, jist?"
Katy might have crawled away unobserved, very possibly, if she had
started as soon as the missile was thrown. Now, that dog and man
were both on the lookout, escape was cut off.
"Will he find me?" Katy asked herself, with some anxiety.
The question was soon answered.
Pompey jumped over the wall, and a joyous bark announced his
discovery. He knew Katy, and seemed to fancy that she had
concealed herself in joke. He jumped upon her, and wagged his tail
intelligently, as if to say:
"You see, I've found you out, after all."
Mr. Craven hurried to the wall, eagerly expecting to detect Frank in
the person concealed. He started back in astonishment as Katy
O'Grady rose and faced him. Then he became wrathful, as he
realized that his own hired servant had had the audacity to fling a
tumbler at his hat.
"What brings you out here, Katy?" he demanded, with a frown.
"Shure, sir," said Katy, nonchalantly, "I was tired wid stayin' in the
hot kitchen, and I thought I'd come out and take the air jist."
"And so you neglected the work."
"The worruk will be done; niver you mind about that."
"Did you fling this tumbler at my head?" demanded Mr. Craven,
sternly.
"Let me look at it, sir."
Katy looked at it scrutinizingly, and made answer:
"Very likely, sir."
"Don't you know?"
"I wouldn't swear it was the same one, sir, but it looks like it."
"Then you admit throwing a tumbler at my head, do you?"
"No, sir."
"Didn't you say you did just now?"
"I threw it at your hat."
"It is the same thing. How came you to have the cursed impudence
to do such a thing?" asked her master, wrathfully.
"Because you was goin' to shoot the dog," said Katy, coolly.
"Suppose I was, is it any business of yours?"
"The dog doesn't belong to you, Mr. Craven. It belongs to Master
Frank."
"I don't think it expedient for him to keep such an ill-natured brute
around."
"He calls you a brute, Pomp," said Katy, caressing Pompey—"you
that's such a good dog. It's a shame!"
"Catherine," said Mr. Craven, with outraged dignity, "your conduct is
very improper. You have insulted me."
"By the powers, how did I do it?" asked Katy, with an affectation of
innocent wonder.
"It was an insult to throw that tumbler at my head. I might order the
constable to arrest you."
"I'd like to see him thry it!" said Katy, putting her arms akimbo in
such a resolute fashion that Mr. Craven involuntarily stepped back
slightly.
"Are you aware that I am your master?" continued Mr. Craven,
severely.
"No, I'm not," answered Katy, promptly.
"You are a servant in my house."
"No, I'm not. The house don't belong to you at all, sir. It belongs to
my mistress and Master Frank."
"That's the same thing. According to the law, I am in control of their
property," said Mr. Craven, resolved upon a master-stroke which, he
felt confident, would overwhelm his adversary. "After the great
impropriety of which you have been guilty this afternoon, I discharge
you from my employment."
"You discharge me!" exclaimed Katy, with incredulous scorn.
"I discharge you, and I desire you to leave the house to-morrow."
"You discharge me!" repeated Katy, with a ringing laugh. "That's a
good one."
Mr. Craven's cadaverous face colored with anger.
"If you don't go quietly, I'll help you out," he added, incautiously.
"Come on, then," said Katy, assuming a warlike attitude. "Come on,
then, and we'll see whether you can put out Katy O'Grady."
"Your impudence will not avail you. I am determined to get rid of
you."
"And do ye think I'm goin' to lave the house, and my ould misthress,
and Master Frank, at the orders of such an interloper as you, Mr.
Craven?" she cried, angrily.
"I don't propose to multiply words about it," said Mr. Craven, with an
assumption of dignity. "If you had behaved well, you might have
stayed. Now you must go."
"Must I?" sniffed Katy, indignantly. "Must I, indade?"
"Yes, you must, and the less fuss you make about it the better."
Mr. Craven supposed that he had the decided advantage, and that
Katy, angry as she was, would eventually succumb to his authority.
But he did not know the independent spirit of Catherine O'Grady,
whose will was quite as resolute as his own.
"And ye think I'm goin' at your word—I that's been in the family
since Master Frank was a baby?"
"I am sorry for you, Katy," said Mr. Craven, in triumphant
magnanimity. "But I cannot permit a servant to remain in my house
who is guilty of the gross impropriety of insulting me."
"I know why you want to get rid of me," said Katy, nodding her head
vigorously.
"Why?" asked Craven, with some curiosity.
"You want to p'ison the dog."
Mr. Craven started. How had his secret leaked out?
"What do you mean?"
"Mane! I mane that I saw you lavin' the p'isoned mate for the dog
three days agone, and if it hadn't been for me he'd have eaten it,
and the poor creetur would be stiff in death."
"He did eat it. I saw him," said Mr. Craven, hastily.
"No, he didn't. It wasn't the same mate!" said Katy, triumphantly.
"What was it, then?"
"It was a piece I cut off and carried out to him," said Katy. "The
other I wrapped up in a piece of paper, and buried it in the field."
Mr. Craven's eyes were opened. Pompey's cast-iron constitution was
explained. After all, he was not that natural phenomenon which Mr.
Craven had supposed him to be. But he was angry at Katy's
interference no less.
"Say no more," he said. "You must go. You have no right to interfere
with my plans."
"Say no more? Won't I be tellin' the misthress and Master Frank how
you tried to kill the poor dog, first with p'ison, and nixt wid a pistol?"
There was something in this speech that made Mr. Craven hesitate
and reflect.
He knew that Katy's revelation would provoke Frank, and make him
an enemy, and he feared the boy's influence on his mother,
particularly as he was concocting plans for inducing his wife to place
some of her money in his hand under pretext of a new investment.
He must be careful not to court hostile influences, and after all, he
resolved to bear with Katy, much as he disliked her.
"On the whole, Katy," he said, after a pause, "I will accept your
apology, and you may stay."
"My apology!" said Katy, in astonishment.
"Yes, your explanation. I see your motives were good, and I will
think no more about it. You had better not mention this matter to
Mrs. Craven or Frank, as it might disturb them."
"And won't you try to kill Pomp agin?" asked Katy.
"No; I dislike dogs, especially as they are apt to run mad, but as
Frank is attached to Pompey, I won't interfere. You had better take
this tumbler and wash it, as it is uninjured."
"All right, sir," said Katy, who felt that she had gained a victory,
although Mr. Craven assumed that it was his.
"I am very glad you are so devoted to your mistress," said Mr.
Craven, who had assumed his old suavity. "I shall propose to her to
increase your wages."
"He's a mighty quare man!" thought the bewildered Katy, as she
hurried back to her work, followed by Pompey.
CHAPTER VIII.
FRANK IS OBSTINATE.

Mr. Craven had as yet gained nothing from his marriage. He was
itching to get possession of his wife's property. Then his next step
would be Frank's more considerable property. He was beginning to
be low in pocket, and in the course of a month or so Mr. Green's
note for six hundred dollars would fall due. He knew enough of that
estimable gentleman to decide that it must be met, and, of course,
out of his wife's money.
"My dear," he said one day, after breakfast, Frank being on his way
to school, "I believe I told you before our marriage that I had twenty
thousand dollars invested in Lake Superior mines."
"Yes, Mr. Craven, I remember it."
"It is a very profitable investment," continued her husband. "What
per cent. do you think it pays me?"
"Ten per cent.," guessed Mrs. Craven.
"More than that. During the last year it has paid me twenty per
cent."
"That is a great deal," said his wife, in surprise.
"To be sure it is, but not at all uncommon. You, I suppose, have not
got more than seven or eight per cent. for your money?"
"Only six per cent."
Mr. Craven laughed softly, as if to say, "What a simpleton you must
be!"
"I didn't know about these investments," said his wife. "I don't know
much about business."
"No, no. I suppose not. Few women do. Well, my dear, the best
thing you can do is to empower me to invest your money for you in
future."
"If you think it best," said Mrs. Craven.
"Certainly; it is my business to invest money. And, by the way, the
income of Frank's property is paid to you, I believe."
"Yes."
"He does not come into possession till twenty-one."
"That was his father's direction."
"And a very proper one. He intended that you should have the
benefit of the income, which is, of course, a good deal more than
Frank needs till he comes of age."
"I thought perhaps I ought to save up the surplus for Frank," said
Mrs. Craven, hesitating.
"That is not necessary. Frank is amply provided for. He might be
spoiled by too much money."
"I don't think so. Frank is an excellent boy," said his mother, warmly.
"So he is," said Mr. Craven. "He has a noble, generous disposition,
and for that very reason is more liable to be led astray."
"I hope he won't be led astray. I should feel wretched if I thought
anything would befall him," said his mother, shuddering.
"We will look after him; we will see that he goes straight," said Mr.
Craven, cheerfully. "But I wanted to suggest, my dear, that it would
be proper that I should be appointed joint guardian with you."
"I am not sure whether Frank will like it," said his mother, who was
aware that Frank, though scrupulously polite to his step-father, had
no cordial liking or respect for him.
"As to that, my dear, I count upon you exerting your influence in the
matter. If you recommend it he will yield."
"Don't you think it just as well as it is?" said Mrs. Craven,
hesitatingly. "Of course, we shall go to you for counsel and advice in
anything important."
"You don't seem to have confidence in me," said Mr. Craven, with an
injured air.
"I hope you won't think that, Mr. Craven," said his wife, hastily.
"How can I help it? You know my interest in Frank, yet you are
unwilling to have me associated in the guardianship."
"I didn't say I objected. I said Frank might."
"You are not willing to urge him to favor the measure."
"You misunderstand me. Yes, I will," said yielding Mrs. Craven.
"Thank you, my dear," said Mr. Craven, with one of his most
unctuous smiles. "I was quite sure you would do me justice in the
end. By the way, what disposition is made of Frank's property if he
does not live to come of age?"
"You—you don't think he is likely to be taken away?" said Mrs.
Craven, in distress.
"You are a goose," said her husband, laughing softly. "Of course not.
But then we are all mortal. Frank is strong, and will, I hope, live to
smooth our dying pillows. But, of course, however improbable, the
contingency is to be thought of."
"I believe the property comes to me in that case, but I am sure I
should not live to enjoy it."
"My dear, don't make yourself miserable about nothing. Our boy is
strong, and has every prospect of reaching old age. But it is best to
understand clearly how matters stand. By the way, you need not say
anything about the guardianship to him till I tell you."
Mrs. Craven not only complied with this request, but she
surrendered to Mr. Craven the entire control of her money within an
hour. She raised one or two timid objections, but these were
overruled by her husband, and in the end she yielded. Mr. Craven
was now in funds to pay the note held by Job Green, and this
afforded him no little relief.
A few evenings later, Frank was about to take his cap and go out,
when Mr. Craven stopped him.
"Frank," he said, "if you have no important engagement, your
mother and I desire to speak to you on a matter of some
consequence."
"I was only going to call on one of my friends," said Frank. "I will
defer that and hear what you have to say."
"Thank you," said Mr. Craven, smiling sweetly. "I wished to speak to
you on the subject of your property."
"Very well, sir."
"Your mother is your guardian, she tells me."
"Yes, sir."
"The responsibilities of a guardian are very great," proceeded Mr.
Craven, leaning back upon his chair. "Naturally there are some of
them to which a woman cannot attend as well as a man."
Frank began to understand what was coming, and, as it was not to
his taste, he determined to declare himself at once.
"I couldn't have a better guardian than my mother," he said.
"Of course not. (I am afraid I shall find trouble with him, thought Mr.
Craven.) Of course not. You couldn't possibly find any one as much
interested in your welfare as your mother."
"Certainly not, sir."
"As your step-father, I naturally feel a strong interest in you, but I do
not pretend to have the same interest as your mother."
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like