Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku: what is the difference between "heroku ps:exec" and "heroku run bash"?

What is the difference between heroku ps:exec and heroku run bash? I am just trying to understand the concept. Both seem to be establishing an SSH-tunnel to a remote container/dyno. So why does heroku ps:exec require a dyno-restart on the first use? It seems this command is more generic (since it uses a default shell), so what needs to be configured/installed for it?

like image 646
Phil Avatar asked Mar 05 '23 15:03

Phil


1 Answers

heroku run bash creates a standalone (ie not associated with any particular process) that has your application code available and gives you a bash session. This is helpful for running one-off tasks like a database migration it can also be helpful to debug issues where you need to look at the filesystem.

heroku ps:exec tunnels to a dyno that is already running as part of your formation. For instance, if you had 5 web dynos you could tunnel directly to web.3 for instance. This is useful in situations where a dyno is exhibiting issues (memory pressure or high load for example). Being able to connect to the problematic dyno is very useful for debugging. You should also note that your config vars (ie environment vars set on the heroku settings tab) are not set in heroku ps:exec session.

I can't say for certain why a restart is required but I imagine that some configuration needs to change to enable a connection to a dyno already running in the fleet.

like image 148
RangerRanger Avatar answered May 18 '23 17:05

RangerRanger