歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 12.04 安裝 PostgreSQL 9.1 及 rails 的設置

Ubuntu 12.04 安裝 PostgreSQL 9.1 及 rails 的設置

日期:2017/2/28 15:42:28   编辑:Linux教程

因為 Heroku 用的 database 是 postgres,但 tutorial 教的是用 sqlite,所以要自找資料去設定 postgres,免得 development environment 跟 production 的不一樣,又要費時再 debug。

安裝:

sudo apt-get install postgresql
之後執行以下指令,開始 postgres console:

sudo -u postgres psql postgres
設定 root password:

\password postgres
安裝 adminpack:

psql < /usr/share/postgresql/8.4/contrib/adminpack.sql

之後便可以用 client 連進去了,Ubuntu 下可以安裝 pgadmin3 這個 GUI client,command line 的實在不懂用...

sudo apt-get install pgadmin3不過以上的只為 development,production 的話要有更多設定,不然被 hack 的話就...

Rails app config:
可以用 pgadmin3 連進去 db 以後,便新增一定使用者,加進 "Can create database object",沒加的話每次會不能自動 create database 的。

然後更新 /config/database.yml 如下:

development:
adapter: postgresql
database: DB_NAME
username: USERNAME
password: PASSWORD
host: localhost
encoding: utf8
pool: 5
timeout: 5000

其他的 environment (test, production) 也記緊跟著改,之後行 rake db:schema:load 和 rake db:test:prepare 便可以繼續 development 和 testing 了。

Copyright © Linux教程網 All Rights Reserved