3đź‘Ť
The original confusion is that Django tries to connect to its databases on startup. This is actually not true. Django does not connect to database, until some app tries to access the database.
Since my web application uses auth
and site
apps, it looks like it tries to connect on startup. But its not tied to startup, its tied to the fact that those app access the database “early”.
If one defines second database backend (non-default), then Django will not try connecting to it unless application tries to query it.
So the solution was very trivial – originally I had one database that hosted both auth/site data and also “real” data that I’ve exposed to users. I wanted to make “real” database connection to be volatile. So I’ve defined separate psql
backend for it and switched default backend to sqlite
.
Now when trying to access “real” database through Query, I can easily wrap it with try/except and handle “Sorry, try again later” over to the user.