在我的Rails應用程序(v 3.2.8)中,到目前爲止,我已經使用遷移沒有問題。pg_dump:「無法連接到服務器」在Rails「schema_format =:sql」遷移
我使用PostgreSQL 9.2作爲數據庫。我調整了我的application.rb
以使用sql而不是模式自卸車(未註釋config.active_record.schema_format = :sql
)。
在那之後,我開始對移民這個錯誤:
$ rake db:migrate
[ALL MIGRATION STUFF IS PRINTED HERE]
pg_dump: [archiver (db)] connection to database "my_dev_db" failed: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
rake aborted!
Error dumping database
I tried manually on the command line(logged in as the same user on my Mac)
<!-- language: lang-sh -->
$ pg_dump my_dev_db > /tmp/db.sql
No problems with that...happily dumps into `/tmp/db.sql`
Why is rails having trouble with `pg_dump`? (I am on Mac OSX Lion)
===========
Adding more diagnosis information
===========
$tail -10 /usr/local/var/postgres9.2/pg_hba.conf
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication rogert trust
#host replication rogert 127.0.0.1/32 trust
#host replication rogert ::1/128 trust
$ sudo lsof -p 62444 | awk '$5 == "unix" && $NF ~ /\// { print $NF }'
/tmp/.s.PGSQL.5432
$ ps auxw | grep post
postgres 1403 0.0 0.0 2435492 640 s007 S+ 21Oct12 0:00.05 bash
root 1401 0.0 0.0 2498096 128 s007 S 21Oct12 0:00.02 su postgres
rogert 62517 0.0 0.0 2426700 388 s001 R+ 9:21PM 0:00.00 grep post
rogert 62448 0.0 0.0 2481656 500 ?? Ss 8:46PM 0:00.03 postgres: wal writer process
rogert 62447 0.0 0.0 2481656 752 ?? Ss 8:46PM 0:00.07 postgres: writer process
rogert 62446 0.0 0.0 2481656 1040 ?? Ss 8:46PM 0:00.00 postgres: checkpointer process
rogert 62444 0.0 0.1 2481656 5368 s001 S 8:46PM 0:00.02 /usr/local/Cellar/postgresql/9.2.1/bin/postgres -D /usr/local/var/postgres9.2
$ rake db:migrate --trace
[ALL MIGRATION STUFF IS PRINTED HERE]
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:393:in `block (3 levels) in <top (required)>'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/rogert/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:162:in `block (2 levels) in <top (required)>'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/rogert/.rvm/gems/[email protected]_3.2.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/rogert/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
$sudo vi /usr/local/var/postgres9.2/postgresql.conf
[search for listen address]
# - Connection Settings -
listen_addresses = 'localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
請告訴我奇怪的是,如果我完全從我的Rails應用程序中刪除這兩條線路,遷移工作。所以,如果它與TCP連接和listenting的一個問題,是如何工作的移民本身(但不會當我把這兩再次打開)
- application.rb中 - config.active_record.schema_format =: SQL
- 在我的移民文件中的一個 - t.hstore:屬性
你沒有測試同樣的事情;正如@Tom所指出的那樣,'pg_dump'默認使用unix域套接字,而不是TCP/IP。嘗試運行'pg_dump -h 127.0.0.1 -p 5432 my_dev_Db>/tmp/db.sql'。它運行正常嗎? –
在Mac OS X上,使用'sudo lsof -i -P | grep -i「listen」'列出偵聽的TCP/IP端口。在你的情況下,你對'sudo lsof -i -P |感興趣grep -i「listen」| grep postgres或者'sudo lsof -i -P | grep -i「listen」| grep 5432'。 –