首先,我是 Vagrant 和 Postgres 的新手。
我使用http://files.vagrantup.com/lucid32.box创建了我的 Vagrant 实例,没有任何问题。我能够运行vagrant up
并且vagrant ssh
没有问题。
我按照说明做了一个小改动,我安装了“postgresql-8.4-postgis”包而不是“postgresql postgresql-contrib”。
我使用以下方法启动服务器:
postgres@lucid32:/home/vagrant$ /etc/init.d/postgresql-8.4 start
Run Code Online (Sandbox Code Playgroud)
在连接到 vagrant 实例时,我可以使用它psql
来毫无问题地连接到实例。
在我的 Vagrantfile 中,我已经添加了:
config.vm.forward_port 5432, 5432
Run Code Online (Sandbox Code Playgroud)
但是当我尝试从本地主机运行 psql 时,我得到:
psql: could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud)
我确定我错过了一些简单的东西。有任何想法吗?
更新:
我找到了对此类问题的引用,文章建议使用:
psql -U postgres -h localhost
Run Code Online (Sandbox Code Playgroud)
我得到:
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Run Code Online (Sandbox Code Playgroud)
您提到的博客文章中的说明对于 ubuntu 根本不正确:它们使用自编译服务器安装中的部分,这些部分与打包版本不能很好地混合。
不应创建 /usr/local/pgsql/data 并将 initdb 运行到该目录,因为 ubuntu 包代表用户使用/var/lib/postgresql/<pg-version-number>/<cluster-name>
和运行initdb
。
提到“/tmp/.s.PGSQL.5432”的错误表明此文件的预期位置不正确(对于 ubuntu)。它应该在/var/run/postgresql
. 这可能是由于手动运行 initdb 的参数与 ubuntu 不兼容。
要编辑以启用非本地连接的 postgresql.conf 和 pg_hba.conf 文件应该在里面/etc/postgresql/8.4/main
,而不是 /usr/local/pgsql/data。
本/etc/init.d/postgresql-8.4
应该由root启动(因为一切都在/etc/init.d其他),而不是由postgres用户。
PGDATA 不应该手动设置,因为它再次妨碍了 ubuntu postgres 包的工作方式。
我的答案是清除并重新安装 postgresql-8.4 包,而无需遵循博客文章中的任何说明。postgresql-8.4-postgis 依赖于 postgresql-8.4,因此它也将被删除。还要确保撤消/etc/bash.bashrc 中PGDATA 的设置。
归档时间: |
|
查看次数: |
7639 次 |
最近记录: |