Underoos
Underoos

Reputation: 5190

Unable to apply Django migration in Postgres DB

In Django app, I'm using Postgres DB. I have two tables where one of them has 76 million records and the other 8.2 million.

I have created a new migration file where in I'm adding a new column to a table in an app and setting default value to 0.

My database is hosted on Ubuntu EC2 instance which has RAM of 8 GB.

When I try to apply the migration using python manage.py migrate app_name migration_file_name, it's throwing below error:

File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) django.db.utils.OperationalError: SSL SYSCALL error: EOF detected

I have gone through this solution Postgres SSL SYSCALL error: EOF detected with python and psycopg But not sure if it's memory issue or something else.

Python: 2.7.12
Django 1.11.15
Ubuntu: 18.04
Postgres DB: 10.7

What else could be the issue?

Upvotes: 0

Views: 521

Answers (2)

J-E Casta
J-E Casta

Reputation: 196

Adding new column with default value trig a table reconstruction. To avoid that with big table, you can create you migrations in 3 times.

  • Firstly, Create a migration file to add NULLABLE column without default value.
  • Secondly, Create an empty migration that fill this new empty value with excepting default value to all instance with null=True
  • Thirdly, Create a migration that define your column is not nullable with a defaut value

Upvotes: -1

Your query might too large - too many operations. This causes the system to run out of memory.

Upvotes: 3

Related Questions