无法启动postgresql.service?

22

我正在使用arch linux(4.8.13-1-ARCH)。 我正按照此处的指示设置PostgreSQL。

执行后:

[postgres@BitBox ~]$ initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgres/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

pg_ctl -D /var/lib/postgres/data -l logfile start

成功地,我使用exit命令返回到了我的常规用户。

[postgres@BitBox ~]$ exit
logout

然后,在尝试启动postgresql.service时,我收到了以下错误:

[code_master5@BitBox ~]$ sudo systemctl start postgresql.service
Failed to start postgresql.service: Unit postgresql.service not found.

我甚至无法获取服务的状态:

[code_master5@BitBox ~]$ sudo systemctl status postgresql.service
Unit postgresql.service could not be found.

我卡住了!


你使用了哪个命令来安装PostgreSQL? - Mark Stosberg
8个回答

30

试试这个:

service postgresql-10.service restart
service postgresql-XX.service restart

2
OP 似乎在使用 RHEL7 或 CentOS7,这是通过 systemctl 命令指示的。如果是这样,服务重启命令将无法工作。 - JohnG
对于Manjaro Linux / ArchLinux:systemctl restart postgresql.service - Hartmut Pfarr

20

最后,我找到了解决方法。已经有一个文件存在。

/usr/lib/systemd/system/postgresql-9.6.service

可能是由于存在这个文件的缘故,我无法启动postgresql.service。然后我尝试按以下方式启动postgresql-9.6.service:

[code_master5@BitBox ~]$ sudo systemctl start postgresql-9.6.service
Failed to start postgresql-9.6.service: Unit postgresql-9.6.service not found.

如您所见,输出结果再次失败。

我只是使用sudo删除了该文件,因为我认为由于存在该文件,相关程序可能未能创建postgresql.service文件。然后我重新启动了系统。从那时起它就一切正常,如下所示的输出:

[code_master5@BitBox ~]$ sudo systemctl status postgresql.service
[sudo] password for code_master5: 
 postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor p
Active: active (running) since Sat 2017-01-28 09:31:30 IST; 7h ago
Main PID: 342 (postgres)
Tasks: 6 (limit: 4915)
CGroup: /system.slice/postgresql.service
       ├─342 /usr/bin/postgres -D /var/lib/postgres/data
       ├─358 postgres: checkpointer process   
       ├─359 postgres: writer process   
       ├─360 postgres: wal writer process   
       ├─361 postgres: autovacuum launcher process   
       └─362 postgres: stats collector process   

Jan 28 09:31:26 BitBox systemd[1]: Starting PostgreSQL database server...
Jan 28 09:31:28 BitBox postgres[340]: FATAL:  the database system is starting up
Jan 28 09:31:28 BitBox postgres[340]: LOG:  database system was shut down at 201
Jan 28 09:31:29 BitBox postgres[340]: FATAL:  the database system is starting up
Jan 28 09:31:29 BitBox postgres[340]: LOG:  MultiXact member wraparound protecti
Jan 28 09:31:29 BitBox postgres[340]: LOG:  database system is ready to accept c
Jan 28 09:31:29 BitBox postgres[340]: LOG:  autovacuum launcher started
Jan 28 09:31:30 BitBox systemd[1]: Started PostgreSQL database server.

我肯定想警告所有遇到同样问题的人。但请自担风险去尝试我所做的事情,因为这些是系统文件,乱搞可能会毁了你的周末!

尽管如此,我仍有些困惑,欢迎解释!


12

我发现这两个命令非常方便。虽然这篇文章有些旧了,但未来可能会有其他人受益。

systemctl list-units|grep postgresql
service postgresql-12.service restart

2

对于PostGres 9.4.12,我尝试了以下操作,它是有效的:

./pg_ctl start

您可以检查它的状态:
./pg_ctl status

2

我使用这个命令:

$ /etc/init.d/postgresql start

1

我知道这篇文章已经过时了,但是对于一些可能会路过的人来说,我发现解决方案是这样的(不是删除系统文件,而是在安装后重新加载守护程序以更新服务文件):

$ sudo systemctl daemon-reload # load the updated service file from disk
$ sudo systemctl enable postgresql
$ sudo systemctl start postgresql

0

请确保初始化数据库。

sudo find / -name post*-setup sudo /usr/bin/postgresql-setup initdb


0

接下来的步骤对我们的测试服务器很有帮助。

通过SSH连接到您的服务器。

然后切换用户:

$ sudo su - postgres

检查Postgres状态:

pg_ctl status

停止数据库:

pg_ctl stop

检查是否存在服务器进程:

ps axf|grep postg

启动Postgres服务:

sudo systemctl start postgresql.service 

或者

sudo systemctl start postgresql

然后检查状态:

systemctl status postgresql.service 

或者

systemctl status postgresql

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接