未运行 - Active:活动(已退出)

a_s*_*ber 10 postgresql linux-mint

Linux 薄荷 20.2

PostgreSQL 9.6。

脚步:

sudo systemctl enable postgresql.service
Run Code Online (Sandbox Code Playgroud)

结果:

Synchronizing state of postgresql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable postgresql
Run Code Online (Sandbox Code Playgroud)

然后像这样重新启动服务:

sudo service postgresql restart
Run Code Online (Sandbox Code Playgroud)

当检查状态时,如下所示:

service postgresql status
Run Code Online (Sandbox Code Playgroud)

我明白了:

postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Wed 2021-08-04 17:33:34 EEST; 47s ago
    Process: 29261 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 29261 (code=exited, status=0/SUCCESS)
Run Code Online (Sandbox Code Playgroud)

为什么服务已退出

这里的内容/var/log/postgresql/postgresql-9.6-main.log

2021-08-05 14:59:14.739 EEST [116538] LOG:  database system was shut down at 2021-08-05 14:59:13 EEST
2021-08-05 14:59:14.741 EEST [116538] LOG:  MultiXact member wraparound protections are now enabled
2021-08-05 14:59:14.746 EEST [116537] LOG:  database system is ready to accept connections
2021-08-05 14:59:14.746 EEST [116542] LOG:  autovacuum launcher started
2021-08-05 14:59:15.210 EEST [116544] [unknown]@[unknown] LOG:  incomplete startup packet
2021-08-05 14:59:55.996 EEST [116537] LOG:  received fast shutdown request
2021-08-05 14:59:55.996 EEST [116537] LOG:  aborting any active transactions
2021-08-05 14:59:55.997 EEST [116542] LOG:  autovacuum launcher shutting down
2021-08-05 14:59:55.998 EEST [116539] LOG:  shutting down
2021-08-05 14:59:56.037 EEST [116537] LOG:  database system is shut down
2021-08-05 14:59:57.069 EEST [119294] LOG:  database system was shut down at 2021-08-05 14:59:56 EEST
2021-08-05 14:59:57.072 EEST [119294] LOG:  MultiXact member wraparound protections are now enabled
2021-08-05 14:59:57.073 EEST [119299] LOG:  autovacuum launcher started
2021-08-05 14:59:57.073 EEST [119290] LOG:  database system is ready to accept connections
2021-08-05 14:59:57.549 EEST [119301] [unknown]@[unknown] LOG:  incomplete startup packet
2021-08-05 15:03:46.004 EEST [119290] LOG:  received fast shutdown request
2021-08-05 15:03:46.004 EEST [119290] LOG:  aborting any active transactions
2021-08-05 15:03:46.004 EEST [119299] LOG:  autovacuum launcher shutting down
2021-08-05 15:03:46.005 EEST [119296] LOG:  shutting down
2021-08-05 15:03:46.018 EEST [119290] LOG:  database system is shut down
2021-08-05 15:03:47.070 EEST [119631] LOG:  database system was shut down at 2021-08-05 15:03:46 EEST
2021-08-05 15:03:47.072 EEST [119631] LOG:  MultiXact member wraparound protections are now enabled
2021-08-05 15:03:47.074 EEST [119630] LOG:  database system is ready to accept connections
2021-08-05 15:03:47.074 EEST [119639] LOG:  autovacuum launcher started
2021-08-05 15:03:47.557 EEST [119642] [unknown]@[unknown] LOG:  incomplete startup packet
Run Code Online (Sandbox Code Playgroud)

这是另一个命令:

pg_lsclusters

Ver Cluster Port Status Owner    Data directory               Log file
9.6 main    5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log
Run Code Online (Sandbox Code Playgroud)

还有一个命令:

sudo pg_isready
/var/run/postgresql:5432 - accepting connections
Run Code Online (Sandbox Code Playgroud)

小智 9

乌班图22.04

\n
sudo apt install -y libpq-dev postgresql postgresql-contrib\n
Run Code Online (Sandbox Code Playgroud)\n

这是结果

\n
$ systemctl status postgresql\n\xe2\x97\x8f postgresql.service - PostgreSQL RDBMS\n Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor    preset: enabled)\n Active: active (exited) since Sun 2022-08-14 14:49:01 CEST; 19min ago\n Main PID: 56596 (code=exited, status=0/SUCCESS)\n    CPU: 5ms\n\n Aug 14 14:49:01 MYHOSTNAME systemd[1]: Starting PostgreSQL RDBMS...\n Aug 14 14:49:01 MYHOSTNAME systemd[1]: Finished PostgreSQL RDBMS.\n\n$ psql --version\npsql (PostgreSQL) 14.4 (Ubuntu 14.4-0ubuntu0.22.04.1)\n\n$ pg_lsclusters\nVer Cluster Port Status Owner    Data directory              Log file\n14  main    5432 online postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log\n\n$ systemctl status postgresql@14-main\n\xe2\x97\x8f postgresql@14-main.service - PostgreSQL Cluster 14-main\n Loaded: loaded (/lib/systemd/system/postgresql@.service; enabled-runtime; vendor preset: enabled)\n Active: active (running) since Sun 2022-08-14 14:49:01 CEST; 28min ago\nMain PID: 56568 (postgres)\n  Tasks: 7 (limit: 19013)\n Memory: 28.8M\n    CPU: 1.287s\n CGroup: /system.slice/system-postgresql.slice/postgresql@14-main.service\n         \xe2\x94\x9c\xe2\x94\x8056568 /usr/lib/postgresql/14/bin/postgres -D /var/lib/postgresql/14/main -c config_file=/etc/postgresql/14/main/postgresql.conf\n         \xe2\x94\x9c\xe2\x94\x8056570 "postgres: 14/main: checkpointer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >\n         \xe2\x94\x9c\xe2\x94\x8056571 "postgres: 14/main: background writer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">\n         \xe2\x94\x9c\xe2\x94\x8056572 "postgres: 14/main: walwriter " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >\n         \xe2\x94\x9c\xe2\x94\x8056573 "postgres: 14/main: autovacuum launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">\n         \xe2\x94\x9c\xe2\x94\x8056574 "postgres: 14/main: stats collector " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >\n         \xe2\x94\x94\xe2\x94\x8056575 "postgres: 14/main: logical replication launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">\n
Run Code Online (Sandbox Code Playgroud)\n

所以在你的情况下:systemctl status postgresql@9.6-main应该显示 postgres active 和 running

\n