我正在尝试停止已经在 Ubuntu 服务器上运行的 Postgresql 9.3 数据库,但我收到以下消息:
root@myprodserver:~# sudo /etc/init.d/postgresql stop
* No PostgreSQL clusters exist; see "man pg_createcluster"
如果我尝试列出集群,我会得到一个空结果:
root@myprodserver:~# pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
我尝试运行一个创建集群:
root@myprodserver:~# pg_createcluster 9.3 main
Configuring already existing cluster (configuration: /etc/postgresql/9.3/main, data: /var/lib/postgresql/9.3/main, owner: 106:114)
Error: move_conffile: required configuration file /var/lib/postgresql/9.3/main/postgresql.conf does not exist
The database is up and running. The response shows that a cluster exists. I've restarted many times the service in the past without error messages.
以下是sudo ps aux | grep postgres
的结果:
root 673 0.0 0.0 11748 2232 pts/5 R+ 15:57 0:00 grep --color=auto postgres
postgres 1044 0.0 0.2 293560 17868 ? S 2017 87:45 /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf
postgres 1288 0.2 1.7 294156 142248 ? Ss 2017 657:18 postgres: checkpointer process
postgres 1289 0.2 1.7 293700 140836 ? Ss 2017 694:24 postgres: writer process
postgres 1290 0.0 0.0 293560 7476 ? Ss 2017 140:10 postgres: wal writer process
postgres 1291 0.0 1.3 294508 107148 ? Ss 2017 55:46 postgres: autovacuum launcher process
postgres 1292 0.0 0.0 105220 3772 ? Ss 2017 172:17 postgres: stats collector process
postgres 7669 0.0 0.2 296244 17700 ? Ss 12:04 0:02 postgres: adempiere postgres ::1(49525) idle
postgres 7671 0.0 0.6 298716 54004 ? Ss 12:04 0:00 postgres: adempiere adempiere_produzione ::1(49526) idle
postgres 7855 0.0 0.4 295844 38160 ? Ss 12:04 0:00 postgres: adempiere adempiere_produzione ::1(49527) idle
postgres 8068 0.0 0.2 294884 18324 ? Ss 12:06 0:00 postgres: adempiere adempiere_produzione ::1(49528) idle
postgres 10115 0.0 1.9 308236 159916 ? Ss 14:25 0:05 postgres: adempiere adempiere_produzione 192.107.YY.XXX(55631) idle
(continues)
服务器 PG 关闭后无法启动,集群(数据库实例(丢失。
最后我已经能够恢复它。我必须纠正一些东西(见下文(,然后我执行了:
sudo pg_createcluster 9.3 main
然后你应该启动它
sudo /etc/init.d/postgresql start
系统回复:正在配置现有的集群....
在这些情况下要做的事情:- 检查所有配置文件和数据文件是否在正确的文件夹中- 检查文件Postmaster.opts是否指向正确的位置
如果主集群(通常为"main"(仍未启动,您可以使用以下命令创建新集群:
pg_createcluster 9.3 cluster2
然后将数据库备份还原到新群集。
控制PG集群的命令:
列出群集
pg_lsclusters
启动/停止群集
pg_ctlcluster <pg version> <cluster name> <start|stop>
pg_ctlcluster 9.3 main start
pg_ctlcluster 9.3 clust2 stop
停止群集 - 删除活动连接
pg_ctlcluster -m fast 9.3 clust2 stop
从 ps aux
的输出中可以看出,在每行的开头,每个 postgres 进程都作为用户 postgres 运行。
据此,运行是安全的:sudo pkill -u postgres
,它发送信号让进程自行关闭,而不是以蛮力方式。