More:
MDB_CP_COMPACT would drop a new, empty main DB. (I.e. the main DB would lose its flags.)
Compacting can verify that the written metapage claims enough DB pages. But not the opposite - it should not fail if it claims too many pages since that would mean we can't compact a DB which has suffered page leaks.
We could detect that and re-write the metas at the end, if the user requests it and the file is seekable.