Railway proxy closes idle DB connections after ~60s, causing CONNECTION_CLOSED errors on stale sockets. Set idle_timeout=20s and max_lifetime=5m so postgres-js recycles connections before they die. Also fix sendCommand to fall back to persistent device ID on reconnect.