vendredi 21 septembre 2012
Npgsql 2.0.12.0: patch for querying a slave setting in "Hot Standby" mode for Streaming Replication
Par david techer, vendredi 21 septembre 2012 à 11:35 :: Réplication PostgreSQL
Issue: For Streaming Replication if you have a a slave you are supposed to know that for a slave queries like "unlisten ...", "notify..." are disallowed on the slave-side not on the master-side. Npgsql used this type of query.
Fix: Remove these queries from the Npgsql sources. Below is the expected patch I use to do that. This patch could be improved but it works
Download
You can download it at http://www.davidgis.fr/download/Hot_Standby_SR.txt
--- Npgsql2.0.12.0.src/src/Npgsql/NpgsqlState.cs 2012-01-12 19:44:55.000000000 +0100 +++ Npgsql2.0.12.0.src_new/src/Npgsql/NpgsqlState.cs 2013-01-07 12:17:04.000000000 +0100 @@ -105,7 +105,7 @@ namespace Npgsql //Qlisten notifytest;notify notifytest; Stream stm = context.Stream; string uuidString = "uuid" + Guid.NewGuid().ToString("N"); - PGUtil.WriteString("Qlisten " + uuidString + ";notify " + uuidString + ";", stm); + PGUtil.WriteString("Qlisten " + uuidString + ";", stm); Queuebuffer = new Queue (); byte[] convertBuffer = new byte[36]; for (;;) @@ -129,7 +129,7 @@ namespace Npgsql throw new EndOfStreamException(); case 'Z': //context.Query(new NpgsqlCommand("UNLISTEN *", context)); - using(NpgsqlCommand cmd = new NpgsqlCommand("UNLISTEN *", context)) + using(NpgsqlCommand cmd = new NpgsqlCommand("-- UNLISTEN *", context)) { context.Query(cmd); } --- Npgsql2.0.12.0.src/src/Npgsql/NpgsqlConnector.cs 2012-01-12 19:44:55.000000000 +0100 +++ Npgsql2.0.12.0.src_new/src/Npgsql/NpgsqlConnector.cs 2013-01-07 12:17:44.000000000 +0100 @@ -401,7 +401,7 @@ namespace Npgsql internal void ReleaseRegisteredListen() { //Query(new NpgsqlCommand("unlisten *", this)); - using(NpgsqlCommand cmd = new NpgsqlCommand("unlisten *", this)) + using(NpgsqlCommand cmd = new NpgsqlCommand("-- unlisten *", this)) { Query(cmd); }
Apply the patch
# Download Npgsql 2.0.12 sources and uncompress on the fly wget -q "http://mirrors.ircam.fr/pub/postgresql/projects/pgFoundry/npgsql/_npgsql2/Npgsql2.0.12/Npgsql2.0.12.0.src.tar.bz2" -O - | tar xjf - # Go to Npgsql folder cd Npgsql2.0.12.0.src/ # Download the patch and apply on the fly wget -q http://www.davidgis.fr/download/Hot_Standby_SR.txt -O - | patch -p1