#132 selinux issue when starting a postgres-server via systemd
Opened by groovyman. Modified

Dear friends,

i am trying to run a new postgres instance with/on:

  • a mounted raid drive
  • a separate process managed by an individual systemd-service
  • with its on listener port

Here is the problem:
I can run the postmaster directly from my postgres account when i perform the call:
$ postmaster -D /mnt/raider/data/postgres/dbaccounting/defTS

But when i try to start the database using systemd-start the invoked postmaster is not able to access the data directory, where the postgres files are located:
/mnt/raider/data/postgres/dbaccounting/defTS

When i disable selinux, the server can be started by systemd, so there seems to be a problem with systemd, when it invokes the postmaster. The generated systemd file is using the postgres user, so this should be fine.

Let me show you, how i build the database:
**my file system file setting **
1) chown -R postgres:postgres /mnt/raider/data/postgres
2) semanage fcontext -a -t postgresql_db_t /mnt/raider/data/postgres/dbaccounting/defTS
3) semanage fcontext -a -t postgresql_db_t /mnt/raider/data/postgres/dbaccounting
4) setfattr -n security.selinux -v "system_u:object_r:postgresql_db_t:s0" /mnt/raider/data/postgres/dbaccounting

my setting when i create the database
5) semanage port -a -t postgresql_port_t -p tcp 5600
6) firewall-cmd --permanent --add-port=5600/tcp
7) firewall-cmd --add-port=5600/tcp
8) firewall-cmd --reload

then create my database unit
9) postgresql-new-systemd-unit --unit accounting --datadir /mnt/raider/data/postgres/dbaccounting/defTS

the create an initialize a new db
10) postgresql-setup --initdb --unit accounting --port 5600

So the systemd-service file was created by the postgresql-new-systemd-unit command and the created service files looks good. The technical user for the database is beeiing set, but for any reasons, the invoked 'postgresql' seems not to have all selinux credentials. Any ideas ?


Metadata