现在我对 Ubuntu 和 postgres 有点动摇,但这是我目前所做的。
在 Ubuntu 中,我创建了一个名为 postgres 的用户,其密码为 postgress:
$ sudo adduser postgres
Enter new UNIX password: (I typed ' postgres ' here)
Retype new UNIX password: (I typed ' postgres ' here)
然后我以 postgres 用户身份登录:
$ su postgres
Password: (I typed ' postgres ' here)
作为 postgres,我启动了 postgres 服务器:
postgres@ubuntu:/$ /usr/lib/postgresql/9.1/bin/postgres -D /usr/local/var/postgres
LOG: database system was shut down at 2013-11-05 17:04:32 PST
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
接下来,我创建了一个 rails 应用程序设置来使用 postgres 数据库:
rails new myapp --database=postgresql
我附加了我的数据库配置 YAML 文件:
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
development:
adapter: postgresql
encoding: unicode
database: postgresql_development
pool: 5
username: postgres
password: postgres
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# 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:
adapter: postgresql
encoding: unicode
database: postgresql_test
pool: 5
username: postgres
password: postgres
production:
adapter: postgresql
encoding: unicode
database: postgresql_production
pool: 5
username: postgres
password: postgres
最后,我跑
rake db:setup
真的不知道会发生什么。如前所述,我对这个话题有点动摇。很多小的 db.postgres 文件会出现在我的应用程序的 db 目录中吗?
无论如何,我收到一条巨大的错误消息,但它的要点是:
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"postgresql_development", "pool"=>5, "username"=>"postgresql", "password"=>nil}
FATAL: role "postgresql" does not exist
好消息是数据库服务器输出是这样的:
FATAL: role "postgresql" does not exist
FATAL: role "postgresql" does not exist
FATAL: role "postgresql" does not exist
这意味着我的系统上的所有内容都已正确“连接”,并且 rake 任务正在尝试创建我的测试、生产和部署数据库。
坏消息是我并不真正理解错误消息:
FATAL: role "postgresql" does not exist
嗯,很确定我的 YAML 中指定的用户名是 postgres,而不是 postgresql。
couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"postgresql_development", "pool"=>5, "username"=>"postgresql", "password"=>nil}
同样,为什么我的用户名 postgresql 和我的密码为空?这根本不是我的 YAML 中的内容!
如果有人可以帮助我迈出最后一步,我将非常感激:)
最后一个问题,非 sqlite3 数据库如何准确工作,它们在系统上的位置。当我开始使用 Rails 并看到我的 db 目录中的小 db.sqlite3 时,我可以完全理解这一点。
但是,使用更强大的数据库,数据库现在存储在称为集群的东西中,对吗?
现在,对于我创建的每个 postgres rails 应用程序,它们的所有数据库都会存储在集群中吗?
如果我购买 Ubuntu VPS 并在其上安装 postgres,情况会不会一样?位于/usr/local/var/postgres
包含我所有应用程序的所有数据库的集群?