列表中遇到和解决的错误:
壳初始化:错误检索当前目录:GETCWD:不能访问父目录:权限被拒绝
pg_config错误
库未加载:libpq.5。dylib
fe_sendauth:没有提供的密码
pg_ctl:没有指定数据库目录和环境变量PGDATA未设置
pg_ctl:服务器不关机
(PG ::错误)
A)预安装:
当您单击.dmg文件开始安装时,会打开一个对话窗口,并在安装程序旁边有一个README文件。阅读。我改变了共享存储器的规定:
$ sudo vi /etc/sysctl.conf
On a MacBook Pro with 2GB of RAM, the author's sysctl.conf contains:
kern.sysv.shmmax=1610612736
kern.sysv.shmall=393216
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
kern.maxprocperuid=512
kern.maxproc=2048
我向下滚动该文件到第k的和改变每个列出的线到指定的值。然后你需要重新启动你的电脑。
B)安装和使用PostgreSQL:
的.dmg文件然后再次单击,然后点击安装程序和安装的Postgres。我接受了所有的默认设置。
据我所知,postgres安装程序仅向名为'postgres'的用户提供目录/Library/PostgreSQL/9.2的权限。在postgres安装期间,安装程序要求为数据库超级用户提供密码,如果您想知道数据库超级用户的名称是什么,那么它是'postgres'。
当您发出sudo命令时,您正在临时更改为用户'root'。但是,root用户无权访问dir /Library/PostgreSQL/9.2。所以你必须使用su命令(切换用户)切换到postgres用户。但为了发出su命令,你需要成为root用户。了解?
其结果是,只要你发出Postgres的命令,你需要做的第一:
$ cd /Library/PostgreSQL/9.2
$ sudo su postgres
Password: <normal sudo password>
象这样的错误:
~$ sudo su postgres
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
由事实,你尝试切换到引起用户postgres在postgres用户没有权限的目录下,也就是说,据我所知,除了/Library/PostgreSQL/9.2以外的每个目录。
在你以后正确切换到postgres用户:
$ cd /Library/PostgreSQL/9.2
$ sudo su postgres
Password: <normal sudo password>
您会看到一个有趣的提示。就我而言,它看起来像这样:
bash-3.2$
如果发出ls命令:
bash-3.2$ ls
bin installer scripts
data lib share
doc pgAdmin3.app stackbuilder.app
include pg_env.sh uninstall-postgresql.app
你可以猜测,你是在/Library/PostgreSQL/9.2目录。
enterpriseDB安装程序在完成安装后自动启动postgres服务器。如果您需要启动服务器,例如您关闭了计算机,请参阅下面的步骤5中的“可以从命令行停止或启动服务器”。
C)连接到使用pgAdmin3服务器:
我花了几个小时试图找出如何启动服务器,只是一般使用的Postgres没有运气。然后我碰巧在目录/Library/PostgreSQL/9.2中看到一个名为pgAdmin3的东西。我点击了它,并打开了一个有几个窗格的窗口。
在pgAdmin3窗口的左侧窗格中,它说:
Server Groups
--Servers(1)
----PostgresSQL 9.2 (localhost:5432)
我点击“的PostgreSQL 9.2(本地主机:5432)”,突出它,然后我右键点击,弹出一个菜单,我选择了连接。出现提示时,我输入了数据库超级用户密码。
d)建立轨道使用PostgreSQL:
然后我跟着本教程中的方向用于获取轨道设置:
https://pragtob.wordpress.com/2012/09/12/setting-up-postgresql-for-ruby-on-rails-on-linux/#comment-1142
如下:
1)第一步是创建一个新用户。
如果使用相同的名称为您的Mac用户名,然后你不必输入用户名(或密码)在你的Rails应用程序添加到database.yml文件:
$ cd /Library/PostgreSQL/9.2
$ sudo su postgres
Password: <normal sudo password>
bash-3.2$ createuser --interactive 7stud
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
Password:<database superuser password>
bash-3.2$
这就产生一个没有密码的新用户。
接下来,在pgAdmin3如果你点击:
---Login Roles(1)
突出它,然后点击图标“刷新选定的对象”窗口的顶部,你会看到显示的新用户。
为CREATEUSER Postgres的文档是在这里:
http://www.postgresql.org/docs/9.2/interactive/app-createuser.html
还有一个dropuser命令:
bash-3.2$ dropuser 7stud
2)然后, 'PG' 宝石添加到您的Gemfile,并注释掉sqlite宝石。
3)然后尝试与捆扎机安装PG宝石:
rails_projects/sample_app/$ bundle install --without production
当我尝试了,我得到了 'pg_config' 错误。要修正这个错误,我跟着建议在这里:
http://excid3.com/blog/installing-postgresql-and-pg-gem-on-mac-osx/#.UftQUOB6gy6
,并添加/Library/PostgreSQL/9.2到我的PATH(我做的.bashrc所有路径的操作)。不要忘记'源'.bashrc或退出终端并重新启动终端以使新PATH生效。
然后我就能够安装PG宝石没有错误:
rails_projects/sample_app/$ bundle install --without production
rails_projects/sample_app/$ bundle update
rails_projects/sample_app/$ bundle install
(我真的不明白,为什么你必须做所有这三个命令,但就是railstutorial做什么。)
4)接下来改变你的config/database.yml文件。
对于每个部分:测试,开发和生产改变了“转接器”和“数据库”行,并添加一个“编码”线,如:
development:
adapter: postgresql
database: ArbitaryDatabaseName (e.g. sampleapp_dev)
encoding: utf8
pool: 5
timeout: 5000
确保所有三个数据库行指定一个不同的名字。
5)然后尝试创建数据库:
rails_projects/sample_app/$ bundle exec rake db:create:all
当我尝试了,我得到了错误:
dlopen(/Users/7stud/.rvm/gems/[email protected]_rails_4_0/gems/pg-0.15.1/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib
Library not loaded: libpq.5.dylib
Referenced from: /Users/7stud/.rvm/gems/[email protected]_rails_4_0/gems/pg-0.15.1/lib/pg_ext.bundle
图书馆libpq.5.dylib位于
/Library/PostgreSQL/9.2/lib
使用这里的建议:
https://github.com/PostgresApp/PostgresApp/issues/109
我解决了这个错误通过添加以下到我的.bashrc文件(或者你可以把它的.bash_profile):
export DYLD_FALLBACK_LIBRARY_PATH="/Library/PostgreSQL/9.2/lib:$DYLD_LIBRARY_PATH"
(请记住,“源” .bashrc或者退出终端并启动一个新的终端窗口)
然后我试图再次创建数据库:
rails_projects/sample_app/$ bundle exec rake db:create:all
fe_sendauth: no password supplied …
为了解决这个诅咒的错误,你需要更改pg_hba.conf文件,这是在目录
/Library/PostgreSQL/9.2/data
使用寻人你不能进入该目录 - 你必须使用Postgres的用户去到该目录:
$ cd /Library/PostgreSQL/9.2
$ sudo su postgres
Password: <normal sudo password>
bash-3.2$ cd data
bash-3.2$ ls
PG_VERSION pg_hba.conf pg_notify pg_subtrans postgresql.conf
base pg_ident.conf pg_serial pg_tblspc postmaster.opts
global pg_log pg_snapshots pg_twophase postmaster.pid
pg_clog pg_multixact pg_stat_tmp pg_xlog
bash-3.2$ mvim pg_hba.conf
(or instead of mvim open with another text editor, e.g. vim)
在.conf文件,你需要改变“MD5”到“信任”:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust #md5
# IPv4 local connections:
host all all 127.0.0.1/32 trust #md5
# IPv6 local connections:
host all all ::1/128 trust #md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres md5
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
访问方法“MD5”是指数据库期待一个加密p指定数据库用户的密码。但是,当你创建新用户时,你创建它时没有密码。访问方法'信任'表示数据库不期望密码。
然后我试图再次创建数据库:
:
rails_projects/sample_app/$ bundle exec rake db:create:all
fe_sendauth: no password supplied …
在试图让服务器读取我.conf文件中所做的更改,我从pgAdmin3与服务器断开连接
Server Groups
--Servers(1)
----PostgresSQL 9.2 (localhost:5432)
Click on PostgresSQL 9.2 (localhost:5432) to highlight it,
right click, then select Disconnect,
then right click and select Connect.
但显然这是行不通的。断开连接并重新连接到服务器不会导致服务器重新加载.conf文件。为了让服务器重新加载.conf文件,在pgAdmin3你可以右键点击PostgresSQL 9.2 (localhost:5432)
选择:
Reload configuration
或者你可以停止,然后启动命令行服务器:
(注下面的命令假定您已经切换到postgres用户,请参见“安装和使用PostgreSQL”上方)
bash-3.2$ cd /Library/PostgreSQL/9.2/
bash-3.2$ pg_ctl stop (First disconnect from the server in pgAdmin3)
然而,所产生的错误:
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
我解决了这个错误是这样的:
bash-3.2$ export PGDATA=/Library/PostgreSQL/9.2/data
bash-3.2$ echo $PGDATA
/Library/PostgreSQL/9.2/data
bash-3.2$ pg_ctl stop
waiting for server to shut down.... done
server stopped
bash-3.2$ pg_ctl start
server starting
如果不从服务器首先在pgAdmin3断开,你得到的输出:
bash-3.2$ pg_ctl stop
waiting for server to shut down............................................................... failed
pg_ctl: server does not shut down
HINT: The "-m fast" option immediately disconnects sessions rather than
waiting for session-initiated disconnection.
bash-3.2$
后来,我无法关闭当我打开滑轨控制台时关闭服务器。我使用User.create(....)
向数据库添加了一个用户,并且我忘记事先启动postgres,所以我想知道该记录会发生什么。出于某种原因,postgress服务器已经在我的系统上运行(似乎每当我启动计算机时都会启动postgress--下面解决)。接下来,我试图停止服务器,我无法。关闭导轨控制台后,服务器停止。
最后,没有任何错误:
~/rails_projects/sample_app4_0$ bundle exec rake db:create:all
~/rails_projects/sample_app4_0$ bundle exec rake db:migrate
~/rails_projects/sample_app4_0
我想这意味着该数据库的创建。如果你看看pgAdmin3,你应该可以看到三个新的数据库(尽管它们有红色的x)。如果看不到它们,请右键单击数据库目录(在pgAdmin3中),然后选择刷新。
编辑:我后来遇到了一些问题。为了全面测试,如果一切正常,在这里看到:
How do I get my rails app to use my postgresql db?
6)保护/叉勺
当我开始了我的后卫/叉勺组合:
~/rails_projects/sample_app4_0$ bundle exec guard
我得到这个错误:
...
...
Preloading Rails environment
Loading Spork.prefork block...
FATAL: the database system is shutting down
(PG::Error)
我修复了通过启动postgres服务器,并使用pgAdmin3连接到服务器。
最终,我想出了如何在每次启动计算机时保持postgres服务器的启动。我不得不作出两个更改:
1)$ sudo vim /Library/LaunchDaemons/com.edb.launchd.postgresql-9.2.plist
用你的postgres版本代替9.2。
2)找到行RunAtLoad
3)从<true/>
下一行更改为<false/>
https://superuser.com/questions/244589/prevent-postgresql-from-running-at-startup
独自这些步骤对我来说没有工作。然后我发现这样的建议:
4)$ sudo launchctl unload -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.2.plist
替换你的Postgres的版本代替9.2。
http://www.postgresql.org/message-id/flat/[email protected]#[email protected]