Ubuntu 12.04 安装 PostgreSQL 9.1 及 rails 的设置

因为 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 了。

天不负;卧薪尝胆,三千越甲可吞吴。

Ubuntu 12.04 安装 PostgreSQL 9.1 及 rails 的设置

相关文章:

你感兴趣的文章:

标签云: