Job for postgresql.service failed because the control process exited with error code

Содержание
Введение
Текст ошибки
Решение
Похожие статьи

Введение

Очень часто данная ошибка возникает вследствии того, что не была инициализирована база данных.

Текст ошибки

Например, вы выполнили

sudo systemctl start postgresql

Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.

Проверяете статус

systemctl status -l postgresql.service

postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Wed 2021-06-09 12:10:31 EEST; 1min 18s ago Process: 7223 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=1/FAILURE) Jun 09 12:10:31 localhost.localdomain systemd[1]: Starting PostgreSQL database server... Jun 09 12:10:31 localhost.localdomain systemd[1]: postgresql.service: control process exited, code=exited status=1 Jun 09 12:10:31 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server. Jun 09 12:10:31 localhost.localdomain systemd[1]: Unit postgresql.service entered failed state. Jun 09 12:10:31 localhost.localdomain systemd[1]: postgresql.service failed.

Решение

Попробуйте выполнить инициализацию базы данных (из под пользователя postgres)

postgresql-setup initdb

Initializing database ... OK

Проверка результата

sudo systemctl start postgresql
systemctl status postgresql.service

postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2021-06-09 12:22:00 EEST; 12s ago Process: 7741 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS) Process: 7734 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Main PID: 7746 (postgres) Tasks: 7 CGroup: /system.slice/postgresql.service ├─7746 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432 ├─7749 postgres: logger process ├─7751 postgres: checkpointer process ├─7752 postgres: writer process ├─7753 postgres: wal writer process ├─7754 postgres: autovacuum launcher process └─7755 postgres: stats collector process Jun 09 12:21:59 localhost.localdomain systemd[1]: Starting PostgreSQL database server... Jun 09 12:22:00 localhost.localdomain systemd[1]: Started PostgreSQL database server.

Конечно, источник ошибки может быть совершенно другим.

Часто помогает разобраться status. Желательно выйти из пользователя postgres и выполнить от вашего обычного пользователя

systemctl status postgresql.service

Из полученной информации можно сделать выводы о причинах проблемы

● postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2021-06-10 01:29:02 EEST; 49s ago Process: 12977 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=1/FAILURE) Process: 12970 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Jun 10 01:29:01 host.andrei.com systemd[1]: Starting PostgreSQL database server... Jun 10 01:29:01 host.andrei.com pg_ctl[12977]: pg_ctl: another server might be running; trying to start server anyway Jun 10 01:29:01 host.andrei.com pg_ctl[12977]: LOG: syntax error in file "/var/lib/pgsql/data/postgresql.conf" line 192, near token "/" Jun 10 01:29:01 host.andrei.com pg_ctl[12977]: FATAL: configuration file "/var/lib/pgsql/data/postgresql.conf" contains errors Jun 10 01:29:02 host.andrei.com systemd[1]: postgresql.service: control process exited, code=exited status=1 Jun 10 01:29:02 host.andrei.com systemd[1]: Failed to start PostgreSQL database server. Jun 10 01:29:02 host.andrei.com systemd[1]: Unit postgresql.service entered failed state. Jun 10 01:29:02 host.andrei.com systemd[1]: postgresql.service failed.

Ошибка в файле postgresql.conf

Расположение конфигурационного файла postgresql.conf можно получить выполнив

-bash-4.2$ su - postgres -c "psql -c 'SHOW config_file;'"

Password: config_file ------------------------------------- /var/lib/pgsql/data/postgresql.conf (1 row)

Теперь нужно подставить полученный вами результат в vi

vi /var/lib/pgsql/data/postgresql.conf

И исправить ошибку

Ещё один пример

● postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2021-06-10 01:33:42 EEST; 28s ago Process: 13262 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=1/FAILURE) Process: 13257 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Jun 10 01:33:41 host.andrei.com systemd[1]: Starting PostgreSQL database server... Jun 10 01:33:41 host.andrei.com pg_ctl[13262]: pg_ctl: another server might be running; trying to start server anyway Jun 10 01:33:41 host.andrei.com pg_ctl[13262]: LOG: invalid value for parameter "wal_level": "replica" Jun 10 01:33:41 host.andrei.com pg_ctl[13262]: HINT: Available values: minimal, archive, hot_standby. Jun 10 01:33:41 host.andrei.com pg_ctl[13262]: FATAL: configuration file "/var/lib/pgsql/data/postgresql.conf" contains errors Jun 10 01:33:42 host.andrei.com systemd[1]: postgresql.service: control process exited, code=exited status=1 Jun 10 01:33:42 host.andrei.com systemd[1]: Failed to start PostgreSQL database server. Jun 10 01:33:42 host.andrei.com systemd[1]: Unit postgresql.service entered failed state. Jun 10 01:33:42 host.andrei.com systemd[1]: postgresql.service failed.

