跳至主要内容

[PSQL] 安裝並連接到 Rails

如果還沒安裝 PostgreSQL 的話請先看文章後半部。

在 Rails 中使用 PostgreSQL

安裝 PostgreSQL 的 gem

gem install pg

建立 Rails APP

rails new blogapp --database=postgresql

Windows

Install PostgreSQL and integrate with Ruby on Rails

Install PSQL from official website directly.

  1. Set all METHOD in pg_hba.conf as trust on both IPv4 and IPv6, the file path of pg_hba.conf is %HOMEPATH%\psql\pg_hba.conf in Windows.

  2. Open the app pgAdmin in program files, create an new role. Check image here if needed.

  3. The name of the role SHOULD BE SAME AS the system user, leave the password field empty and make the privilege as SUPERUSER. Check image here.

The pg_hba.conf should look like the settings below:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5

Windows Settings for Developers @ Andyyou 大尺度私房筆記

參考資料