删除废弃空间的方法

SinoDB表空间是由一个或若干个物理文件chunk组成。在数据库层面,用户表空间里存放着重要的生产数据或索引,一般不建议进行表空间的删除操作。而作为数据库关键的数据库空间,如rootdbspace,physical log dbspace 和logical log dbspace 则不允许删除。如若非要进行删除空间的操作,那么请谨慎操作,删除操作前最好做好相关的备份,以便需要时进行恢复。

SinoDB不允许删除非空的数据库空间,所谓的非空并非指什么信息都没有。
空的表空间是指除了系统所需的53页外不允许有其他的页被使用,如果数据库空间(rootdbspace除外)仅有53页被使用,则认为是“空”。
那么,如何确认为空的表空间?可通过onchek -pe命令进行检查。
以下通过建立一个新的,未进行任何写入数据的表空间进行验证测试:
$ touch testdbs
$ chmod 660 testdbs
$ onspaces -c -d testdbs -p /home/sinodbms/datadbs/testdbs -k 4 -o 0 -s 102400
Verifying physical disk space, please wait …
Space successfully added.

** WARNING ** A level 0 archive of Root DBSpace will need to be done.
$ oncheck -pe testdbs

DBspace Usage Report: testdbs Owner: sinodbms Created: 12/29/2023

Chunk Pathname Pagesize(k) Size(p) Used(p) Free(p)
12 /home/sinodbms/datadbs/testdbs 4 25600 53 25547

Description Offset(p) Size(p)


RESERVED PAGES 0 2
CHUNK FREELIST PAGE 2 1
testdbs:‘sinodbms’.TBLSpace 3 50
FREE 53 25547

Total Used: 53
Total Free: 25547

确认只有page 53被使用,删除操作可以通过命令onspaces -d进行:

$ onspaces -d testdbs
WARNING: Dropping a DBspace.
Do you really want to continue? (y/n)y
Space successfully dropped.
** WARNING ** A level 0 archive will need to be done before any chunks from
DBspace testdbs can be reused (see Dynamic Server Administrator’s manual).

通过onstat -d就可以确认testdbs空间被删除了,数据库逻辑层面的表空间已不再有testdbs,而组成表空间的chunk文件仍然以物理形式存在:
$ ls -l testdbs
-rw-rw---- 1 sinodbms sinodbms 104857600 12月 31 19:32 testdbs
在操作系统层面彻底删除物理文件用rm即可,删除后即可释放chunk所占空间。
$ rm testdbs

十分有用的分享!

1 个赞

写的很好很实用 :smile: