postgres apps not scaling to zero

Hey there! Since discovering the feature where you can scale apps to zero instances I have been moving my two hobby apps to this pattern. I have successfully migrated the applications themselves to use this pattern but I cannot seem to get this feature working for the two Postgres databases that they use. I even tried tearing down the old databases and setting up completely new ones and that does not seem to be working either.

One app is a Django app and the other is a Rails app. Both applications will successfully scale down after inactivity but then even after an hour of the apps being down both databases remain up.

I have pulled down both configs using the fly config save --app <database app> command and both of the toml files have the following env section defined.

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

Here is the full fly.toml file for one of the databases, they have not been modified at all since their creation so both files are identical aside from names.

# fly.toml app configuration file generated for gamestone-db on 2023-06-02T19:54:41-05:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "gamestone-db"
primary_region = "iad"

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

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

[[services]]
  protocol = "tcp"
  internal_port = 5432
  auto_start_machines = true

  [[services.ports]]
    port = 5432
    handlers = ["pg_tls"]
  [services.concurrency]
    type = "connections"
    hard_limit = 1000
    soft_limit = 1000

[[services]]
  protocol = "tcp"
  internal_port = 5433
  auto_start_machines = true

  [[services.ports]]
    port = 5433
    handlers = ["pg_tls"]
  [services.concurrency]
    type = "connections"
    hard_limit = 1000
    soft_limit = 1000

[checks]
  [checks.pg]
    port = 5500
    type = "http"
    interval = "15s"
    timeout = "10s"
    path = "/flycheck/pg"
  [checks.role]
    port = 5500
    type = "http"
    interval = "15s"
    timeout = "10s"
    path = "/flycheck/role"
  [checks.vm]
    port = 5500
    type = "http"
    interval = "15s"
    timeout = "10s"
    path = "/flycheck/vm"

[metrics]
  port = 9187
  path = "/metrics"

Noticing the same issue on my test app/Postgres DB.

App has been suspended but Postgres is still running (machine 6e82dd71a6ee87).

I think I was able to get this fixed. I noticed the default config for the postgres apps had auto_start_machines = true but not auto_stop_machines = true. I set that value on both services and redeployed the config and it appears to be working now.

1 Like

That worked for me :+1:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.