无法启动 postgresql.service?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41867841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:22:19  来源:igfitidea点击:

Unable to start postgresql.service?

postgresqlarchlinuxsystemd

提问by code_master5

I'm using arch linux (4.8.13-1-ARCH). I'm trying to set up PostgreSQL as instructed here.

我正在使用 arch linux (4.8.13-1-ARCH)。我正在尝试按照此处的说明设置 PostgreSQL 。

After performing

演出后

[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

successfully, I returned to the my regular user using exit command.

成功后,我使用 exit 命令返回到我的普通用户。

[postgres@BitBox ~]$ exit
logout

Then, while trying to start postgresql.service, I got the following error:

然后,在尝试启动 postgresql.service 时,出现以下错误:

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

I'm not even getting the status of the service:

我什至没有得到服务的状态:

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

I'm stuck!

我被卡住了!

回答by Emin Kad?o?lu

Try this:

尝试这个:

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

回答by code_master5

Finally, I figured this one out. There was already a file present

最后,我想通了这一点。已经存在文件

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

So, may be due to the presence of this file, I was not able to start postgresql.service. Then I tried to start postgresql-9.6.service as follows:

所以,可能是由于这个文件的存在,我无法启动 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.

And, as you can see the output, again it failed.

而且,正如您所看到的输出,它再次失败了。

I simply deleted the file using sudo as I thought may be postgresql.service file is not being created by relevant program due to the presence of this file. Then I restarted the system. It's working fine since then, as you can see the output below:

我只是使用 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.

I would surely like to warn all those having same problem. Please do whatever I did at your own risk. Since these are system files. Messing with these can spoil your weekend!

我肯定想警告所有有同样问题的人。请自行承担我所做的一切。因为这些是系统文件。搞乱这些会破坏你的周末!

I am still a bit confused on this though. Explanations are welcome!

尽管如此,我仍然有点困惑。欢迎解释!