Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Messages back from postgres

I am initiating a vacuum process in postgres from a C# executable. I want the message to be returned back to my executable, but i I'm not able to get the message back from output window.

In short, I'm looking for equivalent of this in postgres using NPGSQL like:

// Display messages this code is for SQL server to reteive data back from message tab

conn.InfoMessage += delegate(object sender, SqlInfoMessageEventArgs e) {
  stdmForm.txtLastSQLMessages.Text +`=` "\n" + e.Message;
};

I want to get this message in my C# code using NPGSQL.

like image 427
prvnsaini Avatar asked Jul 19 '13 18:07

prvnsaini


1 Answers

I tried the code below. It will give you the complete execution log. From this I just parsed my required log. It's not the best way but I was not able to find anything else.

//log the Vacuum command information
NpgsqlEventLog.Level = LogLevel.Debug;
NpgsqlEventLog.LogName = VacuumLogFilePath + "rolling.log"; 
NpgsqlEventLog.EchoMessages = false;

try
{
    //Run the Vacuum Command
    NpgsqlCommand comm = new NpgsqlCommand("VACUUM VERBOSE ANALYZE", connection); 
    comm.ExecuteNonQuery();

}
like image 91
prvnsaini Avatar answered Sep 23 '22 18:09

prvnsaini