Postgres Auto Stop, Scale to Zero

I have a Postgres app and I think I have it configured to auto stop/start and scale to zero but it always remains running. I do notice that there are two [[services]] blocks but not really sure how they got there. I thought I just edited what was already in the fly.toml.
This is what my fly.toml looks like:

app = "earthwize-pg"
primary_region = "mia"

[checks.pg]
interval = "15s"
path = "/flycheck/pg"
port = 5_500
timeout = "10s"
type = "http"

[checks.role]
interval = "15s"
path = "/flycheck/role"
port = 5_500
timeout = "10s"
type = "http"

[checks.vm]
interval = "15s"
path = "/flycheck/vm"
port = 5_500
timeout = "10s"
type = "http"

[env]
FLY_SCALE_TO_ZERO = "1h"
PRIMARY_REGION = "mia"

[[metrics]]
path = "/metrics"
port = 9_187

[[mounts]]
destination = "/data"
source = "pg_data"

[[services]]
auto_start_machines = true
auto_stop_machines = true
internal_port = 5_432
min_machines_running = 0
protocol = "tcp"

  [services.concurrency]
  hard_limit = 1_000
  soft_limit = 1_000
  type = "connections"

  [[services.ports]]
  handlers = [ "pg_tls" ]
  port = 5_432

[[services]]
auto_start_machines = true
internal_port = 5_433
protocol = "tcp"

  [services.concurrency]
  hard_limit = 1_000
  soft_limit = 1_000
  type = "connections"

  [[services.ports]]
  handlers = [ "pg_tls" ]
  port = 5_433

Hi… In general, you shouldn’t need both FLY_SCALE_TO_ZERO and auto_stop_machines. The first one halts the Machine from within, using a periodic internal count of the number of connections.

Many older images, however, had a bug that caused the stop condition to never actually trigger, :dragon:.


Basically, it was looking for “number of connections > 0”, but that query itself was a connection…


If you’re using PG Flex v0.0.38+ (where scale-to-zero was introduced) and sift through the logs (fly logs -a db-app-name), you should see Current connection count is N every hour or so, which will tell you that the feature is at least trying to work. [Albeit possibly impeded by the glitch above.]

Also, what does fly image show -a db-app-name report, at the moment?