我有一个带有 Ubuntu 14.04.5 LTS (GNU/Linux 2.6.32-042stab127.2 x86_64) 的 VPS,并且还安装了 Postgresql。我在 ruby on rails 应用程序中使用 Postgresql。突然我的应用程序停止工作并抛出错误
无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接?
$psql -V
psql (PostgreSQL) 11.0 (Ubuntu 11.0-1.pgdg14.04+2)
$pg_config --version
PostgreSQL 11.0 (Ubuntu 11.0-1.pgdg14.04+2)
$postgres -V
The program 'postgres' is currently not installed. You can install it by typing:
apt-get install postgres-xc
$locate bin/postgres
/usr/lib/postgresql/11/bin/postgres
/usr/lib/postgresql/9.3/bin/postgres
/usr/lib/postgresql/9.4/bin/postgres
/usr/lib/postgresql/9.5/bin/postgres
$/usr/lib/postgresql/11/bin/postgres -V
postgres (PostgreSQL) 11.0 (Ubuntu 11.0-1.pgdg14.04+2)
$pg_lsclusters
9.3 main 5432 down postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log
11 main 5433 down postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
postgres 状态为 down
$service postgresql status
9.3/main (port 5432): down
11/main (port 5433): down
$systemctl status postgresql.service
postgresql.service
Loaded: error (Reason: No such file or directory)
Active: inactive (dead)
$systemctl status [email protected]
[email protected]
Loaded: error (Reason: No such file or directory)
Active: inactive (dead)
$grep -H '^port' /etc/postgresql/*/main/postgresql.conf /etc/postgresql/11/main/postgresql.conf:port = 5433
/etc/postgresql/9.3/main/postgresql.conf:port = 5432
我正在尝试启动 Postgresql 9.3
$service postgresql start 9.3
* Starting PostgreSQL 9.3 database server
* Failed to issue method call: Unit [email protected] failed
to load: No such file or directory. See system logs and 'systemctl
status [email protected]' for details.
$sudo systemctl start postgresql
Failed to issue method call: Unit postgresql.service failed to load: No
such file or directory. See system logs and 'systemctl status
postgresql.service' for details.
$/etc/init.d# /etc/init.d/postgresql start
* Starting PostgreSQL 11 database server
* Failed to issue method call: Unit [email protected] failed to
load: No such file or directory. See system logs and 'systemctl status
[email protected]' for details.
[fail]
* Starting PostgreSQL 9.3 database server
* Failed to issue method call: Unit [email protected] failed to
load: No such file or directory. See system logs and 'systemctl status
[email protected]' for details.
[fail]
我无法启动 PostgreSQL。我不明白它为什么突然宕机,直到昨天它工作正常。
根据
pg_lsclusters
,您的 PostgreSQL 实例9.3/main
并11/main
没有启动。这解释了“无法连接到服务器”错误。postgresql.service
并且[email protected]
是systemd
单元文件,您的问题似乎是它们在systemctl
需要时丢失了。请注意,
systemctl
默认情况下不会在 Ubuntu 14.04 上安装,因为它是最后一个不使用 systemd 的版本(请参阅Is Ubuntu 14.04 using systemd?)。但不知何故systemd
安装在你的系统上。使用 systemd,通常 postgres 服务文件应该由包自动创建
/lib/systemd/system-generators/postgresql-generator
,由postgresql-common
包提供,并最终*.service
以/lib/systemd/system/
.我无法猜测为什么该部分无法在您的系统上工作或停止工作。
如何手动启动 PostgreSQL
该
pg_ctlcluster
命令独立于 systemd 或 upstart 工作。您应该能够使用以下命令启动 PostgreSQL 实例:就我而言
systemd
,它在 Ubuntu 14.04 上运行,但最早从 16.04 开始支持。所以我运行了 sudo apt-get remove systemd 在我的情况下systemd
是在 Ubuntu 14.04 上运行的,但最早从 16.04 开始支持。所以我跑了之后,postgresql 服务已成功运行。