Django+Celery+postgresql_psycopg2 connection already closed error - django

After forcefully killing (kill -9) the idle db connections. Celery log showing the below error
[2016-03-08 19:28:04,765: CRITICAL/MainProcess] Task users.tasks.refresh_trend_buzz_messages[85a2430a-9a39-4979-b99d-fcaae86b3ba1] INTERNAL ERROR: InterfaceError('connection already closed',)
Traceback (most recent call last):
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/app/trace.py", line 253, in trace_task
I, R, state, retval = on_error(task_request, exc, uuid)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/app/trace.py", line 201, in on_error
R = I.handle_error_state(task, eager=eager)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/app/trace.py", line 85, in handle_error_state
}[self.state](task, store_errors=store_errors)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/app/trace.py", line 118, in handle_failure
req.id, exc, einfo.traceback, request=req,
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/backends/base.py", line 120, in mark_as_failure
traceback=traceback, request=request)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/backends/base.py", line 251, in store_result
request=request, **kwargs)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/backends/database.py", line 29, in _store_result
traceback=traceback, children=self.current_task_children(request),
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/managers.py", line 42, in _inner
return fun(*args, **kwargs)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/managers.py", line 181, in store_result
'meta': {'children': children}})
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/managers.py", line 87, in update_or_create
return get_queryset(self).update_or_create(**kwargs)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/managers.py", line 70, in update_or_create
obj, created = self.get_or_create(**kwargs)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 373, in get_or_create
return self.get(**lookup), False
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 780, in execute_sql
cursor = self.connection.cursor()
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 159, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 131, in _cursor
return self.create_cursor()
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 131, in _cursor
return self.create_cursor()
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 139, in create_cursor
cursor = self.connection.cursor()
InterfaceError: connection already closed
I'm using Django==1.6.1, celery==3.1.10, django-celery==3.1.10 and psycopg2==2.4.1
How can I fix the error ?

This is the expected behaviour. Each celery worker will open a connection to the database and try to reuse it to avoid the overhead of negotiation every time. By killing the database processes you close the connection, hence the error.
What are you trying to achieve by killing the database processes?

You need to adjust max_connections in your PostgreSQL configuration.
You will need at least 1 connection for each celery worker plus enough for any other client code.

Related

Django on Ubuntu giving libpq version 10 error [duplicate]

This question already has answers here:
How can I solve Postgresql SCRAM authentication problem?
(17 answers)
SCRAM authentication requires libpq version 10 or above in
(3 answers)
Closed 10 days ago.
I am trying to setup a Django website on linux ubuntu with postgresql, gunicorn and nginx.
However every time I try to start the development server I get this following error:
Traceback (most recent call last):
File "/home/ubuntu/personalserver/manage.py", line 22, in <module>
main()
File "/home/ubuntu/personalserver/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 114, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 58, in __init__
self.build_graph()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor
return self._cursor()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor
self.ensure_connection()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 281, in ensure_connection
with self.wrap_database_errors:
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
self.connect()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: SCRAM authentication requires libpq version 10 or above
I have already tried the following fix: https://stackoverflow.com/a/62808487/15540615
such that this is my conf file:
and this is my password encryption setting:

What could be the problem of django run error

