Database access from Self host server (linux laptop)

Hello Team,
My team and I built a self-hosted server for running the farmbot.
Everything works well.

I have run the farmbot system for moving the bot and taking pictures.
Now I want to access this data (pics and other data) from the database.

Questions:

  1. In the case of the self-hosted server, Where is the database stored (path)?

  2. How to access the database through Postgres in linux?
    ( I have a good hold on Postgres usage but I am unable to figure the path to access the database.
    And its asking for the password, even when a method is set to trust in post-HBA file)

1 Like

@gowtham you can find the database files in docker_volumes/db.
You can find the image files in storage/, but this is probably going to be difficult to navigate by hand since they are stored in a content addressable manner used by ActiveStorage (a component of Ruby on Rails). A better idea is to get the URLs via the Rails console.

First, open the rails console:

sudo docker-compose run web rails c

Then get all the image URLs:

Image.all.map(&:attachment_url).each{|url| puts url}

You will see a list of URLs for images printed to the screen that you can open individually. A few folks on the forum have created CURL scripts that will automatically download the images from the API, also.

DISCLAIMER: It is better to think of this as a Rails application rather than a PostgreSQL application. The same can be said for trying to access images off of the file system. If you are not familiar with Rails, I would encourage you to give the Rails documentation a look before proceeding. I mention this because accessing the database directly (especially if you are experienced with PostgreSQL, but not with Rails) can inadvertently cause data corruption. Rails expects the data to be updated in specific ways and it is possible to put the application into a bad state if the data is modified in a way that ActiveRecord was not expecting. Accessing the database for read-only operations should be fine, however.

2 Likes