postgresql не может запуститься после изменения data_directory
Я использую postgresql на Debian. Служба 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
Благодарю.
Я наконец получил этот ответ:
Что означает эта ошибка в PostgreSQL?
ответ @langton.
Он сказал, что
вы должны запустить pg_upgradecluster или аналогичный, или просто создать новый кластер с pg_createcluster (эти команды для систем Debian - вы не указали свою ОС)
Итак, я выполнил команду:
pg_createcluster -d /opt/data/postgresql/data -l /opt/data/postgresql/log 9.4 ckd
А потом:service postgresql restart
Началось!
1 ответ
Если время простоя разрешено и у вас уже есть базы данных с данными в старом расположении кластера, вам нужно только физически скопировать данные в новое расположение.
Это более или менее распространенная операция, если в разделе не хватает места.
# Check that current data directory is the same that
# the one in the postgresql.conf config file
OLD_DATA_DIR=$(sudo -u postgres psql --no-psqlrc --no-align --tuples-only --quiet -c "SHOW data_directory;")
echo "${OLD_DATA_DIR}"
CONFIG_FILE=$(sudo -u postgres psql --no-psqlrc --no-align --tuples-only --quiet -c "SHOW config_file;")
echo "${CONFIG_FILE}"
# Stop PostgreSLQ
systemctl stop postgresql
# Change the data directory in the config
# Better to do it with an editor, instead of sed
NEW_DATA_DIR='/opt/data/postgresql/data'
sed -i "s%data_directory = '${OLD_DATA_DIR}'%data_directory = '${NEW_DATA_DIR}'%" "${CONFIG_FILE}"
# Move/Copy the data for example using rsync
rsync -av --dry-run "${OLD_DATA_DIR}" "${NEW_DATA_DIR}"
# Take care with the classical issues of rsync and end backslashes
rsync -av "${OLD_DATA_DIR}" "${NEW_DATA_DIR}"
# Rename the old dir, just to avoid missunderstandings and set
# check the permissions on the new one
# Start postgres
systemctl start postgresql
# Check that everything goes well and eventually drop the old data
# Make sure that the logs and everything else is where you want.