How do I install postgresql in Silverblue

I want to create a postgresql database in silverblue for a web app I am thinking of making. I was wondering what’s the best way? Would it just work fine in a regular toolbox? I tried following instructions in a comment in this post but it didn’t seem to work.

https://discussion.fedoraproject.org/t/error-when-install-postgresql-on-fedora-silverblue/77678

Come to think about it, it is over a year old now.

I would recommend running PostgreSQL in a container via podman and exposing the port to connect to it locally.

1 Like

Would toolbox work? I have heard that toolbox is just an implementation of podman. Would it just be basically creating a container and then going sudo dnf install postgresql?

How do I expose the port locally? Does that mean I will be able to access the database when I’m not in the container and even in another container?

To expose the port you’d run something like:

podman run -e POSTGRES_PASSWORD=your_password -p 5432:5432 postgres:13.4

This would let you access the DB via 5432 on your host.

More info about the official Postgresql image here: Docker

2 Likes

toolbox uses podman to run containers but it does not run a service manager. Using a podman container directly will be easier as you can just use a regular official PostgreSQL container/docker image.

toolbox containers share the host network AFAIK.

1 Like

Thanks, will look into this!

Is there a single command I would be able to type to create a podman container, using one of the Docker images?

Yes, that’s what the podman run command that I gave as an example does.

1 Like

How do I run it after making it? Do I keep running the same command? Does that build the container from the docker image again?

You can use the podman stop/start commands to keep using the same container, though if you want a persistent database you should check the Docker hub page for the image that I linked to, which explains how to keep a persistent database in a directory outside of the container.

1 Like

Thank you!

For development purposes, I have made it my good practice that I have such a folder structure:

  • ProjectName folder
    • Database folder
      • data folder
      • dbstart.sh script
      • dbstop.sh script
    • WebServer folder
      • htdocs folder
      • webstart.sh script
      • webstop.sh script

Basically the dbstart.sh script contains something like this:

podman run \
	--cgroup-manager=cgroupfs  \
	-d \
	-e POSTGRES_USER=xxxxxxx \
	-e POSTGRES_PASSWORD=yyyyyy \
	--privileged \
	--mount type=bind,source=./data,target=/var/lib/postgresql/data  \
	-p 5432:5432 \
	--name postgresProjectName \
	postgres:12

So, the data folder is mapped to the data folder inside the container, and the container is a throwaway one, everything that is needed is in the data folder. Of course postgres is similarly configured inside the container to have everything in the data folder. For example the log files will be in data/log.

Using similar setup for MariaDB.

Similar to this, the webstart.sh script may look like this:

podman run \
	--privileged  \
	--mount type=bind,source=./htdocs,target=/usr/local/tomcat/webapps \
	-p 8080:8080 \
	--name tomcatProjectName \
	-d tomcat:9

Then you can even have many database servers and instances in separate folders and containers and many web server instances for separate modules of your application so that they not confict each other, just map them at different ports. You can then start which ones you need and keep the other off.

I should stress again, that this is for development purposes only.

4 Likes