对子进程运行 SIGKILL 也会导致数据库崩溃
任何在没有机会清理的情况下终止任何后端的致命信号,例如SIGSEGV
、SIGABRT
、SIGKILL
等,都会导致 postmaster 认为共享内存可能已损坏。它将回滚所有事务,终止所有正在运行的后端,然后重新启动。
PostgreSQL 这样做是为了保护您的数据。如果在后端崩溃之前出现问题,导致它在共享内存上乱涂乱画,那么shared_buffers
可能包含无效数据,这些数据会被刷新到磁盘并替换好页面。
我很确定那是在文档中,但我能找到的只是我认为您在关闭服务器时所指的内容。
无论如何,如果您SIGKILL
是后端,您会看到如下内容:
WARNING: terminating connection because of crash of another server process
DETAIL: The postmaster has commanded this server process to roll back the
current transaction and exit, because another server process exited
abnormally and possibly corrupted shared memory.
HINT: In a moment you should be able to reconnect to the database and
repeat your command.
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.
如果 OOM 杀手杀死后端也会发生这种情况,这就是为什么您应该在 Linux 上关闭内存过度使用的原因。
我在我的博客上写了一些关于 PostgreSQL 要做和不做的事情的指南。值得一看。