Rails app won't connect to PostgreSQL - ruby-on-rails

I'm coming from the PHP/MySQL world, trying to set up a Rails/PostgreSQL app. It doesn't seem to want to connect and I'm having a hard time pinning down the cause of the problem. Are there certain troubleshooting steps I can take to figure out what's going wrong?
Update: the problem is not with PostgreSQL. I can connect to PostgreSQL via the command line, remotely via an IDE, and via a PHP script. I just can't seem to connect to it through this Rails app.

First I'd start with the actual database.yml file to make sure i have all the right user and password information.
I'd also make sure i ran whatever it is you do to make postgres start it's server, so that connections can be established. (Whether you use a psql start or it starts when you start your dev env. So only you can answer that one).
Is the database created?
Can i connect through console? rails console shouldn't give an error.
Do you have the correct postgres gem installed and is that in your bundle file (or environment.rb file)?

Related

Connecting Rails to AWS MySQL database

I've recently created a rails app. I pushed the initial files onto github.
My problem is that I want to connect my rails app to AWS in order to use a MySQL database. I keep seeing tutorials on EC2 and Beanstalk, but I am not sure which one I should use. I have all the drivers needed for ruby through the gem installations.
I'm looking to figure out the main differences between Beanstalk and created a MySQL instance as well as what to put in my database.yml file in my rails app to connect to a database. Thank you in advance!
Just to give an idea, after you provision/create your instance on AWS (EC2 or wherever), you will then push your app's code to that remote server somewhere. You can do it manually via scripts, or you can use Capistrano for this. Once your app is deployed to the server, you need to connect to the server via SSH and manually edit the config/database.yml file to point to the staging/production MySQL database. (I'm generalizing, but I think you just need a step in the right direction.)

Pulling down from github, unable to work locally with postgreSQL

I cloned a repository in a RoR app using postgres but I'm unable to work locally. When I run the server 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 "/tmp/.s.PGSQL.5432"?
I've tried many things: the password reset doesn't work because it's not recognizing as a user...I've tried adding the underscore before postgres user...sudo su doesn't work...help!
Ok, so after shuffling through the google return links for the original error message, I came across this: http://www.brentmc79.com/posts/psql-could-not-connect-oh-fuck-you
Very straightforward list of commands that shut down the database, force a reset, and then a manual restart...it will also return prompts that you'll get. Very helpful. I'm getting a CSS error now, but it looks like the database setup is ok. Thanks!

Should the database.yml be configured when testing locally for Heroku with foreman?

Can someone explain to me what they do when they initialise a rails app locally with foreman (part of Heroku toolbelt) (using postgreSQL), destined to run on Heroku?
I'm going by this guide: developing locally with foreman and what I don't understand is if we are expected to specify database username and passwords or if foreman is supposed to handle it as Heroku itself does?
This perplexes me a little as if we are supposed to modify the database.yml to hook it up to postgreSQL, then what is the point of using foreman instead of rails server?
If it does handle it, how does it handle it, and how would I configure my pg_hba.conf to respect it? Something like local all myuser trust?
Yes, database.yml needs to be configured with valid information for your development and test databases.
Foreman is only running what's in your Procfile, not ripping things out and plugging different things in like Heroku does.
So why do you want to use Foreman instead of rails server? Because it:
Runs all roles defined in your Procfile with one command
Automatically loads your .env
Will fail if any of your roles fail (so less scratching your head because some necessary backend service isn't running)

Testing a ROR app without an Internet Connection

Normally if I want to test an ROR app in Ubuntu, I run the rails s command and webrick initializes the server which I access by typing "localhost:3000" or whatever in the URL bar of my browser. However, I can't do this without an internet connection. If I'm in the air or just somewhere with no wifi, is there a way to still do this?
Thank you.
Rails loads dependencies through the your OS's http libraries. I don't know the exact terminology, but it basically means your app will use any connection required to make your app run
To explain, this works in the same way as if you access http://google.com & http://localhost:3000 - you still access through the browser, but your system doesn't mind if those URL's are local or public
To answer your question, you'll need to keep your db & assets local to your system. The simple way is to install & run a MYSQL server, and use localhost in your database.yml file to connect to it

OCIError (ruby on rails)

I am using rails freeze 1.2.3 to run a rails app. Because the app is on a remote machine, I used ssh tunnel (ssh -l -L) to show the app on my screen. When I ran it, it correctly prompted the login page, after I put in the info, I got this error:
OCIError in ServiceController
Error while trying to retrieve text for error ORA-12154
I have tried the same app on a different machine w/o using freeze (because that machine has rails version 1.2.3 while current one has 2.0.2). Is that where the error comes from?
Thanks.
That's an Oracle error. It sounds like your database setup is incorrect. Put the error number ORA-12154 in Google and you'll find some useful stuff.
ORA-12154 is a classic. As Sarah points out its nothing to do with your Rails or Ruby per se. ORA-12154 is generated when the Oracle Client can't connect to the oracle server. So most likely your setup is wrong in:
Your database.yml, if you can connect using tnsping or sqlplus (Oracle client utils) you probably just need to look at this.
Your Oracle networking setup, particularly your tnsnames.ora file (found in $ORACLE_HOME/network/admin if I remember correctly). This may need some extra help from a friendly DBA as the tnsnames.ora syntax has quirks. Check this link link text for more info.
Hope that helps.

Resources