Rails issues when connection to PostgreSQL database - ruby-on-rails

Attempting to get Rails running with postgresql on mac osx 10.8 to deploy to heroku. I'm new to mac's.
Had lots of trouble just getting PostgrSQL installed so I could have botched up something trying all the potential solutions I could find searching on that subject. Which mainly appeared to be permissions and existing OSX installation. for this issue I'm noticing some things that make me think there is some fundamental directory or version conflict that I'm not sure how to resolve yet. But I could be wrong and it is something else! Any direction is appreciated.
retrieving an error such as this:
$ rake db:create:all
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"?
I'm not sure where and why it's looking for the var directory but ~/var appears to be a link (alias) to /private/var (which has empty pgsql_socket & pgsql_socket_alt directories), /usr/local/var doesn't have pgsql_socket directory but does have a postgres directory. both of those directories my admin user has read & write permission from the finder get info dialog.
The above error shown is followed by a long stack in the gems 1.8 directory and finishes with this:
Couldn't create database for {"pool"=>5, "database"=>"blog_development", "password"=>nil, "username"=>"USERNAME", "encoding"=>"unicode", "adapter"=>"postgresql"}
so checking:
$ which psql
/usr/bin/psql
i do remember after installing postgresql i did this:
initdb /usr/local/var/postgres -E utf8
Confirmed:
$ ps aux | grep postgres
username 346 0.0 0.1 2479616 7724 ?? S 3:08PM 0:00.03 /usr/local/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
bundle show yields: pg (0.14.1)
$ postgres --version
postgres (PostgreSQL) 9.2.1
echo $PATH does not show any reference to posgresql.
this app is in a /Users/USERNAME/SUBDIR/APP.
Andy ideas on where i've messed up and how i can get this stuff up and running? I'd appreciate any direction. I'll keep working through stack overflow and google discussions; although my stupidity may be unique!
Thanks.

Add
host: localhost
to database.yml

Related

Trouble installing postgresql on osx using homebrew

