I'm running a query and loading the results into a Stream using Postgrex, like so:
{:ok, host_pid} = Postgrex.start_link(hostname: "somewhere.hostname.io", username: "myuser", password: "mypass", database: "mydb")
Postgrex.transaction(host_pid, fn(conn) ->
# do query that takes 5 seconds
# with timeout set to be really big
query = Postgrex.prepare!(conn, "", "SELECT pg_sleep(5)", timeout: 50_000)
stream = Postgrex.stream(conn, query)
result_to_iodata = fn(%Postgrex.Result{rows: rows}) -> format_query_result(rows) end
Enum.into(stream, File.stream!("eg"), result_to_iodata)
end)
But I get the following error:
localhost$ mix run lib/MyPostgrexScript.exs
** (DBConnection.ConnectionError) connection not available and request was dropped
from queue after 2950ms. You can configure how long requests wait in the queue
using :queue_target and :queue_interval. See DBConnection.start_link/2 for more information
(db_connection) lib/db_connection.ex:836: DBConnection.transaction/3
lib/MyPostgrexScript.exs:3: MyPostgrexModule.sleep/0
(elixir) lib/code.ex:767: Code.require_file/2
(mix) lib/mix/tasks/run.ex:147: Mix.Tasks.Run.run/5
Since I want to do cumbersome queries which will certainly require more than 2950ms to run, I am wondering how I configure Postgrex to let my query take more time. I read about the :timeout option at https://hexdocs.pm/postgrex/Postgrex.html#transaction/3 but I'm not sure to how include it, or whether it's what I'm looking for.
Any guidance is immensely appreciated, thanks!
Like this (see the last line):
Whenever the elixir docs define a function like this:
optsis a keyword list, e.g:However, if a keyword list is the last argument in a function call, the keyword list can be written like this:
and the function definition will receive the three arguments
In any case, the default for :timeout is:
and the error says:
Because
2950 < 15000it doesn't seem like the :timeout value is the source of the error.The error message continues:
This explains how to configure those timeouts:
Also,
But, if you haven't touched those defaults, then I wonder why you are seeing
2950msin the error message and not something closer to 50ms or 1000ms.