Снова ошибка в файле postgresql.conf значение параметра wal_level не допустимо для текущей версии PostgreSQL

Для 9.2 можно выбирать из minimal, archive и hot_standby

Нужно выполнить

vi /var/lib/pgsql/data/postgresql.conf

И заменить replica на hot_standby

Ещё один пример

● postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2021-06-10 01:43:39 EEST; 6s ago Process: 13625 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=1/FAILURE) Process: 13620 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Jun 10 01:43:38 host.andrei.com systemd[1]: Starting PostgreSQL database server... Jun 10 01:43:38 host.andrei.com pg_ctl[13625]: pg_ctl: another server might be running; trying to start server anyway Jun 10 01:43:38 host.andrei.com pg_ctl[13625]: FATAL: lock file "postmaster.pid" already exists Jun 10 01:43:38 host.andrei.com pg_ctl[13625]: HINT: Is another postmaster (PID 25489) running in data directory "/var/lib/pgsql/data"? Jun 10 01:43:39 host.andrei.com systemd[1]: postgresql.service: control process exited, code=exited status=1 Jun 10 01:43:39 host.andrei.com systemd[1]: Failed to start PostgreSQL database server. Jun 10 01:43:39 host.andrei.com systemd[1]: Unit postgresql.service entered failed state. Jun 10 01:43:39 host.andrei.com systemd[1]: postgresql.service failed.

Запущен ещё как минимум один сервер.

Проверить, что сейчас в postmaster.pid можно командой

cat postmaster.pid

25489 /var/lib/pgsql/data 1623237280 5432 /var/run/postgresql localhost 5432001 45

Также можно поискать postgres в выдаче ps

ps -A | grep postgres

25489 pts/1 00:00:00 postgres 25490 ? 00:00:00 postgres 25492 ? 00:00:00 postgres 25493 ? 00:00:00 postgres 25494 ? 00:00:00 postgres 25495 ? 00:00:01 postgres 25496 ? 00:00:00 postgres

kill 25489
systemctl stop postgresql.service
systemctl start postgresql.service
systemctl status postgresql.service

[andrei@host lib]$ systemctl status postgresql.service postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2021-06-10 02:21:42 EEST; 2s ago Process: 14910 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS) Process: 14905 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Main PID: 14913 (postgres) Tasks: 7 CGroup: /system.slice/postgresql.service ├─14913 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432 ├─14914 postgres: logger process ├─14916 postgres: checkpointer process ├─14917 postgres: writer process ├─14918 postgres: wal writer process ├─14919 postgres: autovacuum launcher process └─14920 postgres: stats collector process Jun 10 02:21:41 host.andrei.com systemd[1]: Starting PostgreSQL database server... Jun 10 02:21:42 host.andrei.com systemd[1]: Started PostgreSQL database server.

Похожие статьи
Ошибки
PostgreSQL
psql command not found
ERROR: character with byte sequence 0xd0 0x9a in encoding "e;UTF8"e; has no equivalent in encoding "e;WIN1252"e;
ERROR: database "e;db"e; is being accessed by other users
FATAL password authentication failed for user postgres
ERROR: could not open file "e;/home/user…"e; for reading: Permission denied
ERROR: COPY quote must be a single one-byte character
ERROR: date/time field value out of range
psql: could not connect to server: No such file or directory
pg_basebackup: could not connect to server: No route to host
Failed to stop postgresql.service: Unit postgresql.service not loaded
ERROR: WAL level not sufficient for making an online backup
NOTICE: WAL archiving is not enabled
Job for postgresql.service failed because the control process exited with error code
Please configure_the_postgresql_binary_path

Поиск по сайту

Подпишитесь на Telegram канал @aofeed чтобы следить за выходом новых статей и обновлением старых

Перейти на канал

@aofeed

Задать вопрос в Телеграм-группе

@aofeedchat

Контакты и сотрудничество:
Рекомендую наш хостинг beget.ru
Пишите на info@urn.su если Вы:
1. Хотите написать статью для нашего сайта или перевести статью на свой родной язык.
2. Хотите разместить на сайте рекламу, подходящую по тематике.
3. Реклама на моём сайте имеет максимальный уровень цензуры. Если Вы увидели рекламный блок недопустимый для просмотра детьми школьного возраста, вызывающий шок или вводящий в заблуждение - пожалуйста свяжитесь с нами по электронной почте
4. Нашли на сайте ошибку, неточности, баг и т.д. ... .......
5. Статьи можно расшарить в соцсетях, нажав на иконку сети: