Error: Failed to connect to database – NetBox migration strategy for zero‑downtime deployment
0 reputation · 10 Sept 2023, 13:49 UTC
Goal
To upgrade a small NetBox instance to a newer release while keeping the application online for clients.
Constraints & Uncertainty
NetBox automatically applies pending Django migrations during startup. This process acquires schema locks that can block read/write traffic, potentially exposing a brief outage. The documented option to suppress automatic migrations is the environment variable DJANGO_MIGRATE, but its exact effect on the web server startup remains unclear. Additionally, the Failed to connect to database error is logged when NetBox cannot establish a connection during this migration phase, which may cause the service to halt entirely. A key decision is whether to rely on the automatic migration mechanism or to perform migrations manually in a blue‑green deployment pattern, and how to guarantee the database remains reachable throughout the switch.
Specific Questions
- Does setting
DJANGO_MIGRATE=0fully disable automatic migrations during NetBox startup, or does it only affect thepython manage.py migratecommand? - When a manual migration is run on a live NetBox instance, how long do database locks persist, and can they interrupt ongoing API requests?
- What is the recommended sequence of operations to ensure the database remains reachable and the application stays online during a blue‑green deployment of NetBox?