Postgresql: не удается запустить службу базы данных, система отключена

Я устанавливаю Postgresql с помощью

sudo apt install postgresql postgresql-contrib

, затем запускаю

sudo systemctl restart postgresql

, затем запускаю

sudo systemctl status postgresql

Он говорит

Active: active (exited) since ... 1s ago

Так что похоже, что команда перезапуска завершается немедленно.

/var/log/postgresql/postgresql-12-main.log говорит:

2020-08-13 23:58:39.553 MSK [47081] LOG:  received fast shutdown request
2020-08-13 23:58:39.607 MSK [47081] LOG:  aborting any active transactions
2020-08-13 23:58:39.613 MSK [47081] LOG:  background worker "logical replication launcher" (PID 47088) exited with exit code 1
2020-08-13 23:58:39.613 MSK [47083] LOG:  shutting down
2020-08-13 23:58:39.888 MSK [47081] LOG:  database system is shut down
2020-08-13 23:58:40.246 MSK [47200] LOG:  starting PostgreSQL 12.2 (Ubuntu 12.2-4) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-8ubuntu1) 9.3.0, 64-bit
2020-08-13 23:58:40.247 MSK [47200] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2020-08-13 23:58:40.293 MSK [47200] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-08-13 23:58:40.470 MSK [47201] LOG:  database system was shut down at 2020-08-13 23:58:39 MSK
2020-08-13 23:58:40.508 MSK [47200] LOG:  database system is ready to accept connections

/etc/init.d/postgresql :

#!/bin/sh
set -e

### BEGIN INIT INFO
# Provides:     postgresql
# Required-Start:   $local_fs $remote_fs $network $time
# Required-Stop:    $local_fs $remote_fs $network $time
# Should-Start:     $syslog
# Should-Stop:      $syslog
# Default-Start:    2 3 4 5
# Default-Stop:     0 1 6
# Short-Description:    PostgreSQL RDBMS server
### END INIT INFO

# Setting environment variables for the postmaster here does not work; please
# set them in /etc/postgresql/<version>/<cluster>/environment instead.

[ -r /usr/share/postgresql-common/init.d-functions ] || exit 0

. /usr/share/postgresql-common/init.d-functions

# versions can be specified explicitly
if [ -n "$2" ]; then
    versions="$2 $3 $4 $5 $6 $7 $8 $9"
else
    get_versions
fi

case "$1" in
    start|stop|restart|reload)
        if [ "$1" = "start" ]; then
            create_socket_directory
        fi
    if [ -z "`pg_lsclusters -h`" ]; then
        log_warning_msg 'No PostgreSQL clusters exist; see "man pg_createcluster"'
        exit 0
    fi
    for v in $versions; do
        $1 $v || EXIT=$?
    done
    exit ${EXIT:-0}
        ;;
    status)
    LS=`pg_lsclusters -h`
    # no clusters -> unknown status
    [ -n "$LS" ] || exit 4
    echo "$LS" | awk 'BEGIN {rc=0} {if (match($4, "down")) rc=3; printf ("%s/%s (port %s): %s\n", $1, $2, $3, $4)}; END {exit rc}'
    ;;
    force-reload)
    for v in $versions; do
        reload $v
    done
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload|status} [version ..]"
        exit 1
        ;;
esac

exit 0

Как мне это исправить?

PS : У меня проблема в том, что Postgresql не запускается . После команды restart ее статус должен быть активен (работает) , в то время как он активен (завершен) .

Я попытался очистить postgresql и запустить

sudo apt-get install postgresql

снова, и это /var/log/postgresql/postgresql-12-main.log:[12108 impression

0
задан 14 August 2020 в 19:11

1 ответ

When you say you purged PostgreSQL, do you mean you did something like sudo apt-get --purge remove postgresql-12? Without the --purge flag, the database files will not be removed, only the software to manage those files.

The log is indicating something is triggering a fast shutdown request, which (according to the PostgreSQL documentation) only happens if another process sends a SIGINT signal (numeric value 2). Something is doing this about 2 or 3 minutes after the database is ready to accept connections. So it appears your server does start, but exits really quick... You need to find out what process is doing this. This could be a rogue process, a Cron job, or the systemctl process that is starting PostgreSQL.

If it is the systemctl process (that is starting PostgreSQL) that is killing it, it is because it can not detect that PostgreSQL is sucessfully started. That is probably due to a configuration issue in PostgreSQL or maybe corrupted data. Try increasing the verbosity of logging or try to start the PostgreSQL server manually (sudo -u postgres /usr/lib/postgresql/12/bin/postgres -D /var/lib/postgresql/12/main -c config_file=/etc/postgresql/12/main/postgresql.conf) to see if you can find a clue.

Or, if you are willing to hose all your data, you could uninstall PostgreSQL and then remove any content still present in /var/lib/postgresql/12 and /etc/postgresql/12. Then do an sudo apt-get install postgresql-12 and you should have a fresh install again.

If it is a roges process or a Cron job or something, you want to find the PID of the process that is signalling the PostgreSQL server, and fix it. To find out what process is signalling PostgreSQL server, you could use killsnoop-bpfcc (sudo apt-get install bpfcc-tools). Start it in a terminal, and wait for your PostgreSQL to die again. You should see a line with column SIG being 2. Column TPID is the process that received the signal, and column PID is the process that is being naughty.

Example of this:

  1. I start sleep 100000 in a console.
  2. In another console I check it's PID: ps -Alf | grep sleep. I find it's 31326.
  3. I start killsnoop-bpfcc and check for TPID 31326.
  4. In yet another console, I kill my sleep command: kill -SIGINT 31326.

The result is:

TIME      PID    COMM             SIG  TPID   RESULT
20:29:43  9097   bash             2    31326  0

So, process 31326 is signalled with SIGINT (2) by process 9097.

0
ответ дан 21 August 2020 в 08:00

Другие вопросы по тегам:

Похожие вопросы: