Home / OCI

OCIRunbookAdvanced

Sev1: OCI block volume detached from a running database server

A data volume was detached from a live database VM and the database crashed with I/O errors. Reattach it at the same device path, check the filesystem, recover the database and stop it happening again.

Deepak Bhardwaj6 min read

Applies toOCI Block Volume with paravirtualized and iSCSI attachments; self-managed databases (Oracle, PostgreSQL, MySQL, SQL Server) on OCI Compute; Oracle Linux 8/9; OCI CLI 3.x

Symptoms

  • The database crashed or hung. Its alert log shows I/O errors: ORA-27072, ORA-01115, PostgreSQL could not write to file ... Input/output error, MySQL InnoDB: Operating system error number 5.
  • dmesg shows I/O error, Buffer I/O error on dev sdb, XFS (sdb1): log I/O error or EXT4-fs error.
  • The mount point is still listed by mount, but ls on it returns Input/output error.
  • The volume shows Available (not attached) in the console, or is attached to another instance.

This post covers self-managed databases on Compute. For Base Database Service and Exadata, storage is managed by the service; open a Sev1 with Oracle Support instead of attaching volumes yourself.

1. Confirm the volume is detached (2 minutes)

export INSTANCE=ocid1.instance.oc1..xxxx
export COMP=ocid1.compartment.oc1..xxxx

oci compute volume-attachment list --compartment-id $COMP --instance-id $INSTANCE --all \
  --query 'data[].{vol:"volume-id", type:"attachment-type", device:device, state:"lifecycle-state"}' --output table

Find the volume and check where it is now:

export VOL=ocid1.volume.oc1..xxxx
oci bv volume get --volume-id $VOL --query 'data.{name:"display-name", state:"lifecycle-state", size:"size-in-gbs"}'
oci compute volume-attachment list --compartment-id $COMP --volume-id $VOL --all \
  --query 'data[].{instance:"instance-id", state:"lifecycle-state"}' --output table

Find out who detached it and why, so you know whether it will happen again in five minutes:

oci logging-search search-logs \
  --search-query 'search "'"$COMP"'/_Audit" | where data.eventName = '"'DetachVolume'"' | sort by datetime desc' \
  --time-start $(date -u -d '-12 hours' +%Y-%m-%dT%H:%M:%SZ) \
  --time-end $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --query 'data.results[].data.{time:datetime, who:data.identity.principalName, resource:data.resourceName}'
What you find Cause Next step
Volume AVAILABLE, detached by a person Wrong volume picked during cleanup Reattach to the same instance
Detached by a Terraform/Resource Manager principal Plan removed the attachment resource Pause the pipeline, then reattach
Volume attached to another instance Someone attached it elsewhere Stop anything using it there and detach cleanly
Volume TERMINATED Volume deleted, not just detached Restore from the latest volume backup or replica

2. Stop the database and clean up the stale mount

The kernel still holds the old device. Clean that up before reattaching, or the volume can come back under a different device name while the old mount hangs.

sudo systemctl stop <database-service>      # e.g. postgresql-16, mysqld, oracle-db unit
sudo fuser -vm /u01                          # anything still holding the mount
sudo umount /u01 || sudo umount -l /u01      # lazy unmount if the normal one hangs

Caution

Do not start the database, run fsck/xfs_repair, or restore over the data until the volume is reattached and you have made a backup or clone of it. If the volume is attached elsewhere and something wrote to it, a second writer can corrupt the filesystem for good.

If the volume is attached to another instance, stop the workload there, unmount, and detach it:

oci compute volume-attachment detach --volume-attachment-id <attachment-ocid> --force --wait-for-state DETACHED

3. Protect the data before you touch it

Take a backup or a clone first. A clone is fast and gives you a copy to fall back on if the repair goes badly.

oci bv volume create --source-volume-id $VOL --display-name db-data-pre-repair \
  --availability-domain <same-AD> --compartment-id $COMP
# or a backup:
oci bv backup create --volume-id $VOL --type INCREMENTAL --display-name db-data-pre-repair

4. Reattach at the same device path

Using the same consistent device path (/dev/oracleoci/oraclevdX) keeps /etc/fstab and the database configuration valid. Check which paths are free:

oci compute device list-instance-devices --instance-id $INSTANCE --is-available true \
  --query 'data[].name' --output table

Paravirtualized (the default for most current shapes and images):

oci compute volume-attachment attach --instance-id $INSTANCE --volume-id $VOL \
  --type paravirtualized --device /dev/oracleoci/oraclevdb --wait-for-state ATTACHED

iSCSI:

ATT=$(oci compute volume-attachment attach --instance-id $INSTANCE --volume-id $VOL \
  --type iscsi --device /dev/oracleoci/oraclevdb --wait-for-state ATTACHED \
  --query 'data.id' --raw-output)
oci compute volume-attachment get --volume-attachment-id $ATT \
  --query 'data.{iqn:iqn, ip:ipv4, port:port}'

If the Block Volume Management plugin of Oracle Cloud Agent is enabled, it logs in to the iSCSI target for you. Otherwise, use the values from get:

sudo iscsiadm -m node -o new -T <iqn> -p <ip>:3260
sudo iscsiadm -m node -o update -T <iqn> -n node.startup -v automatic
sudo iscsiadm -m node -T <iqn> -p <ip>:3260 -l

Confirm the device is back:

ls -l /dev/oracleoci/
lsblk -f

5. Check the filesystem, mount, recover

Run a read-only check first. The examples use partition 1; use the whole device or LVM volume if that is how the disk was set up (lsblk -f shows it):

sudo xfs_repair -n /dev/oracleoci/oraclevdb1     # XFS: no-modify mode
sudo e2fsck -n /dev/oracleoci/oraclevdb1         # ext4

For XFS, mounting replays the log and that is usually all that is needed. Only run xfs_repair without -n if the mount fails, and never use -L (zeroing the log) without your clone in hand.

sudo mount /u01          # uses the fstab entry
ls /u01 && df -h /u01

Start the database and let it run crash recovery:

  • Oracle: startup in SQL*Plus; instance recovery runs automatically. If datafiles are flagged, recover datafile <n> then alter database datafile <n> online.
  • PostgreSQL: start the service and watch the log for redo done and database system is ready to accept connections.
  • MySQL/InnoDB: start the service and check the error log for crash recovery completing.

Then run a consistency check before you reopen to users: dbv or RMAN validate database, amcheck on critical PostgreSQL indexes, CHECK TABLE on key MySQL tables.

Verify

  • oci compute volume-attachment list shows the volume ATTACHED to the right instance.
  • /etc/fstab uses the consistent device path or UUID, with _netdev,nofail for iSCSI volumes.
  • The database is open, the consistency check passes, and application error rates are back to normal.
  • Reboot test in the next maintenance window: the volume reattaches and mounts on its own.

Prevent it next time

  • Tag data volumes clearly (role=db-data, owner=...) and include the instance name in the display name, so the wrong volume is not picked.
  • Limit manage volume-attachments in production to the platform group and pipeline. Most teams only need use or read.
  • In Terraform, put lifecycle { prevent_destroy = true } on production volume attachments as well as volumes.
  • Create an Events rule for DetachVolume in production compartments that pages the database on-call.
  • Keep a volume backup policy and, for critical databases, cross-region block volume replication.