dmitrinesterenko / blog

Blog
http://dmitri.co
1 stars 0 forks source link

What happens in Elixir land when I drop DB connections from PG? #50

Open dmitrinesterenko opened 8 years ago

dmitrinesterenko commented 8 years ago

SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'phoenix_blog' AND pid <> pg_backend_pid();

Elixir or Ecto specifically restarts the connections right away. What happens between terminating these connections and them being re-established anew?

dmitrinesterenko commented 8 years ago

This is from the logs when a connection is terminated:

[error] GenServer #PID<0.331.0> terminating
** (FunctionClauseError) no function clause matching in Postgrex.Protocol.handle_msg/3
    (postgrex) lib/postgrex/protocol.ex:1576: Postgrex.Protocol.handle_msg(%Postgrex.Protocol{buffer: nil, connection_id: 5792, null: nil, parameters: #Reference<0.0.1.2086>, postgres: :idle, queries: 225331, sock: {:gen_tcp, #Port<0.7111>}, timeout: 15000, transactions: :naive, types: 106544}, %{mode: :transaction, notify: #Function<19.91205445/2 in Postgrex.Protocol.notify/1>, sync: :sync}, {:msg_error, [severity: "FATAL", code: "57P01", message: "terminating connection due to administrator command", file: "postgres.c", line: "2872", routine: "ProcessInterrupts"]})
    (postgrex) lib/postgrex/protocol.ex:1670: Postgrex.Protocol.do_sync_recv/4
    (db_connection) lib/db_connection/connection.ex:358: DBConnection.Connection.handle_info/2
    (connection) lib/connection.ex:810: Connection.handle_async/3
    (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:681: :gen_server.handle_msg/5
    (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: :timeout
State: {Postgrex.Protocol, %Postgrex.Protocol{buffer: "", connection_id: 5792, null: nil, parameters: #Reference<0.0.1.2086>, postgres: :idle, queries: 225331, sock: {:gen_tcp, #Port<0.7111>}, timeout: 15000, transactions: :naive, types: 106544}}