2012-12-27 3 views
8

Tôi đang cố gắng thiết lập máy chủ PostgreSQL dev. Nó đang chạy và tôi có thể tạo vai trò, bảng, v.v. từ dòng lệnh. Tuy nhiên, khi tôi cố gắng áp dụng các diễn biến bằng cách sử dụng Play, tôi nhận được lỗi sau:Diễn biến PostgreSQL: "PSQLException: FATAL: xin lỗi, quá nhiều khách hàng đã"

org.postgresql.util.PSQLException: FATAL: sorry, too many clients already 

Tôi có thể kết nối và nếu tôi đặt sai mục đích, nó sẽ trả về lỗi cú pháp để tôi biết rằng Play có thể kết nối với cơ sở dữ liệu. Tuy nhiên, sau khi quá trình tiến hóa được áp dụng thành công, tôi nhận được lỗi được hiển thị ở trên.

Tôi không hiểu rõ về quản trị PostgreSQl vì vậy tôi không chắc liệu sự cố xảy ra với Play hay cài đặt PostgreSQL của tôi. Tôi vừa cài đặt nó bằng cách sử dụng Postgres.app của Heroku trên máy Mac chạy Mountain Lion.

Đây là những gì được ghi vào giao diện điều khiển:

! @6cnb0blpp - Internal server error, for request [GET /] -> 

play.api.db.evolutions.InvalidDatabaseRevision: Database 'default' needs evolution! [An SQL script need to be run on your database.] 
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1$$anonfun$apply$1.apply$mcV$sp(Evolutions.scala:427) ~[play_2.9.1.jar:2.0.4] 
    at play.api.db.evolutions.EvolutionsPlugin.withLock(Evolutions.scala:448) ~[play_2.9.1.jar:2.0.4] 
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:414) ~[play_2.9.1.jar:2.0.4] 
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:412) ~[play_2.9.1.jar:2.0.4] 
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.3] 
    at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library.jar:0.11.3] 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 9. Exception: null 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 8. Exception: null 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 7. Exception: null 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 6. Exception: null 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 5. Exception: null 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 4. Exception: null 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 3. Exception: null 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 2. Exception: null 
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 1. Exception: null 
[error] application - 

Cảm ơn!

Trả lời

2

Bạn có thể giảm số lượng kết nối được ứng dụng của bạn sử dụng. Đã có lỗi tương tự trên cài đặt mac. Như đã trình bày trong official documentation:

db.default.partitionCount=2 

# The number of connections to create per partition. Setting this to 
# 5 with 3 partitions means you will have 15 unique connections to the 
# database. Note that BoneCP will not create all these connections in 
# one go but rather start off with minConnectionsPerPartition and 
# gradually increase connections as required. 
db.default.maxConnectionsPerPartition=5 

# The number of initial connections, per partition. 
db.default.minConnectionsPerPartition=5 
+0

Tôi đã thiết lập các cài đặt đó trong tệp tin application.conf của mình nhưng vẫn kết thúc với cùng một kết quả. Tôi đã kết nối với PostgreSQL trong quá khứ với Play và tôi chưa bao giờ gặp vấn đề này, tôi thực sự bối rối. – Ryan

5

Số lượng kết nối được phép được đặt trong postgresql.conf với GUC ("Cấu hình hợp nhất Grand") max_connections. Mặc định là 100.

Nhưng trước khi bạn nhắn tin thiết lập, bạn phải tự hỏi mình: tất cả 100 kết nối khác đến từ đâu, trước khi cụm của bạn đạt đến giới hạn? Điều đó thường chỉ đến một lỗi trong chương trình hoặc chương trình của bạn!

Bạn cũng có thể quan tâm connection pooling và điều này article about The Number of Connections trong Postgres Wiki.

+0

Đây là bản cài đặt vanilla Postgres và dự án Play 2.0.4 hoàn toàn mới. Tất cả tôi có cho đến nay là một số mô hình được xác định. Có một bản ghi mà tôi có thể xem xét để tìm ra nơi các kết nối khác đến từ đâu? – Ryan

+0

@Ryan: Bạn có thể thiết lập PostgreSQL để ghi lại khá nhiều thứ. [Bắt đầu bằng cách đọc hướng dẫn tại đây] (http://www.postgresql.org/docs/current/interactive/runtime-config-logging.html). –

3

Postgres.app mặc định là max_connections = 10. Xem ~/Library/Application Support/Postgres/var/postgresql.conf.

Tôi đã sửa lỗi này bằng cách tăng max_connections lên 50. Trên Mountain Lion, tôi cũng phải giảm shared_buffers xuống 500kB cho Postgres để bắt đầu.