正在从postgres获取消息

本文关键字:获取 消息 postgres | 更新日期: 2023-09-27 18:24:02

我正在从C#可执行文件启动postgres中的真空过程。我希望将消息返回到我的可执行文件,但我无法从输出窗口获取消息。

简而言之,我正在使用NPGSQL在postgres中寻找类似的:

// 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;
};

我想用NPGSQL在我的C#代码中得到这个消息。

正在从postgres获取消息

我尝试了下面的代码。它将为您提供完整的执行日志。从这里我刚刚解析了我需要的日志。这不是最好的方法,但我找不到其他东西。

//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();
}

尝试NpgsqlConnection.Notification事件,它是PostgreSQL与SqlConnection.InfoMessage的对应事件。请参阅此处:http://npgsql.projects.pgfoundry.org/docs/api/Npgsql.NpgsqlConnection.Notification.html.