登录
sudo su - postgres
psql
1 创建Postgresql新用户,devpg是用户名,密码也是devpg, 不是超级管理员,拥有创建数据库权限,登录权限,继承拥有角色权限
create user devpg with NOSUPERUSER CREATEDB NOCREATEROLE INHERIT LOGIN PASSWORD 'devpg' ;
2 \du查看
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
devpg | Create DB | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
3 配置rails config/database.yml ,注意host属性和port属性要填写
注意: 同时要安装 pg 这个gem , gem install pg
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
username: devpg
password: devpg
host: localhost
port: 5432 development:
<<: *default
database: developmentpg # 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: testpg production:
<<: *default
database: productionpg
4 然后在rails目录的终端下 执行
rake db:setup