简体   繁体   English

postgres服务器拒绝连接到heroku

[英]postgres server refuses to connect to heroku

I've set up a remote postgresql database for a gradle app that I'd like to deploy on Heroku. 我已经为要在Heroku上部署的gradle应用程序设置了一个远程postgresql数据库。 When running my app on my machine it works fine. 在机器上运行我的应用程序时,它可以正常运行。 However, I had a hard time connecting to the database that I've set up on Heroku, so I thought I'd just try to connect to my remote database. 但是,我很难连接到在Heroku上设置的数据库,因此我认为我只是尝试连接到远程数据库。 This is the error that showed up in my app log: 这是显示在我的应用日志中的错误:

2016-08-18T13:28:12.606715+00:00 app[web.1]: [JarClassLoader] INFO:  findResource(): unable to locate "org/postgresql/translation/messages_en.properties"
2016-08-18T13:28:12.609362+00:00 app[web.1]: Exception in thread "main" java.lang.reflect.InvocationTargetException
2016-08-18T13:28:12.609487+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2016-08-18T13:28:12.609542+00:00 app[web.1]:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2016-08-18T13:28:12.609642+00:00 app[web.1]:    at java.lang.reflect.Method.invoke(Method.java:498)
2016-08-18T13:28:12.609715+00:00 app[web.1]:    at com.simontuffs.onejar.Boot.main(Boot.java:161)
2016-08-18T13:28:12.609970+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
2016-08-18T13:28:12.610011+00:00 app[web.1]:    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:239)
2016-08-18T13:28:12.610060+00:00 app[web.1]:    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
2016-08-18T13:28:12.610112+00:00 app[web.1]:    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:127)
2016-08-18T13:28:12.610162+00:00 app[web.1]:    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
2016-08-18T13:28:12.610440+00:00 app[web.1]:    at org.postgresql.Driver.connect(Driver.java:282)
2016-08-18T13:28:12.610602+00:00 app[web.1]:    at net.bethydiakabana.mbta.MbtaApplication.run(MbtaApplication.java:79)
2016-08-18T13:28:12.611050+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused
2016-08-18T13:28:12.611072+00:00 app[web.1]:    at java.net.PlainSocketImpl.socketConnect(Native Method)
2016-08-18T13:28:12.611122+00:00 app[web.1]:    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
2016-08-18T13:28:12.611146+00:00 app[web.1]:    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
2016-08-18T13:28:12.611170+00:00 app[web.1]:    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
2016-08-18T13:28:12.611286+00:00 app[web.1]:    at org.postgresql.core.PGStream.<init>(PGStream.java:61)
2016-08-18T13:28:12.611331+00:00 app[web.1]:    ... 23 more
2016-08-18T13:28:12.688094+00:00 heroku[web.1]: Process exited with status 1
2016-08-18T13:28:12.703273+00:00 heroku[web.1]: State changed from starting to crashed

I've read that I needed to change the permissions in the postgres configuration files yet I kept getting the same errors. 我读到我需要更改postgres配置文件中的权限,但我一直遇到相同的错误。 What would be the best way to fix this on a windows machine? windows计算机上修复此问题的最佳方法是什么?

EDIT: 编辑:

I've set up a heroku postgres database to see if that would help. 我已经建立了一个heroku postgres数据库,看看是否有帮助。 I'm not sure if it's still having connection issues as well as locating the main class. 我不确定它是否仍然存在连接问题以及查找主类的问题。 Would it still be worth connecting to my original database? 连接到我的原始数据库仍然值得吗? This is the error that I'm getting now: 这是我现在得到的错误:

 Starting process with command `java -Ddw.server.connector.port=37275 -Ddw.database.user=mmcyajlpsbacac -Ddw.database.password=C6nrfQzuoS2ZEMDaTqVEssPDxa -Ddw.database.url=jdbc:postgresql://ec2-54-235-254-199.compute-1.amazonaws.com:5 432/d8hvhhr0h3hr8d?user=mmcyajlpsbacac&password=C6nrfQzuoS2ZEMDaTqVEssPDxa&sslmo de=require  $JAVA_OPTS -jar build/libs/mbta-tweets.jar server config.yaml`
2016-08-18T17:25:22.842387+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2016-08-18T17:25:22.846667+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
2016-08-18T17:25:23.220849+00:00 app[web.1]: Error: Could not find or load main class 432.d8hvhhr0h3hr8d?user=mmcyajlpsbacac&password=C6nrfQzuoS2ZEMDaTqVEssPDxa&sslmo
2016-08-18T17:25:23.317758+00:00 heroku[web.1]: Process exited with status 1
2016-08-18T17:25:23.331809+00:00 heroku[web.1]: State changed from starting to crashed

Here is a snippet of my yaml configuration that's read by the configuration class: 这是配置类读取的yaml配置的片段:

server:
  type: simple
  applicationContextPath: /application
  adminContextPath: /admin
  connector:
    type: http
    port: 8080

database:
  # the name of your JDBC driver
  driverClass: org.postgresql.Driver

  # the username
  user: someusername

  # the password
  password: somepassword

  # the JDBC URL
  url: jdbc:postgresql://host:port/dbname?user=username&password=password

Here is my procfile : 这是我的procfile

web: java $JAVA_OPTS -Ddw.server.connector.port=$PORT -Ddw.database.user=$JDBC_DATABASE_USERNAME -Ddw.database.password=$JDBC_DATABASE_PASSWORD -Ddw.database.url=$JDBC_DATABASE_URL  $JAVA_OPTS -jar build/libs/mbta-tweets.jar server config.yaml

This message: 这条信息:

Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused

Suggests that you are trying to connect to a database on localhost on Heroku, which is certainly not correct. 建议您尝试连接到Heroku上localhost上的数据库,这当然是不正确的。 Can you show how you've configured your database connection in the Java code? 您可以显示如何用Java代码配置数据库连接吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM