django.db.utils.OperationalError: server closed the connection unexpectedly

2,765 views
Skip to first unread message

Bobby Paul

unread,
May 31, 2017, 7:44:29 AM5/31/17
to Django users
Dear All,

I am getting this error message while trying to install psql database.

 File "setup.py", line 18, in <module>
    execute_from_command_line(['manage.py','migrate'])
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 93, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/loader.py", line 191, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
    self.ensure_connection()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/local/bin/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
==========
DATABASES_DEFAULT = {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'litdb',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '80',
}

How to sort this issue?

Kind Regards
Bobby Paul

Antonis Christofides

unread,
May 31, 2017, 7:57:02 AM5/31/17
to django...@googlegroups.com

Hello,

DATABASES_DEFAULT = {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'litdb',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '80',
}

First, if this means what I think it means, it's a very nasty way to define your database. Instead, do this:

DATABASES = {
    'default': {
        'ENGINE': ...,
        ...,
    }
}

Now, for what you are asking, PostgreSQL does not listen on port 80; more likely it's listening on port 5432.

Regards,

A.

Antonis Christofides
http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b07acc86-a2a9-4fe7-9004-0f7a90fe4100%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bobby Paul

unread,
May 31, 2017, 9:10:57 AM5/31/17
to Django users
Dear Antonis,

Thank you very much for your quick response.
Sorry, I am newer in this field. I was trying to install LitDB (http://www.ikmb.uni-kiel.de/litdb)
I changed the settings as what your suggestion, but not happened.

with port number 5432, it showing
 Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

Is there any other settings i need to change?
Thanks and Regards
Bobby Paul

Antonis Christofides

unread,
May 31, 2017, 9:24:52 AM5/31/17
to django...@googlegroups.com

It's because you don't have PostgreSQL installed. The LitDB instructions say, among other things, "Make sure that you have a PostgreSQL database running and that you have permissions to create tables in that database".

The LitDB installation instructions are quite brief, which is probably fine for someone who knows Django already, but you're in for a rough ride. What operating system are you running? In Debian/Ubuntu you can install postgresql with "apt install postgresql". Are you executing manage.py as root?

Antonis Christofides
http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Bobby Paul

unread,
Jun 1, 2017, 3:21:50 AM6/1/17
to Django users
Thank you Antonis,
Yeah, We have installed postgresql-8.4.20-7.el6.x86_64

Now we are checking the permission. Will touch you once it done.

Thanks,

Bobby Paul
On Wednesday, May 31, 2017 at 5:14:29 PM UTC+5:30, Bobby Paul wrote:
Reply all
Reply to author
Forward
0 new messages