Chapter 31 Exercises: DB2 in the Cloud
Exercise 31.1: Provision a Db2 on Cloud Instance
Objective: Understand the provisioning process and connection configuration for IBM Db2 on Cloud.
Tasks:
-
Using the IBM Cloud CLI syntax shown in Section 31.2.2, write the command to provision a Db2 on Cloud Enterprise HA instance with the following specifications: - Instance name:
meridian-digital-prod- Region:eu-de(Frankfurt) - CPU: 16 vCPUs - Memory: 64 GB - Storage: 500 GB -
Write the JDBC connection string for this instance assuming the hostname is
dashdb-txn-flex-yp-fra02-01.services.eu-de.bluemix.net, port 50001, databaseBLUDB, usermeridian_admin, with SSL enabled. -
Write a Python connection script using the
ibm_dblibrary that: - Connects to the instance using the DSN string. - ExecutesSELECT CURRENT_TIMESTAMP FROM SYSIBM.SYSDUMMY1. - Prints the result. - Closes the connection. -
Explain why you would choose the Enterprise HA plan over the Standard plan for Meridian's digital banking workload.
Exercise 31.2: Docker Db2 Deployment
Objective: Deploy a Db2 Community Edition container for local development.
Tasks:
-
Write a complete
docker runcommand that: - Uses theicr.io/db2_community/db2:latestimage. - Creates a database namedDEVMERIDIAN. - Maps ports 50000 and 50001 to the host. - Uses a named volumedb2-dev-datafor persistent storage. - Sets the instance password to a secure value. - Enables archive logging. -
Write a
docker-compose.ymlfile that defines the same Db2 service with the addition of: - A health check that verifies the database is accessible. - Memory limits (8 GB max, 4 GB minimum). - Automatic restart on failure. -
Write a shell script that waits for the container to be ready and then: - Creates a schema named
MERIDIAN. - Creates theCUSTOMER_DIGITAL_PROFILEtable with columns:customer_id,preferred_channel,notification_prefs,last_login_ts,mfa_enabled. - Inserts 5 sample rows. - Queries and displays the data. -
Explain why the
--privilegedflag is required for Db2 containers and what security implications it has.
Exercise 31.3: Kubernetes StatefulSet for Db2
Objective: Design a Kubernetes deployment for Db2 in a production-like environment.
Tasks:
-
Write a Kubernetes Secret manifest that stores the Db2 instance password.
-
Write a StatefulSet manifest that: - Deploys a single Db2 instance. - Uses the Db2 Community Edition image. - Requests 4 CPUs and 8 GB memory, with limits of 8 CPUs and 16 GB. - Uses a PersistentVolumeClaim template for 200 GB of SSD storage. - Mounts the Db2 data volume at
/database. - References the password from the Secret. -
Write a ClusterIP Service that exposes both port 50000 (plain) and port 50001 (SSL).
-
Write a LoadBalancer Service for external access on the SSL port only.
-
Explain why a StatefulSet is used instead of a Deployment for Db2, and what guarantees a StatefulSet provides that a Deployment does not.
Exercise 31.4: Federation Configuration
Objective: Configure data federation between on-premises DB2 z/OS and Db2 on Cloud.
Tasks:
-
Write the complete federation configuration script including: - Enabling the federated feature in DBM CFG. - Creating the DRDA wrapper. - Defining a server for the on-premises DB2 z/OS instance. - Defining a server for Db2 on Cloud. - Creating user mappings. - Creating nicknames for:
MERIDIAN.ACCOUNT_MASTERon z/OSMERIDIAN.TRANSACTION_HISTORYon z/OSMERIDIAN.CUSTOMER_DIGITAL_PROFILEon Db2 on Cloud
-
Write a federated query that: - Joins the z/OS account master with the cloud digital profile. - Filters for accounts with a balance greater than $100,000. - Returns account details and the customer's preferred channel and last login.
-
Explain what "predicate pushdown" means in the context of this federated query and which predicates would be pushed to which server.
-
Design a materialized query table (MQT) that caches the result of the federated join for frequently accessed data. Explain when the MQT should be refreshed.
Exercise 31.5: Cloud Migration Planning
Objective: Develop a migration plan for moving a Db2 LUW database to Db2 on Cloud.
Scenario: Meridian's digital banking team has a 500 GB Db2 LUW database running on-premises that needs to migrate to Db2 on Cloud. The database contains: - 45 tables - 120 indexes - 15 stored procedures - 8 triggers - 3 MQTs (materialized query tables)
Tasks:
-
Choose a migration strategy (lift-and-shift, re-platform, or re-architect) and justify your choice.
-
Create a migration checklist that includes: - Pre-migration compatibility assessment - Schema migration steps - Data migration steps - Application connection updates - Post-migration validation
-
Calculate the data transfer time for the 500 GB database over: - A 100 Mbps internet connection - A 1 Gbps dedicated link - A 10 Gbps Direct Link
-
Write the
db2movecommands for exporting and importing the entire database. -
Design a zero-downtime migration plan using CDC replication. List the steps from initial setup through final cutover.
Exercise 31.6: Cloud Security Configuration
Objective: Implement a comprehensive security configuration for Db2 on Cloud.
Tasks:
-
Write the IBM Cloud CLI command to create a Key Protect root key for database encryption.
-
Write SQL statements to implement role-based access control: - Create roles:
APP_READONLY,APP_READWRITE,ANALYTICS_USER,DBA_ADMIN. - Grant appropriate privileges for each role on theMERIDIANschema. - Create a user mapping that ties an IAM service ID to theAPP_READWRITErole. -
Write an audit policy that: - Audits all EXECUTE operations (with data) on the
ACCOUNT_MASTERandTRANSACTION_HISTORYtables. - Audits all SYSADMIN and DBADMIN operations. -
Write the CLI command to configure a private endpoint for the Db2 instance.
-
Design a network architecture diagram (described in text) showing: - VPC configuration - Private endpoint for Db2 - VPN or Direct Link to on-premises - IP allowlisting rules
Exercise 31.7: Cost Optimization Analysis
Objective: Analyze and optimize cloud costs for Meridian's database deployment.
Tasks:
-
Using the illustrative pricing from Section 31.10.1, calculate the monthly cost for: - Db2 on Cloud Enterprise with 16 vCPUs, 64 GB RAM, 500 GB storage, Enterprise HA. - Include backup storage (assume 1 TB of backups retained). - Include 100 GB/month of data transfer out.
-
Calculate the savings from switching to a 3-year reserved commitment.
-
Design a tiered storage strategy for Meridian's 7-year transaction history: - Hot tier: Last 6 months on Db2 on Cloud. - Warm tier: 6 months to 3 years on Db2 Warehouse (estimate compression ratio of 8:1). - Cold tier: 3 to 7 years on Cloud Object Storage. - Calculate the total monthly storage cost.
-
Identify three specific cost optimization opportunities beyond what is already implemented.
-
Build a 3-year TCO comparison between on-premises Db2 LUW and Db2 on Cloud for the digital banking workload. State your assumptions clearly.