Database operations can fail because of temporary network errors or because the database is temporarily unavailable. Is there a way to automatically retry the operation in these cases ?
The documentation of Google’s managed database offering states that connection pooling systems should reconnect to the database if a connection is in a bad state, and applications should retry a database transaction if an error app in the middle of a transaction. (See Manage database connections | Cloud SQL for PostgreSQL | Google Cloud, section “Exponential backoff”) How can I implement this advise using Django?
I’m currently having problems with views that successfully perform some database operations but randomly encounter a connection error during a subsequent database operation. How can I retry the database operation so that the view is finally rendered successfully?