My Django project used to work well the day before but it was not working when I run the next day. The following is the error I am getting. I didn't change anything and yet it did not work. When I run my project, the following error occurs. The project name is 'carpooling' and the the database user is 'Jigme'. I think the last line points the error towards the database which I didn't change anything.
Please help me. Your help will be appreciated.
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\base.py", line 234, in get_new_connection
return Database.connect(**conn_params)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\__init__.py", line 130, in Connect
return Connection(*args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\connections.py", line 185, in __init__
super().__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1044, "Access denied for user 'jigme'#'%' to database 'carpooling'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\threading.py", line 950, in _bootstrap_inner
self.run()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\threading.py", line 888, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
self.check_migrations()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 459, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\loader.py", line 53, in __init__
self.build_graph()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\loader.py", line 216, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\recorder.py", line 77, in applied_migrations
if self.has_table():
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
return self._cursor()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 235, in _cursor
self.ensure_connection()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\base.py", line 234, in get_new_connection
return Database.connect(**conn_params)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\__init__.py", line 130, in Connect
return Connection(*args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\connections.py", line 185, in __init__
super().__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1044, "Access denied for user 'jigme'#'%' to database 'carpooling'")

Can’t connect to MySQL while upgrading Bitnami Review Board by rb-site

I am trying to upgrade Bitnami ReviewBoard from 3.0.1 to 3.0.2 . I have done the venv/bin/easy_install -U ReviewBoard. But when I try venv/bin/rb-site upgrade installdir/rb-sites/reviewboard/, I obtained an error of django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/opt/reviewboard-3.0.1-0/mysql/tmp/mysql.sock' (2)").
Following is the detailed log:
bash-4.2# venv/bin/rb-site upgrade ./rb-sites/reviewboard/
Traceback (most recent call last):
File "venv/bin/rb-site", line 11, in <module>
load_entry_point('ReviewBoard==3.0.2', 'console_scripts', 'rb-site')()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 1965, in main
command.run()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 1742, in run
static_media_upgrade_needed = site.get_static_media_upgrade_needed()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 503, in get_static_media_upgrade_needed
siteconfig = SiteConfiguration.objects.get_current()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/Djblets-1.0.2-py2.7.egg/djblets/siteconfig/managers.py", line 50, in g et_current
site = Site.objects.get_current()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/contrib/sites/models.py", line 47, in get_current
current_site = self.get(pk=sid)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/query.py", line 304, in get
num = len(clone)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/query.py", line 857, in _fetch_all
self._result_cache = list(self.iterator())
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/sql/compiler.py", line 713, in results_iter
for rows in self.execute_sql(MULTI):
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/sql/compiler.py", line 785, in execute_sql
cursor = self.connection.cursor()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 162, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 132, in _cursor
self.ensure_connection()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 115, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/mysql/base.py", line 435, in get_new_connection
conn = Database.connect(**conn_params)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server th rough socket '/opt/reviewboard-3.0.1-0/mysql/tmp/mysql.sock' (2)")
bash-4.2# pwd
/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs
bash-4.2# /opt/reviewboard-3.0.1-0/ctlscript.sh status
apache not running
mysql not running
memcached not running
bash-4.2# sudo venv/bin/rb-site upgrade ./rb-sites/reviewboard/
Cannot locate wrapped file
bash-4.2# venv/bin/rb-site upgrade ./rb-sites/reviewboard/
Traceback (most recent call last):
File "venv/bin/rb-site", line 11, in <module>
load_entry_point('ReviewBoard==3.0.2', 'console_scripts', 'rb-site')()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 1965, in main
command.run()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 1742, in run
static_media_upgrade_needed = site.get_static_media_upgrade_needed()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 503, in get_static_media_upgrade_needed
siteconfig = SiteConfiguration.objects.get_current()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/Djblets-1.0.2-py2.7.egg/djblets/siteconfig/managers.py", line 50, in get_current
site = Site.objects.get_current()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/contrib/sites/models.py", line 47, in get_current
current_site = self.get(pk=sid)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/query.py", line 304, in get
num = len(clone)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/query.py", line 857, in _fetch_all
self._result_cache = list(self.iterator())
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
for rows in self.execute_sql(MULTI):
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 785, in execute_sql
cursor = self.connection.cursor()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 162, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 132, in _cursor
self.ensure_connection()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 115, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 435, in get_new_connection
conn = Database.connect(**conn_params)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/opt/reviewboard-3.0.1-0/mysql/tmp/mysql.sock' (2)")
All operations are executed in the Bitnami Console.
Environemnts:
bash-4.2# /opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/bin/rb-site --version
rb-site 3.0.2
Python 2.7.14 (default, Dec 12 2017, 10:27:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
Installed to /opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard
Currently, if I start all the required services and visite the review board, the following page is showed:
Thank you in advance!!
It was my stupid mistake! I thought upgrading should stop the MySQL service. It works perfectly after I started the MySQL service.

InterfaceError: connection already closed

I'm running a celery(4.1.0) task with django(1.11.6) using psycopg2(2.7.3), getting these errors after 5-6 hour of deploying the app on production. One of the related issue on Django issue tickets. Tried various solution of reconnecting the connection using try and except, handling InterfaceError. Any help will be appreciated. Checked and Applied some of the solutions, but nothing seems to be working, Celery Worker Database Connection Pooling
Traceback
InterfaceError: connection already closed
File "billiard/pool.py", line 358, in workloop
result = (True, prepare_result(fun(*args, **kwargs)))
File "celery/app/trace.py", line 537, in _fast_trace_task
uuid, args, kwargs, request,
File "celery/app/trace.py", line 482, in trace_task
I, _, _, _ = on_error(task_request, exc, uuid)
File "celery/app/trace.py", line 330, in on_error
task, request, eager=eager, call_errbacks=call_errbacks,
File "celery/app/trace.py", line 164, in handle_error_state
call_errbacks=call_errbacks)
File "celery/app/trace.py", line 212, in handle_failure
task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
File "telemetry/tasks.py", line 29, in on_failure
save_failed_task(self, exc, task_id, args, kwargs, einfo)
File "telemetry/celery_failure.py", line 46, in save_failed_task
existing_task_first = existing_task.first()
File "django/db/models/query.py", line 564, in first
objects = list((self if self.ordered else self.order_by('pk'))[:1])
File "django/db/models/query.py", line 250, in __iter__
self._fetch_all()
File "django/db/models/query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "django/db/models/sql/compiler.py", line 882, in execute_sql
cursor = self.connection.cursor()
File "django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "django/db/backends/base/base.py", line 231, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "django/db/backends/base/base.py", line 231, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "django/db/backends/postgresql/base.py", line 220, in create_cursor
cursor = self.connection.cursor()

Django OperationalError: could not fork new process for connection

I've started getting this error on the production environment this morning, after getting Django-storages, Boto, and Django-compressor working to put static files on S3 yesterday, though I don't know if that is related...
OperationalError: could not fork new process for connection: Cannot allocate memory
could not fork new process for connection: Cannot allocate memory
could not fork new process for connection: Cannot allocate memory
Stacktrace (most recent call last):
File "django/core/handlers/base.py", line 89, in get_response
response = middleware_method(request)
File "reversion/middleware.py", line 17, in process_request
if hasattr(request, "user") and request.user.is_authenticated():
File "django/utils/functional.py", line 184, in inner
self._setup()
File "django/utils/functional.py", line 248, in _setup
self._wrapped = self._setupfunc()
File "django/contrib/auth/middleware.py", line 16, in <lambda>
request.user = SimpleLazyObject(lambda: get_user(request))
File "django/contrib/auth/middleware.py", line 8, in get_user
request._cached_user = auth.get_user(request)
File "django/contrib/auth/__init__.py", line 98, in get_user
user_id = request.session[SESSION_KEY]
File "django/contrib/sessions/backends/base.py", line 39, in __getitem__
return self._session[key]
File "django/contrib/sessions/backends/base.py", line 165, in _get_session
self._session_cache = self.load()
File "django/contrib/sessions/backends/db.py", line 19, in load
expire_date__gt=timezone.now()
File "django/db/models/manager.py", line 131, in get
return self.get_query_set().get(*args, **kwargs)
File "django/db/models/query.py", line 361, in get
num = len(clone)
File "django/db/models/query.py", line 85, in __len__
self._result_cache = list(self.iterator())
File "django/db/models/query.py", line 291, in iterator
for row in compiler.results_iter():
File "django/db/models/sql/compiler.py", line 763, in results_iter
for rows in self.execute_sql(MULTI):
File "django/db/models/sql/compiler.py", line 817, in execute_sql
cursor = self.connection.cursor()
File "django/db/backends/__init__.py", line 308, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
self.connection = Database.connect(**conn_params)
File "psycopg2/__init__.py", line 178, in connect
return _connect(dsn, connection_factory=connection_factory, async=async)
I am deploying the site on Heroku. It works for a bit after I restart the application, but stops working again after a few minutes.
Any ideas as to what might be causing this?
I encountered the same problem trying to set up a simple django web application with a postgresql database on heroku and managed to solve it.
I don't fully understand the error but the fix is fairly simple: when you are passing python lists created by queries to your database, you need to limit the size of the list.
So for example if you are passing as context the following list:
set_list = userSetTable.objects.all()
return render(request, 'fc/user.html', {'set_list': set_list,})
That will cause an error because set_list might be really big. You need to specify a maximum size:
set_list = userSetTable.objects.all()[0:20]
So in a real-world application, you might want to display the list as page results or whatever... you get the point.