Rails 4:PG :: ConnectionBad定义服务" postgresql"未找到

时间:2014-12-21 11:29:28

标签: ruby-on-rails database postgresql

我的rails应用程序似乎无法与我的Postgresql数据库连接。当我在localhost:3000上访问它时,它一直给我这个错误。

PG::ConnectionBad  
definition of service "postgresql" not found

当我将pgAdmin3与我的db连接并给出pg_service.conf文件的位置时,甚至会发生这种情况。如果我将服务字段留空,那么我可以成功连接到我的数据库。

所以我只是想知道为什么它没有拿起我的pg_services文件,我在这里缺少什么。

我的pg_services.conf文件位于/ etc / postgresql-common中,它看起来像这样:

[postgres]  
dbname=postgres  
user=postgres  
password=postgres 

所有参数都是故意设置的,这意味着我已经使用用户postgres和密码postgres命名了我的db postgres。

我的database.yml看起来像这样:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  host: localhost
  adapter: postgresql
  encoding: utf8
  database: postgres
  pool: 5
  username: postgres
  password: postgres
  timeout: 5000

development:
  <<: *default
  database: postgres

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: postgres

production:
  <<: *default
  database: postgres

postgresql.conf中也允许localhost连接。这是一个片段:

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = 'localhost'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost', '*' = all
                                        # (change requires restart)
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)
# Note:  Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3     # (change requires restart)
unix_socket_directory = '/var/run/postgresql'           # (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                        # (change requires restart)
#bonjour = off                          # advertise server via Bonjour
                                        # (change requires restart)
#bonjour_name = ''                      # defaults to the computer name
                                        # (change requires restart)

那么为什么它仍然找不到pg_service.conf或者我在这个文件中缺少某种指令?

0 个答案:

没有答案