Occasional Postgres error on Heroku: could not translate host name “<pg URL>” to address: Name or service not known (PG::Error)

穿精又带淫゛_ 提交于 2019-12-01 18:04:53

That's a DNS error. It's exceedingly unlikely to be anything to do with your code. If both your Rails app and your DB are within Heroku, contact Heroku support.

If your Rails app is running outside the Heroku cloud (as a bit of searching for the term "Unicorn" suggests it could be; please link to things like this; not everyone knows what "unicorn" is), you need to do some debugging to work out where the DNS issues are. Is it the recursive DNS server your app is using? Some closer caching server? Some intermediate server up the chain used to resolve Heroku's DNS (unlikely) ? Heroku's DNS its self? Is it a packet loss issue, an issue where the server responds with a false negative, one bad server in a round-robin cluster, ... ? Expect to spend lots of quality time with dig +trace and with traceroute or mtr - assuming you can ssh in. If you have root, tcpdump and tshark may also be useful, as will examination of the logs of the DNS server you're using if you can get access to them.

If you have no shell access you pretty much have to bug the support of the people you're hosting with.

Just for reference, I had the same problem (Heroku was having an issue with AWS). Here was the helpful response from customer service (08/15):

We are occasionally seeing DNS resolution failure on our instances and we're working to solve this with AWS. The issue is really intermittent and unfortunately we're having hard time trying to identify the cause. While we're investigating, I have one workaround for this issue - currently, you're using Django's default way for the database connection - which is trying to make a new connection per request. This is pretty expensive, also this means you'll need to do DNS resolution for your every request which would increase the possibility to face this issue very unfortunately. Instead, I recommend that you use connection pooling. You can find some examples here:

https://devcenter.heroku.com/articles/python-concurrency-and-database-connections

One customer who was seeing this issue occasionally (but frequently, with Django app) saw a good improvement with the connection pooling, this should help a lot to prevent it from happening.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!