简体   繁体   中英

No such file or directory Is the server running locally and accepting connections on Unix domain socket “/tmp/.s.PGSQL.5432”?

I'm working on a rails4 app.

A colleague of mine recently changed the database we use to postgress. When I pulled his branch and try to run my server 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 "/tmp/.s.PGSQL.5432"?

This is my database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: sciencevest_development

test:
  <<: *default
  database: sciencevest_test

production:
  <<: *default
  database: sciencevest_production
  username: sciencevest
  password: <%= ENV['SCIENCEVEST_DATABASE_PASSWORD'] %>

Gemfile:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.2'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Bootstrap & sass
gem 'bootstrap-sass', '~> 3.3.5'
gem 'sass-rails', '>= 3.2'


# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# authentication
gem 'devise'
gem 'devise_invitable'

# authorization
gem 'pundit'

# roles
gem 'rolify'

# states
gem 'aasm'
# pretty development data
gem 'faker'

# uploading images & videos
gem 'carrierwave'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

source 'https://rails-assets.org' do
  gem 'rails-assets-bootstrap'
end

group :development, :test do

  # test suite
  gem 'minitest-rails'
  gem 'factory_girl_rails', '4.0'

  # guards
  gem 'guard'
  gem 'guard-minitest'
  gem 'database_cleaner'

  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :development do 

  gem 'guard-livereload'
end

When I run ps auwwx|grep postg I get this:

c5227806        42095   0.0  0.0  2432772    648 s001  S+    5:47PM   0:00.00 grep postg

I also have this:

$ psql --version
psql (PostgreSQL) 9.4.4

And this(i dont know if they are different):

$ postgres -V
postgres (PostgreSQL) 9.4.4

Also this:

$ brew info postgres
postgresql: stable 9.4.4 (bottled)
Object-relational database system
https://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.4.4 (3014 files, 40M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/postgresql.rb
==> Dependencies
Required: openssl ✔, readline ✔
==> Options
--32-bit
    Build 32-bit only
--with-dtrace
    Build with DTrace support
--with-python
    Build with python support
--without-perl
    Build without Perl support
--without-tcl
    Build without Tcl support
==> 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 have launchd start postgresql at login:
    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
    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
c5227806 at PALM00566449A in ~/desktop/dev_projects/rails_projects/sciencevest on carrierwave
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
/Users/c5227806/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: No such file or directory

Any ideas? All the explanations I found online either didn't work or were too complicated to understand.

pg was not running as stated in the comments I had to run:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Then create and migrate database. Hopefully this helps someone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM