PostgreSQL启动失败 [英] Postgresql failed to start
问题描述
我正在尝试在Ubuntu上使用PostgreSQL。我安装了它,一切正常。但是,由于空间限制,我需要更改数据库的位置,所以我尝试了在线指南。
I am trying to use PostgreSQL on Ubuntu. I installed it and everything was working fine. However, I needed to change the location of my database due to space constraints so I tried an online guide to do it.
我继续停止postgresql,创建一个新的空白目录并使用以下权限授予
I proceeded to stop postgresql, create a new empty directory and give it permissions by using
chown postgres:postgres /my/dir/path
这也很好。然后我用
initdb -D /my/dir/path
启用我的数据库。我还将 postgresql.conf
文件中的path_data更改为新目录。
to enable my database. I also changed the path_data in the postgresql.conf
file to my new directory.
当我现在尝试启动时数据库中显示: postgresql服务器无法启动,请检查日志文件
。但是,没有日志文件!当我更改默认目录时,出现了问题。如何解决此问题?
When I now try to start the database, it says: The postgresql server failed to start, please check the log file
. However, there is no log file! Something got screwed up when I changed the default directory. How do I fix this?
推荐答案
首先:您可能会发现使用自定义工具Ubuntu在Ubuntu上管理Pg安装更加容易作为 pg_wrapper
: pg_createcluster
, pg_dropcluster
, pg_ctlcluster
等。这些与Ubuntu启动脚本集成,并将配置移至 / etc / postgresql /
,Ubuntu希望保留该配置,而不是datadir中的PostgreSQL默认值。要移动实际文件的存储位置,请使用符号链接(请参见下文)。
First: You may find it easier to manage your Pg installs on Ubuntu using the custom tools Ubuntu provides as part of pg_wrapper
: pg_createcluster
, pg_dropcluster
, pg_ctlcluster
etc. These integrate with the Ubuntu startup scripts and move the configuration to /etc/postgresql/
where Ubuntu likes to keep it, instead of the PostgreSQL default of in the datadir. To move where the actual files are stored, use a symbolic link (see below).
遇到问题时,如何启动PostgreSQL?
When you have a problem, how are you starting PostgreSQL?
如果通过 pg_ctl
启动它,则应该可以正常工作,因为必须指定数据目录位置。但是,如果您使用的是发行版软件包脚本,则它们不知道您已移动数据目录。
If you're starting it via pg_ctl
it should work fine because you have to specify the data directory location. If you're using your distro package scripts, though, they don't know you've moved the data directory.
在Ubuntu上,您需要在以下位置更改配置 / etc / postgresql
告诉脚本数据目录在哪里,可能是 pg_ctl.conf
或 start.conf
获取相应的版本。我不确定具体细节,因为我从来不需要这样做。这就是为什么:
On Ubuntu, you will need to change configuration in /etc/postgresql
to tell the scripts where the data dir is, probably pg_ctl.conf
or start.conf
for the appropriate version. I'm not sure of the specifics as I've never needed to do it. This is why:
不过,还有更好的方法。使用从您的旧datadir位置到新位置的符号链接。 PostgreSQL和设置脚本将很高兴地遵循它,您无需更改任何配置。
There's a better way, though. Use a symbolic link from your old datadir location to the new one. PostgreSQL and the setup scripts will happily follow it and you won't have to change any configuration.
cd /var/lib/postgresql/9.1/main
mv main main.old
ln -s /new/datadir/location main
我猜是 9.1,因为您没有提供Ubuntu版本或PostgreSQL版本。
I'm guessing "9.1" because you didn't give your Ubuntu version or your PostgreSQL version.
一种替代方法是使用 mount -o bind
将新的datadir位置映射到旧位置,因此没有什么区别。然后将绑定安装添加到 / etc / fstab
使其在重新启动后保持不变。仅当其中一种工具不喜欢符号链接方法时,才需要这样做。我认为 pg_wrapper
等不会成为问题。
An alternative is to use mount -o bind
to map your new datadir location into the old place, so nothing notices the difference. Then add the bind mount to /etc/fstab
to make it persistent across reboots. You only need to do that if one of the tools doesn't like the symbolic link approach. I don't think that'll be an issue with pg_wrapper
etc.
您还应该注意,因为您手动使用initdb时,新的数据目录将直接在数据目录中进行配置,而不是在 / etc / postgresql /
中。
You should also note that since you've used initdb manually, your new datadir will have its configuration directly inside the datadir, not in /etc/postgresql/
.
如果您只使用Ubuntu集群管理脚本,则会更轻松。
It's way easier if you just use the Ubuntu cluster management scripts instead.
这篇关于PostgreSQL启动失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!