Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,82 @@
---
# Patch STMTHEAP for a single Db2 instance
# Patch a single Db2 instance for v12 upgrade (STMTHEAP + DBT5530N fix)
# =============================================================================
# This task checks and patches STMTHEAP configuration for a single instance.
# It verifies if AUTOMATIC is already present and only patches if needed.
# This task:
# 1. Fixes DBT5530N `The db2ckupgrade command failed because the tablespace is not
# in normal state. Tablespace: "TEMPSPACE1". State: "OFFLINE + DROP_PENDING".
# Member: "0".` by creating a new tablespace TEMPSPACE2.
# 2. Ensures STMTHEAP has the AUTOMATIC keyword required by Db2 v12.
# =============================================================================

- name: "Set instance name for STMTHEAP patching"
- name: "Set instance name for v12 patching"
set_fact:
current_instance_name: "{{ db2_instance.metadata.name }}"
current_dbconfig: "{{ db2_instance.spec.environment.database.dbConfig | default({}) }}"

# -----------------------------------------------------------------------------
# Fix DBT5530N The db2ckupgrade command failed because the tablespace is not in
# normal state. Tablespace: "TEMPSPACE1"
# -----------------------------------------------------------------------------
- name: "Fix DBT5530N for {{ current_instance_name }}"
block:
- name: "Check if TEMPSPACE1 is in OFFLINE + DROP_PENDING state for {{ current_instance_name }}"
kubernetes.core.k8s_exec:
namespace: "{{ db2_namespace }}"
pod: "c-{{ current_instance_name }}-db2u-0"
command: >
su - db2inst1 -c
"db2 -x \"SELECT TBSP_STATE FROM SYSIBMADM.TBSP_UTILIZATION WHERE TBSP_NAME = 'TEMPSPACE1'\""
register: tempspace1_check
failed_when: false

- name: "Fix tablespace for {{ current_instance_name }}"
when: >-
tempspace1_check.rc == 0 and
'OFFLINE' in tempspace1_check.stdout.upper() and
'DROP_PENDING' in tempspace1_check.stdout.upper()
block:
- name: "Retrieve IBMDEFAULTBP page size for {{ current_instance_name }}"
kubernetes.core.k8s_exec:
namespace: "{{ db2_namespace }}"
pod: "c-{{ current_instance_name }}-db2u-0"
command: >
su - db2inst1 -c
"db2 -x \"SELECT PAGESIZE FROM SYSCAT.BUFFERPOOLS WHERE BPNAME = 'IBMDEFAULTBP'\""
register: pagesize_result

- name: "Parse page size for {{ current_instance_name }}"
set_fact:
db2_tempspace_pagesize: "{{ pagesize_result.stdout | trim }}"

- name: "Create TEMPSPACE2 with page size {{ db2_tempspace_pagesize }} for {{ current_instance_name }}"
kubernetes.core.k8s_exec:
namespace: "{{ db2_namespace }}"
pod: "c-{{ current_instance_name }}-db2u-0"
command: >
su - db2inst1 -c
"db2 'CREATE TEMPORARY TABLESPACE TEMPSPACE2 PAGESIZE {{ db2_tempspace_pagesize }} MANAGED BY AUTOMATIC STORAGE'"
register: create_tempspace2_result

- name: "Drop TEMPSPACE1 for {{ current_instance_name }}"
kubernetes.core.k8s_exec:
namespace: "{{ db2_namespace }}"
pod: "c-{{ current_instance_name }}-db2u-0"
command: >
su - db2inst1 -c
"db2 'DROP TABLESPACE TEMPSPACE1'"
register: drop_tempspace1_result

- name: "Debug DBT5530N tablespace fix result for {{ current_instance_name }}"
ansible.builtin.debug:
msg:
- "Instance: {{ current_instance_name }}"
- "Page size: {{ db2_tempspace_pagesize }}"
- "Create TEMPSPACE2: {{ create_tempspace2_result.stdout | default('N/A') }}"
- "Drop TEMPSPACE1: {{ drop_tempspace1_result.stdout | default('N/A') }}"

# -----------------------------------------------------------------------------
# Patch STMTHEAP - add AUTOMATIC keyword required by Db2 v12
# -----------------------------------------------------------------------------
- name: "Debug current STMTHEAP configuration for {{ current_instance_name }}"
ansible.builtin.debug:
msg:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
---
# Patch STMTHEAP configuration for Db2 v12 upgrade
# Patch Db2 instances for v12 upgrade (STMTHEAP + DBT5530N tablespace fix)
# =============================================================================
# This task ensures STMTHEAP has AUTOMATIC keyword before upgrading to v12.
# Db2 v12 requires STMTHEAP to include AUTOMATIC (e.g., STMTHEAP=20000 AUTOMATIC)
# This task ensures STMTHEAP has AUTOMATIC keyword and fixes DBT5530N tablespace
# access errors before upgrading to v12.
# This only runs when upgrading from v11 to v12, not for minor version updates.
# =============================================================================

- name: "Patch STMTHEAP for Db2 v12 upgrade"
- name: "Patch Db2 for v12 upgrade"
when:
- old_db2_major_version is version('12', '<')
- new_db2_major_version == '12'
block:
- name: "Get {{ instanceKind }} instances for STMTHEAP patching"
- name: "Get {{ instanceKind }} instances for v12 patching"
kubernetes.core.k8s_info:
api_version: db2u.databases.ibm.com/v1
kind: "{{ instanceKind }}"
namespace: "{{ db2_namespace }}"
register: db2_instances_for_patch

- name: "Debug STMTHEAP patching information"
- name: "Debug v12 patching information"
ansible.builtin.debug:
msg:
- "Patching STMTHEAP for Db2 v12 upgrade"
- "Patching Db2 instances for v12 upgrade"
- "Instance Kind ............................ {{ instanceKind }}"
- "Number of instances ....................... {{ db2_instances_for_patch.resources | length }}"
- "Namespace ................................. {{ db2_namespace }}"

- name: "Process each {{ instanceKind }} instance for STMTHEAP configuration"
- name: "Process each {{ instanceKind }} instance for v12 configuration"
when: db2_instances_for_patch.resources | length > 0
include_tasks: "tasks/upgrade/patch-stmtheap-instance.yml"
include_tasks: "tasks/upgrade/patch-db2-for-v12-instance.yml"
loop: "{{ db2_instances_for_patch.resources }}"
loop_control:
loop_var: db2_instance
Expand Down
15 changes: 8 additions & 7 deletions ibm/mas_devops/roles/db2/tasks/upgrade/prepare-db2-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,22 @@
- "License file exists .................... {{ license_file_stat.stat.exists }}"
- "License encoded (first 50 chars) ....... {{ db2_license_encoded[:50] }}..."

# 5. Patch STMTHEAP for Db2 v12 upgrade (before subscription upgrade)
# 5. Patch Db2 instances for v12 upgrade (before subscription upgrade)
# -----------------------------------------------------------------------------
# This must run before the subscription upgrade to ensure STMTHEAP has AUTOMATIC
# keyword when upgrading from v11 to v12
- name: "Patch STMTHEAP for Db2uCluster instances (v11 to v12 upgrade)"
include_tasks: "tasks/upgrade/patch-stmtheap-v12.yml"
# This must run before the subscription upgrade to:
# - Fix DBT5530N tablespace errors
# - Ensure STMTHEAP has AUTOMATIC keyword required by v12
- name: "Patch Db2uCluster instances for v11 to v12 upgrade"
include_tasks: "tasks/upgrade/patch-db2-for-v12.yml"
vars:
instanceKind: Db2uCluster
when:
- db2u_kind == "db2ucluster"
- db2_channel != old_db2_channel
- db2_v12_upgrade is defined and db2_v12_upgrade == true

- name: "Patch STMTHEAP for Db2uInstance instances (v11 to v12 upgrade)"
include_tasks: "tasks/upgrade/patch-stmtheap-v12.yml"
- name: "Patch Db2uInstance instances for v11 to v12 upgrade"
include_tasks: "tasks/upgrade/patch-db2-for-v12.yml"
vars:
instanceKind: Db2uInstance
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ ok=0
# Fix SQL0290N Table space access is not allowed. SQLSTATE=55039
if ! $(ls /mnt/tempts/systemp/db2inst1/NODE0000/{{ db2_dbname }}/T0000001); then
db2 "restart database {{ db2_dbname }} drop pending tablespaces (TEMPSPACE1)"
PAGESIZE=$(db2 -x "SELECT PAGESIZE FROM SYSCAT.BUFFERPOOLS WHERE BPNAME = 'IBMDEFAULTBP'" | awk '{print $1}')
db2 "CREATE TEMPORARY TABLESPACE TEMPSPACE2 PAGESIZE ${PAGESIZE} MANAGED BY AUTOMATIC STORAGE"
db2 "DROP TABLESPACE TEMPSPACE1"
fi

# connect to the newly created database - required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Fix SQL0290N Table space access is not allowed. SQLSTATE=55039
if ! $(ls /mnt/tempts/systemp/db2inst1/NODE0000/{{ db2_dbname }}/T0000001); then
db2 "restart database {{ db2_dbname }} drop pending tablespaces (TEMPSPACE1)"
PAGESIZE=$(db2 -x "SELECT PAGESIZE FROM SYSCAT.BUFFERPOOLS WHERE BPNAME = 'IBMDEFAULTBP'" | awk '{print $1}')
db2 "CREATE TEMPORARY TABLESPACE TEMPSPACE2 PAGESIZE ${PAGESIZE} MANAGED BY AUTOMATIC STORAGE"
db2 "DROP TABLESPACE TEMPSPACE1"
fi

TBSP_SQL="/tmp/.tbsp.sql"
Expand Down
Loading