安裝Postgresql之後,建立使用者 配置rails

c3tc3tc3t發表於2017-09-22

登入 

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

 

相關文章