Postgres:创建一个用户名 [英] Postgres: creating a username

查看:416
本文介绍了Postgres:创建一个用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Mac上开始使用Postgres on Rails应用程序。我创建了一个名为shawsome的新rails应用程序,并在database.yml文件中创建了这个

 开发:
适配器:postgresql
编码:unicode
数据库:shawsome_development
池:5
用户名:shawsome
密码:

但服务器不会运行,因为shawsome没有任何作用。 Rails似乎从我的应用程序的名称推断出用户名。



我看了一下postgres的文档,谈到了CREATE USER的命令

  CREATE USER jonathan; 

但是,当我尝试执行CREATE USER时,它说未找到CREATE注释。

任何人都可以告诉我我做错了什么吗?

另外,一旦它在生产中(在Heroku上),我假设它也需要一个用户名。该用户名会保持不变吗?也就是说,如果它是在我的机器上配置的,我是否需要在Heroku上做任何额外的工作? 解决方案

扩展一下TheDelChop的答案
安装后,您可以在终端中运行以下代码:

  createuser -P 

(-P是添加密码)

它会问你对于名称,密码,它们是否是超级用户,可以创建新的角色,并且可以创建新的数据库。您可能不需要任何这些rails的权限。

然后创建数据库,以您创建的以下角色运行:

  createdb -O ROLE_NAME_FROM_PREVIOUS_STEP NEW_DATABASE_NAME 

以及中提琴,你应该很好去。


I'm trying to get started with Postgres on Rails apps on Mac. I made a new rails app called "shawsome" and in the database.yml file it created this

development:
adapter: postgresql
  encoding: unicode
  database: shawsome_development
  pool: 5
  username: shawsome
  password:

But the server wouldn't run because there's no role for "shawsome." Rails just seemed to have inferred the username from the name of my app.

I looked at postgres documentation and it talks about CREATE USER command

CREATE USER jonathan;

However, when I tried to do CREATE USER, it said CREATE comment not found.

Can anyone tell me what I'm doing wrong?

Also, once it's in production (on Heroku) I'm assuming it will also need a username. Will that username remain the same? i.e. if it's configured on my machine, do I need to do anything extra on Heroku?

解决方案

To expand a bit on TheDelChop's answer After installation you can run the following in the terminal:

createuser -P

(The -P is to add a password)

It will ask you for name, password, whether they are a superuser, can create new roles, and can create new db's. You probably won't need any of those permissions for rails.

Then create the database to run with the following role you created:

createdb -O ROLE_NAME_FROM_PREVIOUS_STEP NEW_DATABASE_NAME

And viola, you should be good to go.

这篇关于Postgres:创建一个用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