ted.strauss
ted.strauss

Reputation: 4339

How to override or disable Postgrex timeout setting: 15 seconds?

Working on an Elixir app. There's a Scraper function that copies data from a Google Spreadsheet into a postgres database via the Postgrex driver. The connection through the Google API works fine, but the function always times out after 15 seconds.

01:48:36.654 [info] Running MyApp.Endpoint with Cowboy using http://localhost:80
Interactive Elixir (1.6.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Scraper.update
542
iex(2)> 01:48:55.889 [error] Postgrex.Protocol (#PID<0.324.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.445.0> timed out because it owned the connection for longer than 15000ms

I have tried changing the 15_000 ms timeout setting everywhere in the source, but it seems the setting has been compiled into binary. I am not an erlang/elixir developer, just helping a client install the app for the purposes of demoing. My question is:

Upvotes: 0

Views: 1788

Answers (2)

denis.peplin
denis.peplin

Reputation: 9831

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "postgres",
  database: "my_app_dev",
  hostname: "localhost",
  timeout: 600_000,
  ownership_timeout: 600_000,
  pool_timeout: 600_000

Look at timeout and ownership_timeout. These values are set to 600 seconds. And probably not of them are necessary.

Also I want to say that once I had to remove everything from _build and recompile an application to have this values actually applied.

Upvotes: 2

m3characters
m3characters

Reputation: 2290

When issuing a query with postgrex, the last argument can be a keyword list of options.

Postgrex.query!(pid, "AN SQL STATEMENT;", [], timeout: 50_000, pool_timeout: 40_000)

https://hexdocs.pm/postgrex/Postgrex.html#query/4

Upvotes: 1

Related Questions