PostgreSQL & databases for Django in production
Connecting, pooling, tuning, and troubleshooting the database behind Django: mostly PostgreSQL, with MySQL and SQLite.
PostgreSQL holds the data that matters, and its connections, locks, and queries decide how far a Django site can scale. Most performance problems end up here.
The guides cover connecting securely, pooling, timeouts, replicas, tuning, and the connection and authentication errors that appear in production.
Set it up
Guides that take this from nothing to running in production.
- How to Connect Django to PostgreSQL in Production
Connecting Django to PostgreSQL in production is more than changing the DATABASES setting.
- Connect Django to Managed PostgreSQL Securely
Moving a Django app from a local database or self-managed PostgreSQL server to a managed PostgreSQL service sounds simple: update the host, username, and password, then deploy.
- Set Up PgBouncer for Django
Put PgBouncer between Django and PostgreSQL: transaction pooling, SCRAM auth, pool sizing, compatible Django settings, and monitoring.
- Configure Django with MySQL in Production
Run Django on MySQL or MariaDB in production: mysqlclient, utf8mb4, strict SQL mode, time zone tables, connection timeouts, TLS, and backups.
- Deploy Multi-Tenant Django with django-tenants
Deploy a schema-per-tenant Django SaaS with django-tenants: wildcard DNS and TLS, Nginx for subdomains, migrate_schemas in releases, tenant-aware caching, media, Celery, and pooling.
- Run Django on SQLite in Production
Run Django on SQLite in production safely: WAL mode, busy timeout and IMMEDIATE transactions, file placement and permissions, online backups, Litestream replication, and when to move on.
- Deploy GeoDjango with PostGIS in Production
Deploy a GeoDjango app: GDAL, GEOS, and PROJ libraries on servers and in Docker, enabling PostGIS on self-hosted and managed PostgreSQL, spatial indexes, backups, and upgrades.
- Migrate a Django Project From SQLite to PostgreSQL
Move a live Django project from SQLite to PostgreSQL without losing data: create the schema with migrate, transfer data with dumpdata and loaddata or pgloader, fix content types and sequences, and cut over with minimal downtime.
- Run Elasticsearch or OpenSearch for Django in Production
Run Elasticsearch or OpenSearch as the search backend for a Django app: choose managed or self-hosted, connect with django-opensearch-dsl or django-elasticsearch-dsl, index asynchronously with Celery, secure the cluster, and plan reindexing.
- Deploy Django With the Official MongoDB Backend
Use the official django-mongodb-backend in production: connect to MongoDB Atlas or a replica set, set ObjectId primary keys, handle migrations and contrib apps, configure indexes, transactions, and connection pooling, and know its current limitations.
- Connect Django to Google Cloud SQL
Connect Django to Cloud SQL for PostgreSQL securely: use the Cloud SQL Auth Proxy or Unix sockets on Cloud Run, private IP inside a VPC, IAM database authentication, connection limits, and running migrations against Cloud SQL.
- Connect Django to Supabase Postgres
Use Supabase as the PostgreSQL database for a Django app: choose the direct connection or the Supavisor pooler, handle transaction-mode pooling with server-side cursors off, require SSL, keep Row Level Security from blocking Django, and run migrations.
- Connect Django to Neon Serverless Postgres
Use Neon serverless PostgreSQL with Django: pooled versus direct connection strings, cold starts after scale-to-zero, transaction-mode pooling settings, branches for preview environments, and running migrations safely.
- Run pgvector With Django in Production
Store and search embeddings with pgvector in a production Django app: enable the extension with a migration, use VectorField, build HNSW indexes without blocking writes, tune memory, batch embedding generation in Celery, and plan for index size.
- PostgreSQL vs MySQL for Django
Compare PostgreSQL and MySQL (and MariaDB) as the database for a Django project: Django feature support, transactional DDL for migrations, JSON, full-text search, extensions, managed hosting, performance, and team experience.
- Use Azure Database for PostgreSQL Flexible Server With Django
Connect Django to Azure Database for PostgreSQL Flexible Server: choose public or private access, require TLS, use Microsoft Entra authentication with managed identity, enable built-in PgBouncer, allow extensions, and configure high availability and backups.
- Run Django on Amazon Aurora PostgreSQL and Aurora Serverless v2
Run Django on Amazon Aurora PostgreSQL: choose provisioned or Serverless v2 capacity, use writer and reader endpoints with a database router, add RDS Proxy for connection pooling and faster failover, set minimum ACUs, and plan upgrades and backups.
- Run Django on CockroachDB
Run Django on CockroachDB with the django-cockroachdb backend: match backend and Django versions, configure TLS connections, handle transaction retries, adjust migrations and primary keys, and understand what works differently from PostgreSQL.
- Use Microsoft SQL Server With Django in Production
Run Django on Microsoft SQL Server or Azure SQL with mssql-django: install the ODBC driver in Docker or Linux, configure the connection and encryption, handle collation and Unicode, migrations, and connection pooling, and know the backend’s limitations.
- Back Up and Replicate a Django SQLite Database With Litestream
Use Litestream to continuously replicate a Django SQLite database to S3-compatible storage: enable WAL mode, run Litestream as a sidecar or systemd service, restore on startup in containers, test point-in-time recovery, and know the limits of single-writer SQLite.
- Add Meilisearch Search to a Django App in Production
Run Meilisearch for Django search in production: deploy it with a master key and persistent storage, index models from signals or Celery, use scoped API keys for frontend search, configure filterable and sortable attributes, and rebuild indexes safely.
- Use Typesense With Django for Fast Search
Use Typesense with Django in production: run a Typesense node or cluster with an API key and persistent data, define collection schemas, sync models from Celery, use scoped search keys in the frontend, and rebuild collections with aliases for zero downtime.
- Connect Django to Amazon RDS With IAM Authentication
Connect Django to Amazon RDS PostgreSQL or Aurora with IAM database authentication instead of a static password: grant rds_iam, create an rds-db:connect policy, generate auth tokens in a custom database backend, and require TLS.
- Run Procrastinate as a PostgreSQL Task Queue for Django
Use Procrastinate, a PostgreSQL-based task queue, with Django in production: install the Django contrib app, define and defer tasks inside transactions, run workers with concurrency, schedule periodic tasks, use locks and queueing locks, and monitor jobs in the admin.
Run it well
Tuning, reliability, and operations once it works.
- Configure Persistent Database Connections in Django
Use CONN_MAX_AGE and CONN_HEALTH_CHECKS correctly: when persistent connections help, connection math, idle timeouts, ASGI caveats, and measuring gains.
- Use Django's Built-In PostgreSQL Connection Pool
Enable Django's native psycopg 3 connection pool: sizing per process, CONN_MAX_AGE rules, health checks, Gunicorn and ASGI behavior, and PgBouncer.
- Route Django Reads to PostgreSQL Read Replicas
Add PostgreSQL read replicas to Django: multi-database settings, routers, replication lag and read-your-writes, transactions, migrations, and tests.
- Set PostgreSQL Statement Timeouts for Django
Stop runaway queries from exhausting Django workers: set statement_timeout per connection or role, give migrations and Celery different limits, handle QueryCanceled errors, and work with PgBouncer.
- Upgrade PostgreSQL to a New Major Version for Django
Upgrade the PostgreSQL behind a Django app to a new major version: check Django and psycopg support, choose dump and restore, pg_upgrade, or logical replication, then analyze, verify, and roll back safely.
- Tune PostgreSQL Autovacuum for Django
Keep Django tables fast and small with autovacuum tuning: find dead tuples and bloat, set per-table thresholds for hot tables in migrations, raise cost limits, and remove blockers like long transactions.
- Fast Pagination for Large Django Tables
Paginate large Django tables without slow OFFSET and COUNT queries: keyset (cursor) pagination on an indexed column, DRF CursorPagination, avoiding exact counts, admin tips, and when page numbers are still fine.
- Fast Bulk Inserts and Updates in Django
Speed up large Django data loads and updates: bulk_create and bulk_update with batch_size, update() with F expressions, update_conflicts for upserts, transactions, disabling per-row signals, COPY for very large imports, and what bulk methods skip.
- Tune PostgreSQL Settings for a Django Workload
Tune PostgreSQL configuration for a Django app: shared_buffers, effective_cache_size, work_mem, max_connections with pooling, random_page_cost on SSDs, checkpoints and WAL, autovacuum, and statement timeouts, with safe starting values by server size.
- Partition Large PostgreSQL Tables in a Django App
Use PostgreSQL declarative partitioning for very large Django tables such as events, logs, and audit trails: range partitions by time, creating them with migrations or pg_partman, primary key constraints, ORM behaviour, and dropping old data instantly.
- PostgreSQL Full-Text Search for Django in Production
Run Django search on PostgreSQL full-text search in production: a stored SearchVectorField with a GIN index, weights and ranking, language configurations, trigram similarity for typos, keeping vectors updated, and when to move to a search engine.
- Copy Production Data to Staging Safely (Anonymised)
Give a Django staging environment realistic data without exposing customers: copy production, anonymise personal fields with a management command or tooling, subset large tables, disable outbound email and payments, and automate refreshes.
- PostgreSQL High Availability and Failover for Django
Keep a Django app running through database failures: managed Multi-AZ PostgreSQL, Patroni or CloudNativePG for self-hosted clusters, connection endpoints that follow the primary, CONN_HEALTH_CHECKS and retries, and testing failover.
- Move a Django Database With Minimal Downtime Using Logical Replication
Migrate a Django PostgreSQL database to a new server, provider, or major version with seconds of downtime: logical replication publications and subscriptions, schema copy, sequence sync, cutover steps, and verification.
- A Practical Database Indexing Strategy for Django
Decide which indexes a Django app needs: find slow queries, index foreign keys and filter and ordering columns, use composite, partial, covering, and expression indexes with Meta.indexes, remove unused indexes, and add them without locking production tables.
- Use QuerySet.explain() and EXPLAIN ANALYZE to Speed Up Django Queries
Read PostgreSQL query plans for Django ORM queries with QuerySet.explain(analyze=True, buffers=True): spot sequential scans, bad row estimates, sorts, and nested loops, run EXPLAIN safely on production, and turn plans into indexes and queryset fixes.
- Index Django JSONField Queries With GIN on PostgreSQL
Speed up Django JSONField lookups on PostgreSQL: choose GinIndex with jsonb_ops or jsonb_path_ops for containment queries, add expression B-tree indexes for specific keys, write queries that can use them, and build the indexes concurrently.
- Remove PostgreSQL Table Bloat in Django With pg_repack
Measure and remove PostgreSQL table and index bloat in a Django database without long locks: estimate bloat, understand why VACUUM FULL blocks the app, run pg_repack on large tables, reindex concurrently, and prevent bloat from returning.
- Delete Old Rows in Django in Batches Without Hurting Production
Implement data retention in Django: delete old logs, task results, sessions, and events in small batches with primary key ranges, avoid long locks and replica lag, handle cascades, schedule cleanup with Celery or cron, and consider partitioning for big tables.
- Log Slow PostgreSQL Queries From Django With log_min_duration_statement
Turn on PostgreSQL slow query logging for a Django app: set log_min_duration_statement, add auto_explain for plans, tag queries with application_name and SQL comments to find the view that sent them, and ship logs to your log platform without flooding it.
- Manage PostgreSQL Connections for Django on Serverless Platforms
Avoid connection exhaustion when Django runs on Lambda, Cloud Run, Vercel, or autoscaling containers: use pooled endpoints (RDS Proxy, Neon, Supabase pooler, PgBouncer), set CONN_MAX_AGE and server-side cursor options correctly, and cap concurrency per instance.
- Backup and Restore PostgreSQL for Django Apps
A Django app is only recoverable if its PostgreSQL data is recoverable. In production, that means more than occasionally running pg_dump.
- Find and Fix N+1 Queries in Django
Find and fix N+1 queries in Django: detect them in tests and logs, use select_related, prefetch_related, Prefetch objects, and annotations correctly.
- Run Schema Changes on Large Tables in Django Safely
Change large PostgreSQL tables from Django migrations without outages: lock_timeout, concurrent indexes, NOT VALID constraints, and batched backfills.
- Find Slow Django Queries with pg_stat_statements
Enable pg_stat_statements for a Django app, rank queries by total time, trace them back to ORM code, confirm plans with EXPLAIN ANALYZE, and fix them with indexes and better querysets.
- PostgreSQL Point-in-Time Recovery for Django
Set up point-in-time recovery for a Django PostgreSQL database with pgBackRest: WAL archiving, full and incremental backups, restoring to a timestamp before a bad migration, and managed-service PITR.
- Add Database Indexes in Django Without Locking Tables
Add PostgreSQL indexes to large tables in a live Django app without blocking writes: AddIndexConcurrently in non-atomic migrations, handling failed concurrent builds, finding missing indexes, and removing unused ones safely.
- Deploy Django Across Multiple Regions
Plan a multi-region Django deployment: decide between active-passive and active-active, route users with latency or geo DNS, place PostgreSQL primaries and read replicas, handle sessions, caches, Celery, and media per region, and test regional failover.
- Use the Transactional Outbox Pattern With Django and Celery
Stop losing or duplicating side effects when Django saves data and enqueues Celery tasks: compare transaction.on_commit with a transactional outbox table, write outbox rows atomically, relay them with a worker using SKIP LOCKED, and make consumers idempotent.
- Run a Django Data Migration on a Large Table
Backfill or transform millions of rows in Django without long locks or failed deploys: move heavy data changes out of schema migrations, batch updates by primary key, run them as resumable management commands or Celery jobs, and keep code compatible during the backfill.
- Migrate a Django Integer Primary Key to BigInt Without Downtime
Convert a Django AutoField primary key to BigAutoField before it overflows: estimate time to exhaustion, avoid the table-rewriting ALTER on big tables, add a new bigint column with triggers, backfill, swap keys and foreign keys, and handle sequences.
- Rotate the Django Database Password Without Downtime
Rotate PostgreSQL or MySQL credentials used by a Django app without outages: use two database roles or dual passwords, update secrets in the right order, restart web, Celery, and cron processes, handle PgBouncer, and automate rotation with Secrets Manager.
Check it
Review lists to run before launch or after a change.
- PostgreSQL Production Checklist for Django
Review PostgreSQL for a production Django app: roles and TLS, connections and pooling, memory settings, autovacuum, slow query visibility, backups, and upgrades.
- Checklist for Moving a Django Database to Managed PostgreSQL
Move a Django app’s self-hosted PostgreSQL to RDS, Cloud SQL, Azure, Neon, or another managed service: check versions and extensions, choose dump/restore or logical replication, handle roles and ownership, plan cutover and rollback, and verify Django afterwards.
- Django Multi-Tenant SaaS Production Checklist
A production checklist for multi-tenant Django SaaS apps: choose shared tables, schemas, or databases, enforce tenant isolation in queries and caches, scope files and background jobs, handle custom domains, run migrations per tenant, and test for cross-tenant leaks.
Fix it
Errors and symptoms, each traced to a cause and a fix.
- Fix Database Connection Errors in Django Production
Database connection errors in Django production usually appear right after a deploy, after a restart, or after an infrastructure change such as rotating secrets, moving PostgreS...
- Fix PostgreSQL "Too Many Connections" in Django
Fix PostgreSQL sorry, too many clients already errors from Django: count connections by source, fix CONN_MAX_AGE and worker math, find idle leaks, and add pooling.
- Fix "database is locked" with SQLite in Django
Fix SQLite database is locked errors in Django: concurrent writes, long transactions, WAL mode, timeouts, IMMEDIATE transactions, and when to migrate.
- Fix PostgreSQL "password authentication failed" for Django
Fix FATAL: password authentication failed for user in Django: read the server-side reason, URL-encode special characters, reload environment variables, fix Docker volume passwords, and pg_hba methods.
- Fix PostgreSQL SSL Connection Errors in Django
Fix Django PostgreSQL TLS errors: no pg_hba.conf entry with no encryption, server does not support SSL, root.crt missing for verify-full, certificate verify failed, and SSL SYSCALL EOF drops.
- Fix Idle in Transaction Connections from Django
Find and fix PostgreSQL sessions stuck 'idle in transaction' from Django: identify the source with application_name, fix atomic blocks around slow work, and set idle_in_transaction_session_timeout.
- Fix "cannot execute in a read-only transaction" in Django
Fix PostgreSQL 'cannot execute INSERT in a read-only transaction' in Django: writes sent to a replica or reader endpoint, stale connections after failover, database routers, and read-only settings.
- Fix PostgreSQL "deadlock detected" in Django
Fix PostgreSQL deadlock detected errors in Django apps: read the deadlock log, lock rows in a consistent order with select_for_update, shorten transactions, and retry the transactions that lose.
- Fix "duplicate key value violates unique constraint" After a Restore
Fix Django IntegrityError duplicate key value violates unique constraint on the id column after loaddata, a restore, or a migration from another database: reset PostgreSQL sequences with sqlsequencereset or setval.
- Fix PostgreSQL "role does not exist" and "database does not exist"
Fix Django errors FATAL role does not exist and FATAL database does not exist when connecting to PostgreSQL: create the role and database, match the names in settings, and avoid connecting as the Linux user by accident.
- Fix PostgreSQL "Peer authentication failed" for Django
Fix Django FATAL Peer authentication failed for user when connecting to local PostgreSQL: understand peer versus password auth in pg_hba.conf, connect over TCP with HOST=localhost, or map the Linux user correctly.
- Fix "permission denied for schema public" on PostgreSQL 15+
Fix Django migrate failing with permission denied for schema public on PostgreSQL 15 and newer: make the app role own the database or schema, grant CREATE on public, and set up roles correctly on managed databases.
- Fix MySQL "Access denied for user" in Django
Fix Django OperationalError 1045 Access denied for user when connecting to MySQL or MariaDB: match the user host part, use TCP instead of the socket, fix authentication plugins, and grant privileges on the right database.
- Fix mysqlclient Install Errors (mysql_config not found)
Fix pip install mysqlclient failures for Django: mysql_config not found, pkg-config cannot find mysqlclient, and missing Python.h, on Ubuntu, Debian, RHEL, Alpine, macOS, and in Docker builds.
- Fix "MySQL server has gone away" (2006) in Django
Fix Django OperationalError 2006 MySQL server has gone away and 2013 lost connection: align CONN_MAX_AGE with wait_timeout, enable CONN_HEALTH_CHECKS, close connections in long-running scripts, and raise max_allowed_packet.
- Fix MySQL "Incorrect string value" With utf8mb4
Fix Django DataError 1366 Incorrect string value when saving emoji or other 4-byte characters to MySQL: convert databases, tables, and columns to utf8mb4, set the connection charset, and handle index length limits.
- Fix "value too long for type character varying" in Django
Fix Django DataError value too long for type character varying(N) on PostgreSQL: find the field and the input, raise max_length with a safe migration, validate in forms and serializers, and understand why SQLite never complained.
- Fix Django "Are Time Zone Definitions for Your Database Installed?"
Fix the Django ValueError saying the database returned an invalid datetime value and asking whether time zone definitions for your database are installed: load MySQL or MariaDB time zone tables, including on Docker, RDS, and Cloud SQL.
- Fix PostgreSQL "No pg_hba.conf Entry for Host" in Django
Fix the PostgreSQL FATAL error no pg_hba.conf entry for host when Django connects: add the right host or hostssl rule, match the client address and auth method, reload PostgreSQL, and handle Docker networks and SSL-only managed databases.
- Fix PostgreSQL "fe_sendauth: no password supplied" in Django
Fix the PostgreSQL error fe_sendauth no password supplied in Django: find why the password is empty, check DATABASE_URL parsing and environment loading in systemd, Docker, and cron, escape special characters, and use .pgpass or secrets safely.
- Fix "Server Closed the Connection Unexpectedly" in Django and PostgreSQL
Fix the Django OperationalError server closed the connection unexpectedly: find whether PostgreSQL crashed, a firewall or load balancer killed idle connections, or a failover happened, then tune CONN_MAX_AGE, CONN_HEALTH_CHECKS, and TCP keepalives.
- Fix "Canceling Statement Due to Conflict With Recovery" on Django Replicas
Fix the PostgreSQL error canceling statement due to conflict with recovery when Django reads from a hot standby: understand vacuum conflicts, tune max_standby_streaming_delay and hot_standby_feedback, and route long reports to the right replica.
- Fix PostgreSQL "Could Not Resize Shared Memory Segment" in Docker
Fix the PostgreSQL error could not resize shared memory segment No space left on device in Docker and Kubernetes: raise /dev/shm with shm_size or a memory-backed emptyDir, and tune parallel query and work_mem for Django workloads.
- Fix PostgreSQL "Database Is Being Accessed by Other Users" in Django
Fix the PostgreSQL error database is being accessed by other users when Django tests, restores, or resets drop a database: find the open sessions, stop app processes and pools, terminate backends, or use DROP DATABASE WITH (FORCE).
- Fix "Current Transaction Is Aborted, Commands Ignored" in Django
Fix the PostgreSQL InternalError current transaction is aborted, commands ignored until end of transaction block in Django: find the first failing query, use atomic savepoints around expected errors, and clean up after exceptions in tests and workers.
- Fix PostgreSQL WAL Files Filling the Disk on a Django Server
Fix PostgreSQL pg_wal growing until the disk is full on a Django database: find inactive replication slots, broken WAL archiving, or high max_wal_size, free space safely without deleting WAL by hand, and add alerts so it does not happen again.
- Fix PostgreSQL Collation Version Mismatch After an OS Upgrade
Fix the PostgreSQL warning database has a collation version mismatch after upgrading Ubuntu, Debian, or a Docker base image under a Django database: reindex affected text indexes, refresh the collation version, and avoid silent index corruption.
- Fix "Permission Denied to Create Extension" in Django Migrations
Fix the PostgreSQL error permission denied to create extension when Django migrations add pg_trgm, unaccent, hstore, citext, or PostGIS: create extensions as an admin once, use trusted extensions, and handle RDS, Cloud SQL, Azure, and Supabase.
- Fix MySQL "Specified Key Was Too Long" in Django Migrations
Fix the MySQL error 1071 Specified key was too long; max key length is 767 or 3072 bytes in Django migrations: understand utf8mb4 index limits, use InnoDB DYNAMIC rows, shorten indexed CharFields, or index a prefix.
- Fix MySQL Error 1040 "Too Many Connections" in Django
Fix MySQL error 1040 Too many connections from Django: count connections per Gunicorn worker, Celery process, and thread, tune max_connections and wait_timeout, set CONN_MAX_AGE sensibly, and add ProxySQL or RDS Proxy when apps scale out.
- Fix MySQL "Lock Wait Timeout Exceeded" in Django
Fix MySQL error 1205 Lock wait timeout exceeded; try restarting transaction in Django: find the blocking transaction, shorten long atomic blocks, avoid gap locks from unindexed filters, and handle select_for_update and migrations safely.
- Fix Django SQLite "Attempt to Write a Readonly Database"
Fix Django SQLite errors attempt to write a readonly database and unable to open database file in production: give the app user write access to the database file and its directory, use an absolute path, and handle Docker volumes and read-only images.
- Fix Django InterfaceError: Connection Already Closed
Fix django.db.utils.InterfaceError connection already closed in Celery tasks, management commands, and long-running scripts: call close_old_connections, set CONN_MAX_AGE and CONN_HEALTH_CHECKS, and handle database restarts and idle timeouts.
- Fix GeoDjango "Could Not Find the GDAL Library" in Production and Docker
Fix the GeoDjango ImproperlyConfigured error could not find the GDAL library (tried gdal, GDAL...) on servers and in Docker: install GDAL, GEOS, and PROJ system packages, set GDAL_LIBRARY_PATH when needed, and match library versions to Django.
- Fix psycopg Installation Errors on Django Servers
Fix psycopg and psycopg2 install failures on servers and Docker images: pg_config not found, missing libpq, binary versus source builds, and missing wheels.
- Fix Django Cannot Connect to Postgres in Docker Compose
Fix Django connection errors to PostgreSQL in Docker Compose: localhost versus service names, readiness health checks, credentials in volumes, networks, and ports.
- Fix Django Migrations Hanging on a Database Lock
Fix a Django migrate command that hangs during deploy: find the blocking PostgreSQL session with pg_blocking_pids, stop the lock queue from taking the site down, and set lock_timeout.
- Fix "relation does not exist" in Django Production
Fix ProgrammingError: relation does not exist (and SQLite 'no such table') in Django production: unapplied or uncommitted migrations, the wrong database, faked migrations, and import-time queries.
- Fix Celery Tasks Raising DoesNotExist for Newly Created Objects
Fix Celery tasks that raise Model.DoesNotExist for an object the view just created: queue tasks with transaction.on_commit, understand ATOMIC_REQUESTS, read replicas, and pass IDs instead of model instances.
- Fix a Slow Django Admin on Large Tables
Speed up Django admin changelists and forms on tables with millions of rows: avoid full counts, add list_select_related, use autocomplete and raw ID fields, index search and ordering, and limit filters.
- Fix Django "received a naive datetime" Warnings
Fix the Django RuntimeWarning DateTimeField received a naive datetime while time zone support is active: use timezone.now, make parsed and imported datetimes aware, and set USE_TZ, TIME_ZONE, and database time zones correctly.
- Make Docker Compose Wait for PostgreSQL Before Django Starts
Stop Django failing with could not connect to server or connection refused when Docker Compose starts it before PostgreSQL is ready: use depends_on with service_healthy, pg_isready health checks, and retry logic in the entrypoint.
- Fix Django Tests That Pass Locally but Fail in CI
Fix Django test suites that pass on your machine but fail in GitHub Actions or GitLab CI: PostgreSQL service containers and health checks, missing settings and secrets, static files manifest errors, time zones, and test ordering.
- Fix Wrong Times in Django Production: TIME_ZONE and USE_TZ
Fix Django showing times hours off in production: understand USE_TZ and UTC storage, set TIME_ZONE correctly, activate per-user time zones, render local times in templates, and stop cron and Celery schedules from drifting.
- Fix "SSL Error: Decryption Failed or Bad Record MAC" in Celery and Gunicorn
Fix PostgreSQL errors SSL error decryption failed or bad record mac and SSL SYSCALL error EOF detected in Celery workers or preloaded Gunicorn: stop sharing database connections across fork, close connections before forking, and use per-process connections.
Learning paths through this topic
- Your first production deployment on a VPSFrom a fresh Ubuntu server to a Django site on HTTPS, with the settings and checks that keep it safe.
- Releases without downtimeScript the release, make migrations backward compatible, and switch, verify, or roll back without users noticing.
- Keeping it runningLogs, errors, metrics, uptime, backups, and the runbooks you need before the first incident.
- Making Django fastMeasure first, then fix queries, caching, workers, and delivery, and prove it with a load test.