BUG #13757: Able to write to postgres even when the main process has been killed - Mailing list pgsql-bugs

From vijaysam@mailworks.org
Subject BUG #13757: Able to write to postgres even when the main process has been killed
Date
Msg-id 20151105190132.14034.15191@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #13757: Able to write to postgres even when the main process has been killed  (Kevin Grittner <kgrittn@ymail.com>)
Re: BUG #13757: Able to write to postgres even when the main process has been killed  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      13757
Logged by:          Vijay
Email address:      vijaysam@mailworks.org
PostgreSQL version: 9.4.1
Operating system:   Linux
Description:

Hi,

I am trying to do some tests with basic replication using postgres.

The following is my setup and the scenario.
Postgres 9.4.1 on 2 servers setup as Master and Standby with
repmgr(configured for failover as well). This works fine.

Connection is through java client library.

I connect to the cluster using the multiple IP connection string and load
balancing to connect only to the master server always.
eg.
jdbc:postgresql://192.168.1.100:5432,192.168.1.101:5432/testdb?targetServerType=master

This works fine as long as I shutdown one server and when failover takes
place to the other server. Please note, on proper shutdown of the master
server to failover and continue which the newly promoted standby server to
master. Things work fine.

But, when I try to kill -9 the master server main postgres process. The
client code from java is able to continue to write to the postgres db which
was the old master as there was a connection established to this server and
the connection keeps allowing write to happen as thought the server is still
running. I understand kill -9 is a bad thing. But is it supposed to be
allowed to write with a connection which has been already established though
the servers main process has been killed or crashed whatever and postgres
server on the old master is quite in an inconsistent state? I was able to
write to this server where the main postgres process was killed and the
client process through the java connection was still able to write as though
the server is still properly running without any exceptions or errors. I can
see process that was created for the connection from my java application on
the same server where I killed the main postgres process, which seems to
happily handle the writes and keeps writing to the transaction log/ and even
the database (because, I had a call to a select count(*) from the test table
and I can see the count being increased after each insert).

Once I killall the postgres processes on the server where I specifically
killed the main process, every thing is normal where the client java code
switches to properly write to the newly promoted master.

The same goes if I do a killall postgres to start with instead of a "kill -9
PID" to kill the specific postgres process. If I do a killall postgres then
the proper switching of connection happens and the writes properly go to the
newly promoted master.

If anyone has come across this issue, please respond.

Please note, I understand a kill -9 should have quite weird problems. But is
this problem expected as, with the main postgres process down, I am still
happily able to write to the database which is in an inconsistent state,
behaving as though nothing happened as far as the client connection goes.

Thanks,
-vijay

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Memory leak with PL/Python trigger
Next
From: sdiz@sdiz.net
Date:
Subject: BUG #13756: jsonb_path_ops gin index produce empty result on nested array