Ruby on rails 在Ubuntu上使用Rails应用程序设置postgres数据库
现在我对Ubuntu和postgres有点动摇,但以下是我目前所做的 在Ubuntu中,我创建了一个名为postgres的用户,密码为postgress:Ruby on rails 在Ubuntu上使用Rails应用程序设置postgres数据库,ruby-on-rails,ruby,ubuntu,rails-postgresql,pg,Ruby On Rails,Ruby,Ubuntu,Rails Postgresql,Pg,现在我对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 Passwo
$ 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
好消息是数据库服务器输出如下:
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,我完全理解了这一点
但是,对于beefer数据库,数据库现在存储在称为集群的东西中,对吗
现在,对于我创建的每个postgres rails应用程序,它们的所有数据库都将存储在集群中吗
如果我购买一个Ubuntu VPS并在上面安装postgres,这会是一样的吗?位于
/usr/local/var/postgres
的集群,包含我所有应用程序的所有数据库?您忽略了操作系统和版本、如何安装PostgreSQL等细节,使得这个问题更难回答
你提到Ubuntu,所以我猜你是通过apt从Ubuntu安装了PostgreSQL包
如果是,则postgres PostgreSQL用户帐户已存在,并且已配置为可通过pg_hba.conf中unix套接字的对等身份验证进行访问。您可以作为postgres unix用户运行命令,例如:
sudo-u postgres createuser\u名称
rakedb:create:all
这样做之后,重新启动我的Rails服务器,我回到服务器的url,我很高兴地骑在Rails上 请查看:[postgreserror][1][1]: