Reorder postupgrade operations: take gw snapshot before drop it from database.
Fix load certificate for Server API.

Use raw SQL instead of ORM because changes on database schema are
not yet available.