
The BOOKINGS table contains online booking information. When a booking is confirmed, the details are transferred to an archival table BOOKINGS_HIST and deleted from the BOOKINGS table. There is no fixed time interval between each online booking and its confirmation. Because sufficient space is not always available from the delete operations the high-water mark (HWM) is moved up and many rows are inserted below the HWM of the table. The BOOKINGS table has Automatic Segment Space Management (ASSM) and row movement enabled. The table is accessible in 24x7 mode. What is the most efficient method to reclaim the space released by the delete operations in the BOOKINGS table?()A. Perform EXPORT, DROP, and IMPORT operations on the BOOKINGS table sequentially B. Shrink the BOOKINGS table by using the ALTER TABLE SHRINK SPACE command C. Move the BOOKINGS table to a different location by using the ALTER TABLE MOVE command D. Deallocate the space in the BOOKINGS table by using the ALTER TABLE DEALLOCATE UNUSED command
要高效回收BOOKINGS表因删除操作释放的空间,最佳方案是使用ALTER TABLE SHRINK SPACE命令。该表已启用自动段空间管理(ASSM)和行移动功能,满足收缩操作的核心前提条件。收缩操作通过两个阶段实现空间回收:首先重组数据块使记录紧密排列(COMPACT阶段),仅对涉及移动的行加锁,对24x7可用的业务影响较小;随后调整高水位线(HWM)释放空闲数据块,此时虽需短暂表级锁,但整体效率远高于其他方案。
相比之下,EXPORT/DROP/IMPORT(选项A)和ALTER TABLE MOVE(选项C)需长时间锁定表或重建索引,会中断持续访问;DEALLOCATE UNUSED(选项D)仅释放HWM以上未使用的空间,无法解决HWM以下碎片化问题。而SHRINK SPACE不仅能降低HWM、释放空间供其他对象使用,还可通过CASCADE子句同步收缩关联索引,避免索引失效风险。
在执行时,建议分两步操作以平衡性能与可用性:先执行ALTER TABLE BOOKINGS SHRINK SPACE COMPACT进行在线数据重组,再在业务低峰期执行ALTER TABLE BOOKINGS SHRINK SPACE完成HWM调整。这种方式既能最小化对实时 booking 系统的影响,又能彻底回收碎片空间,提升后续查询效率。
为何日常delete操作无法自动降低HWM?因为Oracle的高水位线机制默认只增不减,如同水库的历史最高水位标记。只有通过SHRINK或重建操作才能重置这一标记,而SHRINK凭借对业务连续性的友好支持,成为动态系统的最优选择。实际运维中,还需注意收缩可能产生大量归档日志,需预留足够存储空间。