Fix error on port 5432 during rails app deploy with kamal

04 Avril 2024

After solving the same issue locally, I faced an error on port 5432 when I tried to deploy my Rails app with Kamal on a Hetzner VPS. In this project, I'm using PostgreSQL. 
When I attempted to deploy through the Kamal deploy command, I encountered an error indicating that port 5432 wasn't available. 
Thanks to the community, I found that we need to remove `postmaster.pid`.

Here's the process I used to fix it:

1. Log in to your server via SSH:

ssh [email protected]


2. Navigate to locate the file:

root@Blog:~# ls -a
.              .cache                   .profile
..             .cloud-locale-test.skip  .ssh
.bash_history  .docker                  blog-db
.bashrc        .kamal


root@Blog:~# ls blog-db/data/
PG_VERSION            pg_snapshots/
base/                 pg_stat/
global/               pg_stat_tmp/
pg_commit_ts/         pg_subtrans/
pg_dynshmem/          pg_tblspc/
pg_hba.conf           pg_twophase/
pg_ident.conf         pg_wal/
pg_logical/           pg_xact/
pg_multixact/         postgresql.auto.conf
pg_notify/            postgresql.conf
pg_replslot/          postmaster.opts
pg_serial/            postmaster.pid


3. Remove the file:

rm postmaster.pid


Job done! You can check by deploying through the Kamal deploy command to see if it's okay.

Happy coding!