Configure RubyMine remote connection to Heroku PostgreSQL - ruby-on-rails

How should I configure RubyMine jdbc datasource to remotely connect to Heroku's PostgreSQL database? Currently I am using such connection URL:
jdbc:postgresql://ec2-54-197-241-67.compute-1.amazonaws.com/dbqi9t12t5035q
but I get error about lack of entry for host '62.87.242.2' in pg_hba.conf. I am pretty sure that user and password are correct, because it runs online... :-). Could you help me?
Thank you in advance!

In the Advanced tab, there are a bunch of properties. Set the following properties:
ssl -> true
sslfactory -> org.postgresql.ssl.NonValidatingFactory

The error you're seeing means the security policy of the Postgres server doesn't allow the connection. Heroku Postgres only allow connections from within Heroku, as far as I know.
You'll need to use their official command line tools if you want to open a remote database connection:
heroku pg:psql
The official tools authenticate to Heroku and tunnel through their network.

Related

heroku pg:psql not working [connection refused]

I am running a Ruby on Rails app on Heroku with Postgres Database.
I used to be able to connect to my database from my terminal using heroku pg:psql command
Recently, things have changed. After running heroku pg:psql command, I get the following error.
--> Connecting to postgresql-perpendicular-94363
psql: could not connect to server: Connection refused
Is the server running on host "ec2-23-23-130-158.compute-1.amazonaws.com" (23.23.130.158) and accepting
TCP/IP connections on port 5432?
I tried to search online about it, but nothing useful has been found.
Please help. Thanks 😄
I've just tried connect to your database:
psql "dbname=postgresql-perpendicular-94363 host=ec2-23-23-130-158.compute-1.amazonaws.com user=test_user port=5432 sslmode=require"
And I've got:
psql: FATAL: password authentication failed for user "test_user"
Because, of course I don't know you credentials :)
However, it seems that connection works. I suppose, that you forgot set sslmode. As you can see in documentation, it is required:
All connections require SSL: sslmode=require.
Update:
I've checked connection without sslmode, and message is other than yours:
FATAL: no pg_hba.conf entry for host "31.42.24.63", user "test_user", database "postgresql-perpendicular-94363", SSL off
So, I suppose that this is a problem with you internet connection. Check you firewall setup.
As per the description mentioned in the post, the way you have specified is correct.
Moreover you can also try the below mentioned command where you specify the database as well.
heroku pg:psql DATABASE_URL
Note: This is only used when there are multiple databases linked.

cannot connect to Heroku Postgres - error "server closed the connection unexpectedly"

I am trying to use the Heroku CLI to connect a Postgres database in the cloud.
heroku pg:info shows the database information, but heroku pg:psql fails with the following error:
$ heroku pg:psql
--> Connecting to postgresql-<database-id>
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
What's wrong?
Port 5432 must be unblocked for psql to work and I was unable to do that. Switching to a different network (e.g. Internet provider at home or mobile Internet) may help.
Might not be the issue for everyone, but if you have a computer set up to connect with mTLS by having a ~/.postgresql/postgresql.crt and ~/.postgresql/postgresql.key, psql will automatically send the key up to all databases you connect to, and you will break heroku pg:psql connections to other databases
So just
mv ~/.postgresql{,.bak}
and try again. If that's your issue, you'll want to put your mTLS certs in a different directory and manually pass them as arguments or via config vars
The location of the certificate and key files can be overridden by the
connection parameters sslcert and sslkey or the environment variables
PGSSLCERT and PGSSLKEY

java.sql.SQLException: FATAL: no pg_hba.conf entry for host

Developing RoR app on Windows using RubyMine, trying to connect to Postgres database hosted on Heroku server. No Postgres installed locally. Getting "java.sql.SQLException: FATAL: no pg_hba.conf entry for host..." What to do, what to do?
This is due to Heroku databases needing additional SSL configuration.
You need to enable SSL in your jdbc string by appending:
?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
For details see Heroku's help document.
It looks like this is a RubyMine issue. RubyMine will convert the hostname to an IP address and pg_hba.conf includes the hostname but not the IP address hence the error. It works fine from the command line (e.g. rails s).

Deploy rails app on dotcloud

I'm trying to deploy a ruby on rails app to dotcloud. The app is deployed but when I try to access the url, I get this error:
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"? (PG::Error)
I'm using a postgresql database. What all changes do I need to make in the database.yml file?
I've also followed the steps outlined here:
http://docs.dotcloud.com/services/postgresql/
Can anyone please help on this?
It looks like your app is configured to use a local PostgreSQL database (local as in "running on the same machine"). You should make sure that your dotcloud.yml file contains a section for a PosgreSQL database, e.g.:
db:
type: postgresql
Then use either dotcloud info to retrieve the host, port, and credentials of the database, or parse them from environment.json in your Ruby app.
This last step is explained in the dotCloud PostgreSQL service documentation.

RoR app deployed on Heroku and working with SQL Server database

Is it feasible to have a Ruby on Rails app, which is:
a) deployed on Heroku, and
b) working with a remote SQL Server database?
I take it that I'll need unixODBC installed on Heroku, but I cannot find a way to do so. Is this possible?
Or, is there any other way (without ODBC?) to accomplish this?
Thank you very much for any guidance or tip.
Updated:
Some info on the subject:
1) Heroku pre-installs both unixODBC and FreeTDS by default, so you already have them.
2) Also, it is possible to run shell commands via Heroku Console in backticks, e.g.:
heroku console
`odbcinst`
(runs "odbcinst" command in Heroku shell and shows the result)
3) You do not have access to filesystem outside of your slice where the packages are installed. If you only need a driver path, Heroku support can provide it (/usr/lib/odbc/libtdsodbc.so in my case).
4) You cannot run sudo commands in Heroku shell.
At the moment, to connect to MS SQL Server you at least need to append ‘freetds.conf’ file. Even when using tinyTDS (there is an open ticket#2 in tinyTDS gitgub issue page). DSN-less connection instructions from "wiki.rubyonrails.org SLASH database-support SLASH ms-sql" didn’t work for me, I guess this connection requires some extra-configuration either.
‘freetds.conf’ cannot be modified without sudo. Therefore, I conclude that currently there is no way to make MS SQL and Heroku work together.
I’ve managed to set up this connection with EngineYard and activerecord-sqlserver-adapter.
I followed these instructions:
https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Platform-Installation---Ubuntu
(there are only some filepath differences, e.g. ‘odbc.ini’ is located in ‘/etc/unicodbc’, not in ‘/etc’ - this is easy to work out).
I installed 'unixODBC' and 'freetds' packages using EY Unix Packages feature, and made all configurations manually through SSH. Sudo is available in EY (no password required). There is also Chef Recepes feature to automate those configurations (seems to be pretty easy, I'm going to try it tomorrow).
Hope this is helpful.
It is possible.
Because Heroku copies/symlinks its own config/database.yml over whatever you supply in your repository, you may need to take additional steps (e.g. in config/environments/production.rb or in config/initializers/remote_mssql_from_heroku.rb) to set up your application appropriately.
You will face the challenge, however, that traffic from Heroku to your MSSQL database will traverse the public internet. By default, this traffic will not be encrypted. Potentially everyone in the world will be able to monitor your traffic between your Heroku application and your database, and even alter the traffic in-flight, whether for benign or malicious purpose, without you being able to detect it. MS SQL offers the capability to connect over SSL. This capability requires explicit configuration in the MSSQL server, so you must be able to access and modify that configuration. Additionally, this configuration requires that your client library be up-to-date and capable of talking with MSSQL over SSL. Note that MSSQL server will enforce that your server certificate list a Common Name or Subject Alternative Name exactly matching or wildcard-matching the server's FQDN (at least, the FQDN that the server knows about), and that the client use an FQDN for the server exactly matching or wildcard-matching one of the names on the certificate.
I've successfully used the following article which uses Heroku's newer buildpack feature to use TinyTDS and connect remotely to SQL Server 2008 R2. I'm still investigating how I could encrypt traffic. Hope this helps others!
http://blog.firmhouse.com/connecting-to-sql-server-from-heroku-with-freetds-here-is-how-on-cedar#
We're having a similar problem where we're needing to import old data from a SQL Server database into our new app. The data isn't a straight table import, but needs to undergo some processing and conversions. We've built an import layer for this which lives in a private gem, so as to not pollute the new app with the old data conversion issues. This approach is also designed to permit incremental updates, as we get closer to launch we'll keep syncing records up to the moment of switch-over.
Heroku told us that it's not trivial to connect to SQLServer, in particular as they don't support FreeTDS. Their support staff recommended to run an instance with the import gem from a laptop in our office and configure it to connect to their database (which requires a dedicated DB, not the free shared one). This sounded like the most palatable approach to us.
Secondly, regarding security that was mentioned by #Justice, we discussed configuring SSL for SQLServer with the hosting company and they pointed out the complexities of this. They recommended VPN as an easier solution. As we don't have office-side VPN hardware, the simplest and free solution proved to be an SSH tunnel.
We've set up an SSH tunnel from the laptop to the SQLServer Windows box. That was straightforward. We had CopSSH installed on Windows (which comes with a Linux shell, by the way) and we were able to simply set up a tunnel, having the laptop talk to localhost for its SQLServer connection, i.e.:
ssh -L 1433:localhost:1433 user#windows_server_name
I did not know Heroku has FreeTDS on it? I was told they did not. TinyTDS if used with FreeTDS 0.91 can have a zero freetds.conf dependency and be driving by runtime connection args. We are looking into building an Ubuntu 10.4 native gem that statically links 0.91 with OpenSSL so you can just drop it into Heroku and us it to connect to Azure and/or you own outside DB.

Resources