我有一个非常简单的ruby文件,可以在开发环境中的本地主机上正常运行,但我无法连接到Heroku上的postgresql数据库。
initialize': could not connect to server: No such file or directory
(PG::ConnectionBad) Is the server running locally and accepting from
/app/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg.rb:45:in
我收到此错误:
/app/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg.rb:45:in
Class2 dad = new Class2(DadName.getText(), DadLastName.getText()); Class1 son = new Class1(FirstName.getText(), dad, "Session"); // Write object to file FileOutputStream outStream = new FileOutputStream(new File("MainStore.dat"), true); ObjectOutputStream objectOutputFile = new ObjectOutputStream(outStream); objectOutputFile.writeObject(son); objectOutputFile.close(); // Update the objectcounter file by // Maintenance is a class I use just to save object contain information about number of files,increase them, decrease them. Maintenance check = new Maintenance(); FileInputStream inStream = new FileInputStream("Counter.dat"); ObjectInputStream objectInput = new ObjectInputStream(inStream); check = (Maintenance) objectInput.readObject(); inStream.close(); check.increaseObject(); FileOutputStream outStream1 = new FileOutputStream("Counter.dat"); ObjectOutputStream objectOutputFile1 = new ObjectOutputStream(outStream1); objectOutputFile1.writeObject(check); objectOutputFile1.close();
新' Unix域套接字上的连接" /var/run/postgresql/.s.PGSQL.5432"?
我无法弄清楚如何从Heroku访问DATABASE_URL ENV配置变量。我甚至尝试将实际字符串剪切并粘贴到代码中代替XXXXX,它会抛出同样的错误。
我在StackOverflow上看到了很多关于如何在rails应用程序中执行此操作的建议,但没有关于如何以独立的ruby工作方式执行此操作的建议。
谢谢!
编辑:在帖子中添加了实际的数据库信息。我知道它不安全,但那里没有任何敏感,只要我弄明白,我就会改变它。