Postgresql cannot start after changing data_directory

I am using postgresql in Debian. The postgresql service cannot start after editing the configuration file:

#data_directory = '/var/lib/postgresql/9.4/main' # use data in another directory data_directory = '/opt/data/postgresql/data' 

(yes, I just use a custom directory instead of the default data_directory file)

I found the log in /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. 

And nothing in /var/log/postgresql/postgresql-9.4-main.log

Thanks.


I finally got this answer:

What does this error mean in PostgreSQL?

@langton.

He said that

you have to run pg_upgradecluster or similar or just create a new cluster with pg_createcluster (these commands are for debian systems - you did not specify your OS)

So, I ran the command:

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

And then: service postgresql restart

it started!

+7
postgresql startup datadirectory
source share

No one has answered this question yet.

See related questions:

1719
How to exit PostgreSQL command line utility: psql
1591
PostgreSQL "DESCRIBE TABLE"
1522
Show tables in PostgreSQL
922
How to start a PostgreSQL server on Mac OS X?
904
How can I drop all tables in a PostgreSQL database?
850
How to change PostgreSQL user password?
211
How to thoroughly clean and reinstall postgresql on ubuntu?
7
How to update PostgreSQL using PostGIS?
one
ERROR after changing data_directory PostgreSQL in ubuntu 16.04
0
PostgreSQL starts in a few minutes, then fails

All Articles