设置PostgreSQL和db:rake的问题

设置PostgreSQL和db:rake的问题,sql,ruby-on-rails,linux,postgresql,Sql,Ruby On Rails,Linux,Postgresql,在为我正在进行的项目设置Postresql时,我遇到了很多问题 一些信息: -我正在运行Ubuntu 12.04 -我已安装postgres用户帐户 -我正在尝试使用RoR中的一个项目 我正在尝试使用以下命令: “bundle exec rake数据库:创建” 我试着把它当作sudo、计算机用户和postgres使用 # enter the psql shell as the postgres admin user psql -d postgres CREATE ROLE <%= yo

在为我正在进行的项目设置Postresql时,我遇到了很多问题


一些信息:

-我正在运行Ubuntu 12.04

-我已安装postgres用户帐户

-我正在尝试使用RoR中的一个项目


我正在尝试使用以下命令:

“bundle exec rake数据库:创建”

我试着把它当作sudo、计算机用户和postgres使用

# enter the psql shell as the postgres admin user
psql -d postgres
CREATE ROLE <%= your_project_name %> WITH LOGIN CREATEDB SUPERUSER;
\q

# create the dbs and load the schema
bundle exec rake db:create
bundle exec rake db:schema:load
bundle exec rake db:migrate
bundle exec rake db:test:prepare

# revoke superuser, it was just there in case there were any extensions that needed installing
psql -d postgres
ALTER ROLE <%= your_project_name %> WITH NOSUPERUSER;
\q
当我以计算机用户身份运行它时,它返回“fe_sendauth:未提供密码”,然后中止rake

知道我的(用户帐户)ruby版本是2.1.0,因为当我运行“ruby--version”时,它会返回

“ruby 2.1.0p0(2013-12-25修订版44422)[x86_64-linux]”

然而,当我以postgres运行“ruby--version”时,它返回

“ruby 2.0.0p353(2013-11-22修订版43784)[x86_64-linux]”

如何为我的用户帐户和postgres提供单独的ruby版本?我尝试使用sudo用RVM更改ruby版本,但被拒绝了

我不记得为postgres sudo设置了密码,我也弄不清楚

我能为你做些什么

  • 恢复/重置我的sudo postgres密码
  • 完成步骤1后,在postgres帐户上安装/设置最新(2.1.0)版本的ruby
  • 运行bundle exec rake db:create完成所有这些之后

  • 嗯,不确定linux有什么具体问题,但听起来你已经安装好了

    如果不查看database.yml,很难说,但是rails的约定似乎是使用用户名和空白密码连接到数据库。根据错误,您可能没有在postgres中创建这样的用户/角色

    # enter the psql shell as the postgres admin user
    psql -d postgres
    CREATE ROLE <%= your_project_name %> WITH LOGIN CREATEDB SUPERUSER;
    \q
    
    # create the dbs and load the schema
    bundle exec rake db:create
    bundle exec rake db:schema:load
    bundle exec rake db:migrate
    bundle exec rake db:test:prepare
    
    # revoke superuser, it was just there in case there were any extensions that needed installing
    psql -d postgres
    ALTER ROLE <%= your_project_name %> WITH NOSUPERUSER;
    \q
    
    #以postgres管理员用户的身份输入psql shell
    psql-d博士后
    使用登录名CREATEDB SUPERUSER创建角色;
    \q
    #创建数据库并加载模式
    bundle exec rake db:create
    bundle exec rake db:schema:load
    bundle exec rake数据库:迁移
    bundle exec rake数据库:测试:准备
    #撤销超级用户,它就在那里,以防有任何需要安装的扩展
    psql-d博士后
    与非超级用户交换角色;
    \q
    
    这应该可以做到这一点,尽管听起来您可能也有RVM方面的问题。网站上有大量关于RVM的文档


    您还可能混淆了数据库中用户/角色的概念与操作系统中用户的概念。您应该能够使用任何unix用户访问数据库,但需要使用database.yml对数据库中的rails进行身份验证。如上所述,我所看到的大多数rails项目似乎都使用默认值,但您当然可以使用任何您想要的东西。

    好的,所以我修复了我的主要问题,我的ruby版本不正确,无法修复,因为我没有身份验证

    我是和你一起做的

    $/bin/bash--登录

    这让我接着打字

    $rvm—默认使用2.1.0

    这将我在用户postgres中的ruby版本设置为2.1.0


    然而,我试着跑了

    $bundle安装

    在用户postgres中,我被拒绝并给出了这个错误

    不幸的是,发生了一个致命错误。请参阅捆绑机故障排除文档,网址为 . 谢谢

    /home/myusername/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/fileutils.rb:250:in`mkdir':权限被拒绝@dir\u s\u mkdir-/home/myusername/.bundler(Errno::EACCES)

    我无法访问用户postgres的sudo,因为我没有为它设置密码。因此,我相信我的问题的答案是跑步

    $sudo bundle安装

    但是我没有sudo密码


    对此问题的任何帮助都将不胜感激。

    请使用RVM。安装RVM之后,您可以在其中安装和管理不同版本的ruby。我有RVM,但我无法通过Postgres帐户访问sudo来使用RVM,因为Postgres sudo不知怎么设置了密码(我不知道)。