I try to show the main problems of transactions with the help of two applications, but I can’t even implement a dirty read. There is a button "withdraw account balance", which should show the data at the current stage of the transaction. Processing a click on it looks like this:

new Select(sConn, trans).ShowDialog(); // вызывается новая форма 

sConn and trans - globally described database connection and transaction. When creating a Select form, the following code is executed:

  private void Select_Load(object sender, EventArgs e) { if (sConn.State != ConnectionState.Open) sConn.Open(); //когда транзакция завершилась, я закрываю соединение, //поэтому надо его снова открыть var sCommand = new NpgsqlCommand { CommandText = "select * from accounts", Connection = sConn, Transaction = trans }; using (var reader = sCommand.ExecuteReader()) { while (reader.Read()) { dataGridView1.Rows.Add((string)reader["login"], ((decimal)reader["balance"]).ToString()); } } } 

And here, for example, in the first application, I execute the following code:

 sConn.Open(); trans = sConn.BeginTransaction(IsolationLevel.ReadUncommitted); 

The isolation level is ReadUncommitted, that is, if I now change the data in another transaction, I will see this change inside the above described transaction. We are checking. In another application, I execute the following code:

  sConn.Open(); trans = sConn.BeginTransaction(); sCommand = new NpgsqlCommand { Connection = sConn, CommandText = @"update accounts set balance = balance + cast(1000 as money) where id = 27", Transaction = trans }; sCommand.ExecuteNonQuery(); 

But! Clicking on the "withdraw account balance" button from 1 application (1 transaction), I get unchanged information. But after all, the isolation level is ReadUncommitted. How to make so that 1 application saw changes?

    1 answer 1

    No Postgresql does not support ReadUncommitted because it is believed that this level of isolation does not provide benefits. https://edu.postgrespro.ru/dev1/dev1_03_arch_mvcc.pdf