一主一备模式下,进行简单测试,一段时间后显示:fail to allocate a zone
通过提供的工具收集日志,结果是死锁导致的:
2022-08-03 14:14:59.865 62ea1252.5025 postgres 139780237289216 PostgreSQL JDBC Driver 1538516 dn_6001_6002 40P01 3377699720531497 [BACKEND] ERROR: deadlock detected 2022-08-03 14:14:59.865 62ea1252.5025 postgres 139780237289216 PostgreSQL JDBC Driver 1538516 dn_6001_6002 40P01 3377699720531497 [BACKEND] DETAIL: Process 139780237289216 waits for ShareLock on transaction 1538556; blocked by process 139780876728064. Process 139780876728064 waits for AccessExclusiveLock on tuple (19808,36) of (relation 16390, bucket 0) of database 15484; blocked by process 139779890865920. Process 139779890865920 waits for ShareLock on transaction 1538516; blocked by process 139780237289216. Process 139780237289216: delete from users where user_name = $1
线程代码:
public class DelectTest extends Thread { String sql = "delete from users where user_name = ?;" + "delete from users where user_name = ?;" + "delete from users where user_name = ?"; JDBCUtil jdbc = new JDBCUtil(); public void run(){ Long startTime = System.currentTimeMillis(); Long endTime = null; boolean flag = true; while(flag){ try { DelectTest.sleep(800); PreparedStatement statement = jdbc.getStatement(sql); statement.setString(1,"zhangsan"); statement.setString(2,"zhaoliu"); statement.setString(3,"longqi"); int i = statement.executeUpdate(); System.out.println("成功地删除了"+ i +"条数据"); //MyLogger.info("成功地删除了"+ i +"条数据"); endTime = System.currentTimeMillis(); if(endTime - startTime > 86400000*3){ flag = false; } } catch (SQLException throwables) { throwables.printStackTrace(); //MyLogger.warning(throwables.getMessage()); } catch (InterruptedException e) { e.printStackTrace(); } finally { jdbc.closeSource(); } } } }
之后将测试关闭程序,只要对数据库进行写操作,就会显示fail to allocate a zone,需要重启数据库才能恢复。请问这是为什么呢?怎么解决