Here’s the link to the excellent guide on how to install Mastodon instance on FreeBSD. If you’re doing it in FreeBSD Jail you may find use for “Installing PostgreSQL in FreeBSD jail” article.