I am running a locally hosted instance of Metabase on my Windows 10 laptop. I had setup a startup service to automatically start Metabase on my computers startup using the nssm utility as outlined here
After migrating to Postgres as my application database for Metabase, I am trying to set my startup service so that when the service starts, it uses the Postgres DB as the application database as opposed to H2 however it seems like it wants to recreate the H2 database every time and starts my whole instance of Metabase from scratch.
Is there any way to configure the startup service using the nssm utility so that it recognizes the Postgres DB?
EDIT: I figured out how to do this. See my solution below.
I'm guessing that the issue here is that when Metabase launches, it does not see (for some reason) the environment variables that have the connection details and that's why you are seeing that it creates the H2 database over and over. Can you check if the environment variables can be read?
I really don't know anything about nssm, but I'm sure you run a BAT file? if that's the case, try setting the env vars on that BAT file so you make sure that the Metabase service is launched with all the necessary configurations to connect to the DB
Thanks again @Luiggi The nssm utility was recommended in another post (see my link above). It's a simple third party utility that provides a GUI to create a windows service.
That said, although you didn't solve my problem, you pointed me in the right direction by making me think through the whole idea about setting the environment variables, so many thanks!
For anyone else who is looking to do something similar, this is what I did:
Follow the instructions to install a service using the nssm install utility as outlined in the link I posted above. Fill the information out on the 'Application' tab but do not install the service yet
Scroll to the right, you will find an 'Environment' tab:
Note: I did not enable the option to 'Replace default environment...'
Now install the service
Restart your computer and the service should start running on startup. Navigate to your localhost and see if Metabase is running and log in. (if service is not running, go to the properties of the service and make sure startup type is set to 'Automatic')
Of course, this is all dependent on the fact that you have installed Postgres on your computer and that you have created an empty database. Also, that you have migrated Metabase to that database following Metabases instructions here
I would recommend one addition thing. The only way I knew that this worked is that I backed up my H2 database files and then deleted them from the Metabase install location. After I re-started, I monitored the install location to see if Metabase re-built the H2 db files and it did not. If it does, that means your instance of Metabase is not utilizing the Postgres database and you will need to re-configure.