如何为本地Rails项目设置Postgres数据库?

Con*_*ech 26 postgresql ubuntu ruby-on-rails rails-postgresql postgresql-9.1

我最近买了一台新机器,现在想从Github处理我的项目.我很好奇如何在我的本地机器上正确设置Postgres数据库.我有postgresql,pgadmin3libpq-dev安装在Ubuntu(12.04)上.

我拉下项目:

git clone https://github.com/thebenedict/cowsnhills.git

并运行:

bundle.

当我跑:

rake db:create && rake db:schema:load

我收到此错误:

rake db:create && rake db:schema:load
FATAL:  password authentication failed for user "cnh"
FATAL:  password authentication failed for user "cnh"
....
Run Code Online (Sandbox Code Playgroud)

config/database.yml文件如下所示:

development:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: cnh_development
  pool: 5
  username: cnh
  password: cnh

test:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: cnh_test
  pool: 5
  username: cnh
  password: cnh

production:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: cnh_production
  pool: 5
  username: cnh
  password: cnh
Run Code Online (Sandbox Code Playgroud)

设置Postgres数据库的正确方法是什么,以便我可以在本地计算机上运行此项目?

现在,当我启动Rails服务器时,我得到:

在此输入图像描述

Dan*_*iel 52

在寻找相同的答案时,我遇到了你的问题.我试图按照@ prasad.surase给你的指示.我发现的问题是ppa存储库将在12.04 LTS即将贬值.相反,我找到了这个链接,它真的有帮助.

在Ubuntu 12.04中进行Rails开发的PostgreSQL设置

  1. 通过包管理器安装postgresql和admin工具

    sudo apt-get install postgresql libpq-dev phppgadmin pgadmin3
    
    Run Code Online (Sandbox Code Playgroud)
  2. 以postgres用户身份登录postgresql提示符

    sudo su postgres -c psql 
    
    Run Code Online (Sandbox Code Playgroud)
  3. 为您的项目创建一个postgresql用户

    create user username with password 'password';
    
    Run Code Online (Sandbox Code Playgroud)
  4. 使用与Ubuntu用户相同的名称和密码设置postgres用户,并使他成为postgres超级用户

    alter user username superuser; 
    
    Run Code Online (Sandbox Code Playgroud)
  5. 创建开发和测试数据库

    create database projectname_development;
    create database projectname_test; 
    
    Run Code Online (Sandbox Code Playgroud)
  6. 在数据库上为用户授予权限

    grant all privileges on database projectname_development to username;
    grant all privileges on database projectname_test to username; 
    
    Run Code Online (Sandbox Code Playgroud)

结束postgresql会话类型 \q

更新用户的密码

alter user username with password ‘new password’;
Run Code Online (Sandbox Code Playgroud)


pra*_*ase 18

首先,安装postgresql

sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update

#now install postgresql
sudo apt-get install postgresql-9.1 libpq-dev
Run Code Online (Sandbox Code Playgroud) 在psql中创建一个新用户
sudo su postgres
createuser user_name #Shall the new role be a superuser? (y/n) y
Run Code Online (Sandbox Code Playgroud) 的Gemfile
gem 'pg'
Run Code Online (Sandbox Code Playgroud)

捆绑安装

development.yml
development:
  adapter: postgresql
  database: app_development
  pool: 5
  username: user_name
  password:
Run Code Online (Sandbox Code Playgroud)

  • 没必要那样做。使用 rake db:create, rake db:migrate 。你可以简单地做 rake db:setup 来创建和迁移。 (2认同)