Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPFMn-0007sp-NY for pgsql-general@arkaria.postgresql.org; Fri, 17 Apr 2020 01:00:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jPFMl-0001eQ-Qt for pgsql-general@arkaria.postgresql.org; Fri, 17 Apr 2020 01:00:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPFMl-0001eI-Ij for pgsql-general@lists.postgresql.org; Fri, 17 Apr 2020 01:00:23 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPFMb-0003jB-H2 for pgsql-general@postgresql.org; Fri, 17 Apr 2020 01:00:22 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id EA364641; Thu, 16 Apr 2020 21:00:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 16 Apr 2020 21:00:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=7 8Fot1gP8jlOtPPb1fTJO23DIKoKaWu/PSzWp9LOyfw=; b=EB0KXeAK3MI38umjd pwyRpO/+gwXWm121BATLdvV4qIz+A09hspeQmCg+ZlLU3wPPFNXqNpurIO+BQy3s SjBUhIahjAu21WxB0+LqimAxD4eSo+KYXqjrPhIQC6lHi8nfLX506+MP08PnAtaF w6hn3s7VZ5xX1PFMhIaOgonk3jThd5giJLPfsinxcwAWpjzQ4scEEHHGBBeqDTSM 3kg9gZrWmUVtOtToekH7xuXceLbLGCjZLTKs3cIJbJIPI4kEHUu17/4zFLyqlup0 8TDlgjRF32XXY5/zD8AapFMQM2sbQQXUadFU0Hl0ZNT4vh72aD3Ij1Xi86pM4VzS K6JGw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=78Fot1gP8jlOtPPb1fTJO23DIKoKaWu/PSzWp9LOy fw=; b=kwT0LHvp7aZs+wYgHFtomzLplJH0jiK+iSlq9qjqjVWQLSI0+Nm+FKH3G /CVf38tcIys9AilYJR1m6QUBW2Y+V47p7I9uuiePTso5YcdFXWQ4AqOLvx04+gpP dEixusQf49UAvmAmSCvMvNC06/GplHXYVqSaDTYS7e36VCgnG6Y8u0uEo+e3BK7l d3RRSd3zqCdqTkNvN6+4HEyTHTEhj+ygcoOZZhW2vKw7gG1LunC8JbNNRmr0fvKi 9SI9b13k5T5iJ1jCC1hTZH8aiAVStpGAhhbRLt3GUjYRTd0wSjkuUhvRAEhNhHGO PyQbXDpo8AVEPee5p22trmUk0tuKw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrfeeigdegudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesthekre dttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhl rghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepugguuhgtkhdrlhhotg grlhenucfkphepleejrdduudefrddvtdejrddufeeknecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklh grvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.10] (97-113-207-138.tukw.qwest.net [97.113.207.138]) by mail.messagingengine.com (Postfix) with ESMTPA id E42723280063; Thu, 16 Apr 2020 21:00:09 -0400 (EDT) Subject: Re: Could not resolve host name error in psycopg2 To: derwin theduck , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: Date: Thu, 16 Apr 2020 18:00:09 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/16/20 5:38 PM, derwin theduck wrote: > We have been getting this error intermittently (about once a week) in > Django with channels since switching from a local database server to a > hosted one: > > could not translate host name "timescaledb" to address: Name or service > not known > > Connecting directly to the server with psycopg2 in the python > interpreter works ok: > > >>> import psycopg2 as pg > >>> pg.__version__ > '2.7.7 (dt dec pq3 ext lo64)' > >>> conn = pg.connect(host='timescaledb', database=*, user=*, > password=*)        >>> conn.server_version > 110005 Well I'm go out on a limb and say there is some sort of DNS resolution issue going on. > > The resident database / network expert maintains that everything is ok > on the networking side, and that django, once it establishes a > connection, should not be attempting to reconnect. Huh? Leaving open connections is not considered a good thing. In other words a connection should last for as long as it takes to get it's task done and then it should close. > > The problem happens not on startup, but in the middle of the day after > processing transactions without any issues for several hours. > > Any idea how to go about troubleshooting / fixing this? :'( > >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/models/query.py", > line 276, in __iter__) >  (    self._fetch_all()) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/models/query.py", > line 1261, in _fetch_all) >  (    self._result_cache = list(self._iterable_class(self))) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/models/query.py", > line 57, in __iter__) >  (    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, > chunk_size=self.chunk_size)) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", > line 1135, in execute_sql) >  (    cursor = self.connection.cursor()) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/utils/asyncio.py", line > 24, in inner) >  (    return func(*args, **kwargs)) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/backends/base/base.py", > line 260, in cursor) >  (    return self._cursor()) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/backends/base/base.py", > line 236, in _cursor) >  (    self.ensure_connection()) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/utils/asyncio.py", line > 24, in inner) >  (    return func(*args, **kwargs)) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/backends/base/base.py", > line 220, in ensure_connection) >  (    self.connect()) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/utils.py", > line 90, in __exit__) >  (    raise dj_exc_value.with_traceback(traceback) from exc_value) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/backends/base/base.py", > line 220, in ensure_connection) >  (    self.connect()) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/utils/asyncio.py", line > 24, in inner) >  (    return func(*args, **kwargs)) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/backends/base/base.py", > line 197, in connect) >  (    self.connection = self.get_new_connection(conn_params)) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/utils/asyncio.py", line > 24, in inner) >  (    return func(*args, **kwargs)) >  (  File > "/home/dduck/.local/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", > line 185, in get_new_connection) >  (    connection = Database.connect(**conn_params)) >  (  File > "/usr/local/lib64/python3.7/site-packages/psycopg2/__init__.py", line > 130, in connect) >  (    conn = _connect(dsn, connection_factory=connection_factory, > **kwasync)) >  (  could not translate host name "timescaledb" to address: Name or > service not known) > > -- Adrian Klaver adrian.klaver@aklaver.com