I wrote application in Rails. It use Postgresql via VPN. Sometimes VPN is going down and database is not available. How I can check connection with database to avoid error on web page ?

Error :

PG::ConnectionBad
could not connect to server: Connection timed out Is the server running on host "192.168.251.6" and accepting TCP/IP connections on port 5432?

Extracted source (around line #651):

        # connected server's characteristics.
        def connect
          @connection = PGconn.connect(@connection_parameters)

          # Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
          # PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision

Any ideas ? And where to check because error is before any controller I think.

share|improve this question
    
Will this help: ActiveRecord::Base.connected? ? – Deep Jan 9 at 8:48

Enter following commands on VPN to check pg:

sudo -u postgres psql

The PostgreSQL console is indicated by the postgres=# prompt.

postgres=# \password pguser

where password is the postgres password and pguser is the user name of postgres

Enter your desired password at the prompt, and confirm it.

Now you may exit the PostgreSQL console by entering this command:

postgres=# \q
share|improve this answer
    
Man I need to do it in Ruby on Rails program. I know how to check on linux side :) – ArtLion Jan 12 at 8:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.