Thread: : Getting error while starting the server

: Getting error while starting the server

From
VENKTESH GUTTEDAR
Date:
Hello,

    i have Postgresql 9.3.5 installed and django 1.7 and till now it was working fine.

    But now i am getting the following error while starting the server to run my app :

   
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0xb2da8074>
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py", line 133, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py", line 122, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 134, in get_new_connection
    return Database.connect(**conn_params)
  File "/usr/local/lib/python3.4/dist-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not translate host name "localhost" to address: Name or service not known


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/utils/autoreload.py", line 222, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/runserver.py", line 107, in inner_run
    self.check_migrations()
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/runserver.py", line 159, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 17, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py", line 48, in __init__
    self.build_graph()
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py", line 183, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.get_table_list(self.connection.cursor()):
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py", line 165, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py", line 138, in _cursor
    self.ensure_connection()
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py", line 133, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 658, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py", line 133, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py", line 122, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 134, in get_new_connection
    return Database.connect(**conn_params)
  File "/usr/local/lib/python3.4/dist-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not translate host name "localhost" to address: Name or service not known


can anyone tell me what is the reason for this error.?

--
Regards :
Venktesh Guttedar.

Re: : Getting error while starting the server

From
Adrian Klaver
Date:
On 02/22/2015 11:02 PM, VENKTESH GUTTEDAR wrote:
> Hello,
>
>      i have Postgresql 9.3.5 installed and django 1.7 and till now it
> was working fine.
>
>      But now i am getting the following error while starting the server
> to run my app :
>
>
> Unhandled exception in thread started by <function
> check_errors.<locals>.wrapper at 0xb2da8074>
> Traceback (most recent call last):
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 133, in ensure_connection
>      self.connect()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 122, in connect
>      self.connection = self.get_new_connection(conn_params)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py",
> line 134, in get_new_connection
>      return Database.connect(**conn_params)
>    File "/usr/local/lib/python3.4/dist-packages/psycopg2/__init__.py",
> line 164, in connect
>      conn = _connect(dsn, connection_factory=connection_factory,
> async=async)
> psycopg2.OperationalError: could not translate host name "localhost" to
> address: Name or service not known
>
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>    File
> "/usr/local/lib/python3.4/dist-packages/django/utils/autoreload.py",
> line 222, in wrapper
>      fn(*args, **kwargs)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/runserver.py",
> line 107, in inner_run
>      self.check_migrations()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/runserver.py",
> line 159, in check_migrations
>      executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py",
> line 17, in __init__
>      self.loader = MigrationLoader(self.connection)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py",
> line 48, in __init__
>      self.build_graph()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py",
> line 183, in build_graph
>      self.applied_migrations = recorder.applied_migrations()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py",
> line 59, in applied_migrations
>      self.ensure_schema()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py",
> line 49, in ensure_schema
>      if self.Migration._meta.db_table in
> self.connection.introspection.get_table_list(self.connection.cursor()):
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 165, in cursor
>      cursor = self.make_debug_cursor(self._cursor())
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 138, in _cursor
>      self.ensure_connection()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 133, in ensure_connection
>      self.connect()
>    File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py",
> line 94, in __exit__
>      six.reraise(dj_exc_type, dj_exc_value, traceback)
>    File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py",
> line 658, in reraise
>      raise value.with_traceback(tb)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 133, in ensure_connection
>      self.connect()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 122, in connect
>      self.connection = self.get_new_connection(conn_params)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py",
> line 134, in get_new_connection
>      return Database.connect(**conn_params)
>    File "/usr/local/lib/python3.4/dist-packages/psycopg2/__init__.py",
> line 164, in connect
>      conn = _connect(dsn, connection_factory=connection_factory,
> async=async)
> django.db.utils.OperationalError: could not translate host name
> "localhost" to address: Name or service not known
>
>
> can anyone tell me what is the reason for this error.?

What OS and what version?

Would be nice to see the DSN you are using?

Though I suspect is the issue is that localhost is not defined in your
hosts file.

Have you tried using 127.0.0.1 instead of localhost to test?

>
> --
> Regards :
> Venktesh Guttedar.
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: : Getting error while starting the server

From
Adrian Klaver
Date:
On 02/22/2015 11:02 PM, VENKTESH GUTTEDAR wrote:
> Hello,
>
>      i have Postgresql 9.3.5 installed and django 1.7 and till now it
> was working fine.
>
>      But now i am getting the following error while starting the server
> to run my app :
>
>
> Unhandled exception in thread started by <function
> check_errors.<locals>.wrapper at 0xb2da8074>
> Traceback (most recent call last):
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 133, in ensure_connection
>      self.connect()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 122, in connect
>      self.connection = self.get_new_connection(conn_params)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py",
> line 134, in get_new_connection
>      return Database.connect(**conn_params)
>    File "/usr/local/lib/python3.4/dist-packages/psycopg2/__init__.py",
> line 164, in connect
>      conn = _connect(dsn, connection_factory=connection_factory,
> async=async)
> psycopg2.OperationalError: could not translate host name "localhost" to
> address: Name or service not known
>
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>    File
> "/usr/local/lib/python3.4/dist-packages/django/utils/autoreload.py",
> line 222, in wrapper
>      fn(*args, **kwargs)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/runserver.py",
> line 107, in inner_run
>      self.check_migrations()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/runserver.py",
> line 159, in check_migrations
>      executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py",
> line 17, in __init__
>      self.loader = MigrationLoader(self.connection)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py",
> line 48, in __init__
>      self.build_graph()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py",
> line 183, in build_graph
>      self.applied_migrations = recorder.applied_migrations()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py",
> line 59, in applied_migrations
>      self.ensure_schema()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py",
> line 49, in ensure_schema
>      if self.Migration._meta.db_table in
> self.connection.introspection.get_table_list(self.connection.cursor()):
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 165, in cursor
>      cursor = self.make_debug_cursor(self._cursor())
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 138, in _cursor
>      self.ensure_connection()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 133, in ensure_connection
>      self.connect()
>    File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py",
> line 94, in __exit__
>      six.reraise(dj_exc_type, dj_exc_value, traceback)
>    File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py",
> line 658, in reraise
>      raise value.with_traceback(tb)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 133, in ensure_connection
>      self.connect()
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py",
> line 122, in connect
>      self.connection = self.get_new_connection(conn_params)
>    File
> "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py",
> line 134, in get_new_connection
>      return Database.connect(**conn_params)
>    File "/usr/local/lib/python3.4/dist-packages/psycopg2/__init__.py",
> line 164, in connect
>      conn = _connect(dsn, connection_factory=connection_factory,
> async=async)
> django.db.utils.OperationalError: could not translate host name
> "localhost" to address: Name or service not known
>
>
> can anyone tell me what is the reason for this error.?

Should have added, this is a generic connection error, below Django and
even psycopg2 for that matter. To solve I would work up the ladder:

1) Try a psql connection. My guess is it will fail.

2) If it does not, try a straight psycopg2 connection.

3) If step 2 does not fail, then try the Django app.


>
> --
> Regards :
> Venktesh Guttedar.
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: : Getting error while starting the server

From
Adrian Klaver
Date:
On 02/23/2015 01:04 AM, VENKTESH GUTTEDAR wrote:

CCing list.

> Hello,
>
>      I have ubuntu 14.04, and i am trying it on my local machine.
>
>      when i tried "psql", i am getting the following error :
>          - psql: could not connect to server: No such file or directory
>      Is the server running locally and accepting
>      connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
>
>      What to do next.?
>

First show us what you are using for connection parameters(DSN)?

Second the above is a different error message. This indicates that
either the Postgres is not running or is running with a different port
then the default of 5432. It also indicates that you are not using -h
localhost, but are trying to connect via a socket.


So first I would look at ps ax | grep post to see if there is a Postgres
instance running?

If there is then you will need to find and look in postgresql.conf to
see what port Postgres is set up on. The port setting is at the top of
the file.

If, as I suspect, Postgres is not actually running then you need to
start it.


>
> --
> Regards :
> Venktesh Guttedar.
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: : Getting error while starting the server

From
Adrian Klaver
Date:
On 02/23/2015 01:14 AM, VENKTESH GUTTEDAR wrote:
> i am facing this issue after inatalling php and mysql on my system.
>
> is it because of that.?

Should not be. I have Postgres and MySQL installed on a 14.04 machine
with no issues.

The caveat is, how did you install Postgres initially and PHP/MySQL
recently?

> if yes then what i should do to get working psql.?

Per my previous post, try restarting it if it is not already running.

>



--
Adrian Klaver
adrian.klaver@aklaver.com


Re: : Getting error while starting the server

From
Raghavendra
Date:

    return Database.connect(**conn_params)
  File "/usr/local/lib/python3.4/dist-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not translate host name "localhost" to address: Name or service not known

 
​I guess problem with your server name resolution. ​Its worth checking as said, using psql -h localhost or ping localhost. 

---
Regards,
Raghavendra
EnterpriseDB Corporation

Fwd: : Getting error while starting the server

From
amihay gonen
Date:



---------- Forwarded message ---------
From: amihay gonen <agonenil@gmail.com>
Date: Tue, 24 Feb 2015 09:07
Subject: Re: [GENERAL] : Getting error while starting the server
To: Raghavendra <raghavendra.rao@enterprisedb.com>


Check postgresql conf file where the socket file is created.

On Tue, 24 Feb 2015 08:42 Raghavendra <raghavendra.rao@enterprisedb.com> wrote:
    return Database.connect(**conn_params)
  File "/usr/local/lib/python3.4/dist-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not translate host name "localhost" to address: Name or service not known

 
​I guess problem with your server name resolution. ​Its worth checking as said, using psql -h localhost or ping localhost. 

---
Regards,
Raghavendra
EnterpriseDB Corporation

Re: : Getting error while starting the server

From
bhartirawatbr
Date:
*Error*: psycopg2.OperationalError: could not translate host name
"localhost" to address: Name or service not known

*Solution*: Sometimes this error come just because that your LAN cable is
not connect to your system.

To resolve this problem connect your LAN cable to system then again run the
command.

You will find that its work Fine.



--
View this message in context:
http://postgresql.nabble.com/Getting-error-while-starting-the-server-tp5838994p5893684.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.