我正在使用rails4应用。
我的一位同事最近改变了我们用来发布的数据库。当我拉动他的分支并尝试运行我的服务器时,我收到以下错误:
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"?
这是我的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
当我运行ps auwwx|grep postg
时,我明白了:
c5227806 42095 0.0 0.0 2432772 648 s001 S+ 5:47PM 0:00.00 grep postg
我也有:
$ psql --version
psql (PostgreSQL) 9.4.4
这个(我不知道它们是不同的):
$ postgres -V
postgres (PostgreSQL) 9.4.4
还有:
$ 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
有什么想法吗?我在网上找到的所有解释都不起作用或者太复杂而无法理解。
答案 0 :(得分:1)
pg没有像我必须运行的评论中所说的那样运行:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
然后创建并迁移数据库。希望这有助于某人!