更改数据目录后无法启动postgresql

更改数据目录后无法启动postgresql,postgresql,startup,datadirectory,Postgresql,Startup,Datadirectory,我在Debian上使用postgresql。 编辑配置文件后,postgresql服务无法启动: #data_directory = '/var/lib/postgresql/9.4/main' # use data in another directory data_directory = '/opt/data/postgresql/data' (是的,我只是使用自定义目录而不是默认的数据目录) 我在/var/log/syslog Sep 14 10:22:17

我在Debian上使用postgresql。 编辑配置文件后,postgresql服务无法启动:

#data_directory = '/var/lib/postgresql/9.4/main'                # use data in another directory
data_directory = '/opt/data/postgresql/data'
(是的,我只是使用自定义目录而不是默认的数据目录)

我在
/var/log/syslog

Sep 14 10:22:17 thinkserver-ckd postgresql@9.4-main[11324]: Error: could not exec /usr/lib/postgresql/9.4/bin/pg_ctl /usr/lib/postgresql/9.4/bin/pg_ctl start -D /opt/data/postgresql/data -l /var/log/postgresql/postgresql-9.4-main.log -s -o  -c config_file="/etc/postgresql/9.4/main/postgresql.conf" :
Sep 14 10:22:17 thinkserver-ckd systemd[1]: postgresql@9.4-main.service: control process exited, code=exited status=1
Sep 14 10:22:17 thinkserver-ckd systemd[1]: Failed to start PostgreSQL Cluster 9.4-main.
Sep 14 10:22:17 thinkserver-ckd systemd[1]: Unit postgresql@9.4-main.service entered failed state.
/var/log/postgresql/postgresql-9.4-main.log中没有任何内容

Sep 14 10:22:17 thinkserver-ckd postgresql@9.4-main[11324]: Error: could not exec /usr/lib/postgresql/9.4/bin/pg_ctl /usr/lib/postgresql/9.4/bin/pg_ctl start -D /opt/data/postgresql/data -l /var/log/postgresql/postgresql-9.4-main.log -s -o  -c config_file="/etc/postgresql/9.4/main/postgresql.conf" :
Sep 14 10:22:17 thinkserver-ckd systemd[1]: postgresql@9.4-main.service: control process exited, code=exited status=1
Sep 14 10:22:17 thinkserver-ckd systemd[1]: Failed to start PostgreSQL Cluster 9.4-main.
Sep 14 10:22:17 thinkserver-ckd systemd[1]: Unit postgresql@9.4-main.service entered failed state.
谢谢


我终于得到了这个答案:

@兰顿的回答

他说

您应该运行pg_upgradecluster或类似程序,或者只使用pg_createcluster创建一个新集群(这些命令用于debian系统-您没有指定操作系统)

于是我执行了命令:

pg_createcluster-d/opt/data/postgresql/data-l/opt/data/postgresql/log 9.4 ckd

然后:
服务postgresql重启


开始了

检查目录,确保postgres对目录及其内容具有读/写/执行权限。我不确定Debian是否使用SELINUX,但如果使用,请确保文件夹具有正确的上下文,以便postgres可以访问它。(快速检查SELINUX是否涉及的一种方法是临时将其设置为permissive,看看这是否会使问题消失)@Pabtore我已经检查了data directory的权限,我确信这不是问题所在。原因是我需要数据库的初始化。谢谢大家为什么不在安装时指定这个目录?