简体   繁体   English

JDBC executeBatch() 在 PostgreSQL 中没有错误地挂起

[英]JDBC executeBatch() hangs without error in PostgreSQL

I try load 50000 rows in table with 200 columns.我尝试在包含 200 列的表中加载 50000 行。 I do executeBatch() every 1000 rows.我每 1000 行执行一次executeBatch() And I get lock for this table.我得到了这张桌子的锁。 The same code works for MS SQL and Oracle but with postgresql I get this issue.相同的代码适用于 MS SQL 和 Oracle,但使用postgresql我遇到了这个问题。 When I decrease executeBatch number from 1000 to 75 all works correctly.当我将executeBatch编号从 1000 减少到 75 时,一切正常。

Is there any param in config file witch responding for batch buffer size?配置文件中是否有任何参数可以响应批处理缓冲区大小?

Same issue http://www.postgresql.org/message-id/c44a1bc0-dcb1-4b57-8106-e50f9303b7d1@79g2000hsk.googlegroups.com同样的问题http://www.postgresql.org/message-id/c44a1bc0-dcb1-4b57-8106-e50f9303b7d1@79g2000hsk.googlegroups.com

When I execute insert statements in batch for tables with a large number of columns occurs hanging, when call statement.executeBatch().当我为具有大量列的表批量执行插入语句时,调用 statement.executeBatch() 时会发生挂起。 It is specific for postgresql jdbc driver.它特定于 postgresql jdbc 驱动程序。 To avoid this issue we should increase buffer size params(SO_SNDBUF, SO_RCVBUF) for socket.为了避免这个问题,我们应该增加套接字的缓冲区大小参数(SO_SNDBUF,SO_RCVBUF)。

For Windows we have to create such params in register:对于 Windows,我们必须在寄存器中创建这样的参数:

[HKEY_LOCAL_MACHINE \SYSTEM \CurrentControlSet \Services \Afd \Parameters]

DefaultReceiveWindow(type=DWORD) = 1640960(Decimal) DefaultSendWindow(type=DWORD) = 1640960(Decimal) DefaultReceiveWindow(type=DWORD) = 1640960(Decimal) DefaultSendWindow(type=DWORD) = 1640960(Decimal)

This number(1640960) I get from internet as general recommendation!这个号码(1640960)我从互联网上得到的一般建议! And it works for me.它对我有用。

Generally you need to look for the following things.通常,您需要查找以下内容。

  1. Are you able to actually get a lock for the table?你真的能够获得表的锁吗?
  2. Do you have other java code locks that you are waiting for?你还有其他的java代码锁在等待吗?

In general the first place to check is the pg_stat_activity system view which will show you the query being executed and whether it is active, idle, waiting, etc. Then if it is waiting (ie waiting is t ), then you will want to check the pg_locks view and see what else may have a lock on anything in the relation.一般来说,首先要检查的是pg_stat_activity system视图,它会显示正在执行的查询以及它是否处于活动状态、空闲状态、等待状态等。然后如果它正在等待(即waitingt ),那么您将需要检查pg_locks视图,看看还有什么可能锁定关系中的任何东西。

If waiting is not true, then you are better off checking your java code for client-side locks but since this works for MySQL and Oracle, I assume this is less of an issue.如果等待不是真的,那么你最好检查你的 java 代码是否有客户端锁,但由于这适用于 MySQL 和 Oracle,我认为这不是一个问题。

There is one other thing to be aware of.还有一件事需要注意。 I am not sure about MySQL and Oracle here but PostgreSQL limits you to one query at a time per connection.我不确定这里的 MySQL 和 Oracle,但 PostgreSQL 将您限制为每次连接一次查询。 You might have some locking there?你可能有一些锁定那里?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM