How do I install and configure Postgresql

I have a stable installation of Rocky 9 but still need Postgresql. Downloaded Postgresql and postgresql-server from repository and setup user postgres BUT can’t find the configuration instructions - like how to define the dataspaces where the databases are stored and determine where they get saved. I don’t want them on /var. Can anyone point me at the docs? Thanks in advance.

There are various eamples of how to setup postgresql. CentOS Stream 9 : PostgreSQL 15 : Install : Server World

If you are trying to change the database location, look into the commands postgresql-setup and /usr/sbin/postgresql-new-systemd-unit. The former will refer to you to the latter, which is the primary way of choosing the datadir location. Highly recommended that where ever you decide to have the database, SELinux and user permissions for the postgres user are set correctly.

Also see the red hat docs.

True, the default config of both the postgres service and SELinux is about /var/lib/pgsql.

Alternative, although not as “obvious” as custom systemd unit&co, is to mount (or bind mount) desired location to /var/lib/pgsql. (That is, first move content of /var/lib/pgsql/ to new location and then mount that path to /var/lib/pgsql.) Neither SELinux nor service will know that the files are “not on /var

Thank you for the information; I’m going to have to study it a bit. Selinux isn’t a problem as I have it turned off while I get this new server running to avoid the problems it causes during configuration and software installation. The last item on the agenda is to get Selinux working properly. No experience with your bind mount suggestion so I’ll follow the other way if I can.

The “bind mount” is “an another way”. The “traditional” mount would be just: /               xfs  defaults  1 1
UUID=14..95 /var/lib/pgsql  xfs  defaults  1 2

That is simple. However, what is good size for the filesystem as it will all be only for postgres?
(LVM volume could help in that, but remember that XFS can not shrink.)
If you do mount the UUID=14..95 on other point, you have to additionally create that custom unit.

The bind mount could be:         /               xfs   defaults  1 1
UUID=14..95         /mnt/data       xfs   defaults  1 2
/mnt/data/postgres  /var/lib/pgsql  none  bind      0 0

In that we have mounted a filesystem (that has UUID=14…95) as /mnt/data.
Therefore, we will have access to directory /mnt/data/postgres (and whatever other data we put to /mnt/data).
However, the content of /mnt/data/postgres/ is also seen is /var/lib/pgsql/ due to the bind mount.
Could one get confused because same data is seen in two paths? Of course we can.

I do hope that the “off” means *enabled, permissive". When you enable SELinux that has been disabled, the SELinux labels of every file has to be (re)created. If you enable directly to enforcing mode, then what it blocks, it blocks.

In permissive mode SELinux maintains the file labels, and logs what enforcing would block but allows anyway.
That way you can get the whole list of denials from audit logs. (Except some. For them see man semanage-dontaudit)

First thank you for the additional info. As you might suspect my server knowledge is somewhat limited and rather specific to the environment at hand. Yes, Selinux is in “permissive” mode at the moment and when everything is running properly rules will be adjusted as necessary and set to “enforcing”. That is simply to allow me to get everything installed with the minimum possible grief.

Thanks for the additional info on mounts too, as a general rule my interaction with mount has been to connect/disconnect a USB memory device.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.