Pergunta

How can I compact Firebird 2.1 database, like we do in MS Access (discarding erased data, remaking index, etc)?

There's a way to do it?

Thanks!

Foi útil?

Solução

Usually there is no need to compact a Firebird Database: see fb release notes about garbage collection and an automatic (per-database configurable) operation named "sweep". In few words, fb reuses space in pages when records are deleted or oldest record version are freed asking for disk space chunks only when free space becomes too small (i.e. under a defined percent). Sweep is performed as default after a predefined number of commited transactions, bur it's an expensive task. Backup and restore must be intended as last resort to optimize and shrink, as this rebuilds and optimize indexes too, but usually this is not needed as there are commands and tools to rebuild indexes.

Outras dicas

The only way to do it is to make a backup and a restore.

From the official faq

Many users wonder why they don't get their disk space back when they delete a lot of records from database.

The reason is that it is an expensive operation, it would require a lot of disk writes and memory - just like doing refragmentation of hard disk partition. The parts of database (pages) that were used by such data are marked as empty and Firebird will reuse them next time it needs to write new data.

If disk space is critical for you, you can get the space back by doing backup and then restore. Since you're doing the backup to restore right away, it's wise to use the "inhibit garbage collection" or "don't use garbage collection" switch (-G in gbak), which will make backup go A LOT FASTER. Garbage collection is used to clean up your database, and as it is a maintenance task, it's often done together with backup (as backup has to go throught entire database anyway). However, you're soon going to ditch that database file, and there's no need to clean it up.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top