断电后,我在 Ubuntu 9.10 Server 上启动 PostgreSQL 8.4 时遇到问题。当我尝试连接到数据库时,它显示:
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request.
当我尝试使用命令启动它时
sudo -u postgres /etc/init.d/postgresql-8.4 start
* Starting PostgreSQL 8.4 database server [ OK ]
Netstat 输出
netstat -tulp
(No info could be read for "-p": geteuid()=1000 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 localhost:postgresql *:* LISTEN -
tcp 0 0 192.168.1.35:svn *:* LISTEN -
tcp 0 0 192.168.1.35:http-alt *:* LISTEN -
tcp 0 0 *:ssh *:* LISTEN -
tcp6 0 0 localhost:postgresql [::]:* LISTEN -
tcp6 0 0 [::]:ssh [::]:* LISTEN -
udp 0 0 *:bootpc *:* -
但仍然不起作用所以让我们重新启动它
sudo -u postgres /etc/init.d/postgresql-8.4 restart
* Restarting PostgreSQL 8.4 database server * The PostgreSQL server failed to start. Please check the log output:
2009-11-30 13:39:37 CET LOG: database system was shut down at 2009-11-30 13:39:33 CET
2009-11-30 13:39:37 CET LOG: autovacuum launcher started
2009-11-30 13:39:37 CET LOG: database system is ready to accept connections
2009-11-30 13:39:37 CET LOG: incomplete startup packet
2009-11-30 13:39:38 CET LOG: server process (PID 2240) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:38 CET LOG: terminating any other active server processes
2009-11-30 13:39:38 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:38 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:37 CET
2009-11-30 13:39:38 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:38 CET LOG: record with zero length at 0/11D464C
2009-11-30 13:39:38 CET LOG: redo is not required
2009-11-30 13:39:38 CET LOG: autovacuum launcher started
2009-11-30 13:39:38 CET LOG: database system is ready to accept connections
2009-11-30 13:39:38 CET LOG: server process (PID 2248) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:38 CET LOG: terminating any other active server processes
2009-11-30 13:39:38 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:38 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:38 CET
2009-11-30 13:39:38 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:38 CET LOG: record with zero length at 0/11D4690
2009-11-30 13:39:38 CET LOG: redo is not required
2009-11-30 13:39:39 CET LOG: autovacuum launcher started
2009-11-30 13:39:39 CET LOG: database system is ready to accept connections
2009-11-30 13:39:39 CET LOG: server process (PID 2256) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:39 CET LOG: terminating any other active server processes
2009-11-30 13:39:39 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:39 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:38 CET
2009-11-30 13:39:39 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:39 CET LOG: record with zero length at 0/11D46D4
2009-11-30 13:39:39 CET LOG: redo is not required
2009-11-30 13:39:39 CET LOG: autovacuum launcher started
2009-11-30 13:39:39 CET LOG: database system is ready to accept connections
2009-11-30 13:39:39 CET LOG: server process (PID 2264) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:39 CET LOG: terminating any other active server processes
2009-11-30 13:39:39 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:39 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:39 CET
2009-11-30 13:39:39 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:40 CET LOG: record with zero length at 0/11D4718
2009-11-30 13:39:40 CET LOG: redo is not required
2009-11-30 13:39:40 CET LOG: autovacuum launcher started
2009-11-30 13:39:40 CET LOG: database system is ready to accept connections
2009-11-30 13:39:40 CET LOG: server process (PID 2272) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:40 CET LOG: terminating any other active server processes
2009-11-30 13:39:40 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:40 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:40 CET
2009-11-30 13:39:40 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:40 CET LOG: record with zero length at 0/11D475C
2009-11-30 13:39:40 CET LOG: redo is not required
2009-11-30 13:39:40 CET LOG: autovacuum launcher started
2009-11-30 13:39:40 CET LOG: database system is ready to accept connections
2009-11-30 13:39:41 CET LOG: server process (PID 2280) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:41 CET LOG: terminating any other active server processes
2009-11-30 13:39:41 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:41 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:40 CET
2009-11-30 13:39:41 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:41 CET LOG: record with zero length at 0/11D47A0
2009-11-30 13:39:41 CET LOG: redo is not required
2009-11-30 13:39:41 CET LOG: autovacuum launcher started
2009-11-30 13:39:41 CET LOG: database system is ready to accept connections
2009-11-30 13:39:41 CET LOG: server process (PID 2288) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:41 CET LOG: terminating any other active server processes
2009-11-30 13:39:41 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:41 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:41 CET
2009-11-30 13:39:41 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:41 CET LOG: record with zero length at 0/11D47E4
2009-11-30 13:39:41 CET LOG: redo is not required
2009-11-30 13:39:41 CET LOG: autovacuum launcher started
2009-11-30 13:39:41 CET LOG: database system is ready to accept connections
2009-11-30 13:39:42 CET LOG: server process (PID 2296) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:42 CET LOG: terminating any other active server processes
2009-11-30 13:39:42 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:42 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:41 CET
2009-11-30 13:39:42 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:42 CET LOG: record with zero length at 0/11D4828
2009-11-30 13:39:42 CET LOG: redo is not required
2009-11-30 13:39:42 CET LOG: autovacuum launcher started
2009-11-30 13:39:42 CET LOG: database system is ready to accept connections
2009-11-30 13:39:42 CET LOG: server process (PID 2304) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:42 CET LOG: terminating any other active server processes
2009-11-30 13:39:42 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:42 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:42 CET
2009-11-30 13:39:42 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:42 CET LOG: record with zero length at 0/11D486C
2009-11-30 13:39:42 CET LOG: redo is not required
2009-11-30 13:39:43 CET LOG: autovacuum launcher started
2009-11-30 13:39:43 CET LOG: database system is ready to accept connections
2009-11-30 13:39:43 CET LOG: server process (PID 2312) was terminated by signal 11: Segmentation fault
2009-11-30 13:39:43 CET LOG: terminating any other active server processes
2009-11-30 13:39:43 CET LOG: all server processes terminated; reinitializing
2009-11-30 13:39:43 CET LOG: database system was interrupted; last known up at 2009-11-30 13:39:42 CET
2009-11-30 13:39:43 CET LOG: database system was not properly shut down; automatic recovery in progress
2009-11-30 13:39:43 CET LOG: record with zero length at 0/11D48B0
2009-11-30 13:39:43 CET LOG: redo is not required
2009-11-30 13:39:43 CET LOG: autovacuum launcher started
2009-11-30 13:39:43 CET LOG: database system is ready to accept connections
[fail]
那么发生了什么事?我该怎么做才能解决这个问题?谢谢回复
答案1
我认为最重要的一句话是:
CET 2009-11-30 13:39:43 CET LOG: database system was not properly shut down; automatic recovery in progress
服务器已启动,但在恢复完成之前无法接受连接。
答案2
准备好从备份中恢复。这很可能是硬件错误,因为 PostgreSQL 非常安全。当然这取决于如何调整。查看此线程:
答案3
好的,现在我到家了,服务器重启后问题就解决了。从本地网络和代理测试,似乎一切都正常
答案4
看起来有些地方非常不对劲——PostgreSQL 确实有安全功能,可以防止断电时出现任何问题。但似乎这些功能没有发挥作用。
其中一个原因是您的硬盘可以欺骗操作系统,说它已经写入了某些内容,但实际上它只是将其保存在写入缓存中。断电时,此缓存会消失,磁盘上的数据会变得不一致。如果是生产系统,并且您没有电池支持的缓存,则应禁用磁盘上的写入缓存:
hdparm -W 0 /dev/sda
但预计数据库写入速度会减慢——现在的写入必须是真实的。
您可以使用 postgresql.conf 中的“synchronous_commit = off”恢复部分性能。您可能会丢失一些近期交易,但数据库将始终保持一致。