I'm trying to install postgres on a new machine for the time. I initially ran thoughtbot's laptop script to install most of what I'd need for rails development which should have included the postgres installation. Yet when I run a rake db:create for the new rails app I get the following error:
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "pool"=>5, "timeout"=>5000, "username"=>"riskpool", "password"=>nil, "database"=>"riskpool_development"}
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 tried uninstalling and reinstalling postgres via homebrew like this and this is the result:
$ brew remove postgres
Uninstalling /usr/local/Cellar/postgresql/9.4.5_2... (3021 files, 40M)
And reinstalling postgres
$ brew install postgres
==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.4.5_2.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/postgresql-9.4.5_2.yosemite.bottle.tar.gz
==> Pouring postgresql-9.4.5_2.yosemite.bottle.tar.gz
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall postgresql`
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/Homebrew/homebrew/issues/2510
To migrate existing data from a previous major version (pre-9.4) of PostgreSQL, see:
https://www.postgresql.org/docs/9.4/static/upgrading.html
To load postgresql:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
WARNING: launchctl will fail when run under tmux.
==> Summary
🍺 /usr/local/Cellar/postgresql/9.4.5_2: 3021 files, 40M
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
/usr/local/Cellar/postgresql/9.4.5_2/homebrew.mxcl.postgresql.plist: Operation not permitted
if I run the second command
$ postgres -D /usr/local/var/postgres
FATAL: could not open directory "pg_tblspc": No such file or directory
If I try to find out where postgres is installed:
$ which postgres
/usr/local/bin/postgres
Someone suggested I kill an existing process id that might be interfering:
$ rm /usr/local/var/postgres/postmaster.pid
rm: /usr/local/var/postgres/postmaster.pid: No such file or directory
But I get the same error
psql: 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"?
Have you tried using this command :
rm /usr/local/var/postgres/postmaster.pid
It appears that this file is blocking postgres from starting up and it would be the reason why you get the below 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"?
Have you tried launching the server with root privileges ? i.e.
sudo postgres -D /usr/local/var/postgres
It seems though as the server is not launching due to file permission privileges.
It also seems that the brew postinstall scripts failed, so you may need to initialize the db cluster.
You can use initdb to create a new cluster.
sudo initdb /usr/local/var/postgres9.4
Alternatively, if this is for a development machine, I would recommend just using the postgres app for macosx (simple click and run):
http://postgresapp.com/

Switched to PG! DB migration error: PG::ConnectionBad:

I was using sqlite but switched to pg for some reasons.
I included pg gem in the makefile and made changes in the config/environments.
When I started migrating the data using rake db:migrate , I’m getting this error.
PG::ConnectionBad: 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"?
I've gone through all the posts related to this but did not find a solution.
I'm using ruby 2.1.5 and rails 4.2.0.
sudo /etc/init.d/postgresql start
or
sudo /etc/init.d/postgresql restart
Both should work just fine
If you still get an error you should fix the config/database.yml file one way to go about this is simply create a new project
rails new yourapp -d postgresql
then just copy the database.yml file
if you need to create an new user and password
sudo -u postgres createuser john -s
If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password john
Most of this is from gorails
You need to start your PG server:
$ postgres -D /usr/local/pgsql/data
http://www.postgresql.org/docs/9.1/static/server-start.html

Deploying Cloud9 to Heroku - Postgresql

Gotten to databases portion of deploying C9 to heroku but I keep running int othis error. Postgresql is already installed on cloud9 but I'm having trouble. I get this error when I run "postgresql" into terminal
ryanreese09#codefund:~/workspace/ruby-getting-started (master) $ psql
ry Is the server running locally and accepting connections on Unix
domain socket "/var/run/postgresql/.s.PGSQL.5432"?
https://devcenter.heroku.com/articles/getting-started-with-ruby#declare-app-dependencies
I haven't run bundle install since the postgresql command didn't work. It's not running. Would anyone be willing to getthrown on my workspace as a member and help? I've been messing with this all weekend. All the various threads I've search on here don't quite help. The don't help with getting the sockets set up. Please don't flame. I'm new.
EDIT- Ruby on Rails: How can i edit database.yml for postgresql?
Changed my database.yml file but literally nothing changed. So I reverted it back to the default database.yml file for now (that came with installation)
$ sudo service postgresql start

Postgres permission denied on MAC OS X

I was following the ruby on rails tutorial to run with postgres but when I try the "rake db:create" I get the following error:
could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I have found this question issuing some similar problem but I couldnt make it work anyway.
Repairing Postgresql after upgrading to OSX 10.7 Lion
I have installed homebrew after reading this question and the path is fine, brew doctor shows me no errors on path.
Instead of troubleshooting your socket file permissions, you could try a TCP connection. Add host: localhost to your config/database.yml. Of course, this will only work if postgres is listening for TCP traffic. Postgres listens on port 5432 by default, so netstat -an | grep 5432 will tell you if it is listening.
References
PostgreSQL Documentation: 18.3. Connections and Authentication.
Oh, may be you are open postgre in another application, like pgadmin http://www.pgadmin.org/
Try to close any application that use postgre SQL and run your command again.
I ran into the same problem today and found this blog post below which helped me:
http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/
It moves your OS X default postgres binaries into an archive folder and symlinks the homebrew versions in place of them.
TL;DR
curl http://nextmarvel.net/blog/downloads/fixBrewLionPostgres.sh | sh
I had the same issue. After unsuccessfully trying all the suggestions posted above, I finally quit out of terminal and restarted it.
This worked.
Just check if your config/database.yml has------host: localhost and port: (check for yourself by netstat -an | grep 5432 or 5433)
I also ran into this problem because I had both the mysql and pg gems active in my Gemfile.
I commented out the mysql gem:
# mysql
Then ran:
bundle install
and then:
rake db:migrate
and it worked like a charm.

Rails rake db:setup fails on server: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

I am running rake db:setup on my server, and I am getting:
Can't connect to local MySQL server through socket '/tmp/mysql.sock'
(I added RAILS_ENV=production)
This is on a ubuntu, nginx, passenger, mysql setup.
Either MySQL isn't running, or it's not configured to put the sock-file in the right place. Run something like ps aux | grep mysql to check if it's running. If it's running and the error persists, check if the file /tmp/mysql.sock exists. You can configure it in /etc/mysql/my.cnf
On my ubuntu machine its configured to /var/run/mysqld/mysqld.sock. Either change your mysql settings, or change config/database.yml in your Rails app.
I had this issue and after trying everything I discovered that this occurs if you install mysql after you have installed rails.
Reinstalling rails solved the issue for me.
Of course this advice is only relevant if iain's answer doesn't solve your issue ;-)
If you dont have the file /tmp/mysql.sock, create a symlink to the actual socket file. You will have to locate it first, but mine was here:
/etc/mysql/my.cnf
That should fix it, as long as mysql is actually installed and running, check using this:
ps aux | grep mysql
I changed the sockets in /etc/mysql/my.cnf, then it worked fine.

Resources