postgresql - Ruby TCP server - ERROR:PG::ConnectionBad: FATAL: remaining connection slots are reserved for non-replication superuser connections -


i have written tcp server receives packets terminal device. tcp server interprets data , saves in database using postgres.

the tcp server multi-threaded. sample of code of moment open db connection , save data looks this;

conn = sequel.connect('postgres://xxxxx:xxxxxxxxxx@127.0.0.1:xxxxx/xxxxxxxxx',:max_connections => 100) # requires pg transactions = conn.from(:transactions) if transactions.insert(serial_number: card_serial, balance_before: balance_before, amount: transaction_amount, balance_after: balance_after, transaction_time: time, terminal_number: terminal_number, terminal_type: terminal_type, created_at: time.now, updated_at: time.now)   response = {message: "tt01000080", status: "success" }   return response else   response = {message: "", status: "failed" }   return response end 

after few packets, db creates error this; error:pg::connectionbad: fatal: remaining connection slots reserved non-replication superuser connections

even adding line conn.disconnect not issue.

the idea connect db every time want create record not best approach. think changing connection pool.

but if still want connect every time, try use block form of connect, assure connection closed after block finishes.

also there no close/disconnect in code, maybe put after return call (which means not executed)

try this:

response = nil sequel.connect('postgres://xxxxx:xxxxxxxxxx@127.0.0.1:xxxxx/xxxxxxxxx',:max_connections => 100) |conn| # requires pg   transactions = conn.from(:transactions)   if transactions.insert(serial_number: card_serial, balance_before: balance_before, amount: transaction_amount, balance_after: balance_after, transaction_time: time, terminal_number: terminal_number, terminal_type: terminal_type, created_at: time.now, updated_at: time.now)     response = {message: "tt01000080", status: "success" }   else     response = {message: "", status: "failed" }   end end return response 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -