Rails can't see my Postgres database - ruby-on-rails

I'm trying to load a Rails 3.2 project on my Macbook and I'm having difficulty. I installed Postgres 9.1.4 via brew. After putting /usr/local/bin in the front of my $PATH, I can now get into Postgres from the command line via psql.
However, in my Rails project, when I run:
rake db:create:all
I get the following error:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.S.PGSQL.5432"?
Well that file indeed does not exist. Yet I can access the database via the command line with psql.
Why is it looking in that area, and what can I do to make it look in the proper place (whatever that is) for Postgres?

This is depressingly common on OS X systems for users of Homebrew and Postgres.app.
What happens is that your Rails 'Pg' gem gets compiled against the old PostgreSQL version Apple pre-installs on some Mac OS X versions, rather than the version you installed yourself. This happens because the PATH has the Apple version of pg_config on it before the version you installed.
Any of these alternatives will work:
Recompile the Pg gem to use the correct libpq by setting your PATH so that the right pg_config is on it before compiling (best option);
Set an explicit socket directory when you connect with host: /tmp, or with psql etc -h /tmp/;
Use TCP/IP: host: localhost, psql -h localhost, etc;
You can find more detail here:
PostgreSQL Mountain Lion socket issue

Check your database.yml file. Probably a bad configuration

Related

So I installed postgresql and localhost port conflicting with ruby app?

I installed postgresql. I put the localhost port to 3000 on pgadmin. Then it started to throw this error since the localhost port for my ruby app is also at port 3000.
Address already in use - bind(2) for "localhost" port 3000 (Errno::EADDRINUSE
I tried to uninstall it and the error still comes up. I tried to delete pgadmin. I tried to set an environment variable export PGPORT=5432. After all this the error still comes up. I just want to get rid of postgres and re-install everything to see what went wrong. I am completely confused. I am faily new with ruby and postgres. I usually use node mongodb etc.
Questions:
What is the best way to get rid of postgresql and reinstall it?
Any other ideas on how to edit the port?
How to delete db on postgresql?
I know it sounds like I am all over the place because I am right now. I just want to start fresh. So please any help.
Best way to install and use PG/Mongo/MySql on Mac OSX is Brew.
If brew not installed, install it by copy/pasting into Terminal.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To install Postgresql
brew install postgresql
To use DB (run/restart/stop)
brew services list
brew services start postgres
brew services stop postgres
you may also use different port.
rails s -p 81
if you want to always start with different port..create Rakefile and add a task..
task :server81 do
`bundle exec rails s -p 8081`
end
you can use it directly by rake server81

PostgreSQL 9.1 and Rails 3 database migration error

I am using PostgreSQL 9.1, which I installed using the DMG provided on the Postgres website. So, my Postgres installation is in /Library/Postgres/9.1.
I am pretty sure my Postgres server is running, but when I run rake db:migrate the rake is aborted with this error:
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Why is "rake" searching /var/... and not using my installation of Postgres?
Can you supply the link from which you actually downloaded Postgres? It seems like your instance of Postgres has a differently-named socket file than Rails expects, so Rails is unable to find it.
One option is to find the socket that does exist on your system and create a symlink to it from the location mentioned in the output. But my suggestion is to delete this instance of Postgres and simply install it again using Homebrew since you seem to be using OSX. Installation using Homebrew is straightforward: brew install postgresql. After completing the installation just follow the steps listed in the command line output to complete the installation.
Also, if you are using the Postgres.app provided by Heroku you may want to check the documentation.

Rails project using MySQL gem not starting up on Windows 8

My specs are as follow:
Windows 8 64-bit
Ruby 1.9.3
Rails 3.2.12
I installed rails via the RailsInstaller. I have also installed the mysql2 gem. I created a new project that is pre-configured to use mysql e.g.
rails new project_name -d mysql
I then tried to start up the server/WEBrick via
rails server
And I get the following error:
I've tried this using the mysql2 as well as teh mysql gem. Both times I get the same error. When I use the default sqlite then the project starts up fine and I can view it on localhost:3000.
I'm aware that mysql2 used to be a problem on rails, but since mysql isn't working either I'm of the opinion that it's a Windows 8 specific project, surprise surprise.
I'd deff like to use MySQL rather than SQLite. Thanks for anyone that can point me in the right direction!
As a noted error case,
The SO Post says-
"The problem is with mysql. It is a 64 bit installation. Change it to 32bit and it runs fine."
Apart from that, this error may also be the result of some missing gems.
You should try running bundle install before running your server.
Also make sure that gem mysql is added to your gemfile before you do bundle install.
Please update your MySQL to 64bit version. It will fix the problem. Don't forgot to install the Devkit.

Rails error: Couldn't find database client: sqlite3

I'm using Rails in a development environment. I'm trying to run simple INSERT commands via the command line, but I can't seem to connect to the SQLite database. Other database-related commands are working fine (e.g. rake db:migrate). I'm using the following command:
rails dbconsole
But I'm getting the following error:
Couldn't find database client: sqlite3. Check your $PATH and try again.
I'm still learning Rails and I'm hoping you rails Rails experts out there will be able to spot the issue.
Sqlite3 isn't installed on your computer, go to the sqlite site and install the command line utility according to whichever operating system your using.

$PATH confusion Postgres and Rails on OSX Lion

Rails and all my gem files + homebrew installs have been working fine up until this point.
I ran
homebrew install postgresql
and was following the prompts pretty much as indicated in this video but it kept giving me error messages saying there is a server already running. I checked
which psql
in the terminal and it reported a
usr/bin
location rather than
usr/local/bin
indicating I was using the postgres that comes with osx not the new homebrew install.
When I attempted to start the database server I recieved an error message saying the server is already running. There is a mention of this error message in the postgres help documentation but no real working solution.
Attempting brew doctor confirmed that i needed to change my PATH in .bash_profile.
I came across this little snippet here on stack overflow for the .bash_profile edit.
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin
I saved the file and managed to get postgres up and running fine but then when I went to start a new rails app.
rails new blog -d postgresql
it says
Rails is not currently installed on this system. To get the latest version,
simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
Any attempt to install does not work until i change the bash_profile file back to what it was before.
If I change it back postgres has the same issue again saying there is already a server running.
Also I thought it might be a launch agent or something but I don't think there are any that are set up.
I figure either something is installed in the wrong place or I have to add something to the .bash_profile?
Don't set your $PATH explicitly. You should append or prepend to it instead:
# In your .bash_profile
export PATH="/usr/local/bin:$PATH"
My guess is that you either use RVM or rbenv. If you change your path to /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin explicitly then RVM or rbenv won't be in your path.

Resources