VMware-Virtual-Platform: sudo systemctl restart postgresql
Warning: The unit file, source configuration file or drop-ins of postgresql.service changed on disk. Run 'systemctl daemon-reload' to reload units.
这个警告信息表示 PostgreSQL 的服务配置文件(postgresql.service
)或其相关配置在磁盘上被修改过,但 systemd(系统服务管理器)尚未重新加载这些更改 。
解决方法:
-
运行以下命令重新加载 systemd 单元配置:
sudo systemctl daemon-reload
这会确保 systemd 识别到最新的服务配置变更。
-
然后再次尝试重启 PostgreSQL:
sudo systemctl restart postgresql
执行完 daemon-reload
后,后续的 restart
操作就不会再出现这个警告了
原因说明:
-
当您修改了 PostgreSQL 的 systemd 服务文件(如
相关的覆盖配置(/lib/systemd/system/postgresql.service
或 /etc/systemd/system/postgresql.service
)或/etc/systemd/system/postgresql.service.d/*.conf
)时,systemd 需要重新加载配置才能生效。 -
daemon-reload
不会中断正在运行的服务,它只是更新 systemd 的内存中的配置。
其他注意事项:
-
如果问题仍然存在,可以检查服务状态和日志:
#查看状态
sudo systemctl status postgresql
#查看日志
journalctl -u postgresql -n 50 --no-pager -
如果是通过包管理器(如
apt
或yum
)升级 PostgreSQL,通常它会自动处理daemon-reload
,但手动修改配置时需要显式触发。
执行完 daemon-reload
后,后续的 restart
操作就不会再出现这个警告了。