2012-11-27 56 views
11

我已經編寫了一個用於批量插入的java代碼。我使用copy命令導入和不同的表創建不同的連接對象,但在執行中,程序則拋出了以下錯誤:如何解決FATAL:超出非超級用戶的連接限制

FATAL: connection limit exceeded for non-superusers 
+2

我敢打賭,你沒有在Java代碼中正確關閉連接。 –

+0

您是否偶然爲每個插頁創建一個新的連接? – lawl0r

回答

5

是否使用連接池?檢查代碼中的連接是否正確關閉。這應該在一個try-finally塊來完成:

Connection connection = dataSource.getConnection(); 
try { 
    .... 
} 
finally { 
    connection.close(); 
} 

如果你真的需要大量的連接,相應地設置在postres的max_connections的屬性。

Documentation

12

您已經超出了PostgreSQL服務器的連接數限制。超級用戶有一些保留的連接。

要增加連接限制,您必須更改它位於PostgreSQL數據目錄中的postgresql.conf(默認值爲100) 。

cat postgresql.conf | grep max_connection max_connections = 100 
     # (change requires restart) 
# Note: Increasing max_connections costs ~400 bytes of shared memory per 
# max_locks_per_transaction * (max_connections + max_prepared_transactions) 

增加限制並重新啓動PostgreSQL實例。

警告:增加連接限制會影響內存。

嘗試使用應用程序或數據庫層中的連接池優化連接。 PostgreSQL上的 可以使用Pgpool2

+0

或者你可以嘗試查殺連接。 – Noumenon

相關問題