Modifying the data directory location v17
On RHEL/Rocky Linux/AlmaLinux 8.x | 9.x
On a RHEL/Rocky Linux/AlmaLinux 8.x or 9.x host, the unit file is named edb-as-<xx>.service
, where <xx>
is the EDB Postgres Advanced Server version. It resides in /usr/lib/systemd/system
. The unit file contains references to the location of the EDB Postgres Advanced Server data
directory. Avoid making any modifications directly to the unit file because they might be overwritten during package upgrades.
By default, data files reside under the /var/lib/edb/as17/data
directory. To use a data directory that resides in a nondefault location:
Create a copy of the unit file under the
/etc
directory:cp /usr/lib/systemd/system/edb-as-17.service /etc/systemd/system/
In the
/etc/systemd/system/edb-as-17.service
file, update the following values with the new location of the data directory:Environment=PGDATA=/var/lib/edb/as17/data PIDFile=/var/lib/edb/as17/data/postmaster.pid
Go to bin directory and initialize the cluster with the new location:
./edb-as-17-setup initdb
Start the EDB Postgres Advanced Server service:
systemctl start edb-as-17
Configuring SELinux policy to change the data directory location on RHEL/Rocky Linux/AlmaLinux 8.x | 9.x
By default, the data files reside under the /var/lib/edb/as17/data
directory. To change the default data directory location depending on individual environment preferences, you must configure the SELinux policy:
Stop the server:
systemctl stop edb-as-17
Check the status of SELinux using the
getenforce
orsestatus
command:# getenforce Enforcing # sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Max kernel policy version: 31
View the SELinux context of the default database location:
ls -lZ /var/lib/edb/as17/data drwx------. enterprisedb enterprisedb unconfined_u:object_r:var_lib_t:s0 log
Create a directory for a new location of the database:
mkdir /opt/edb
Move the data directory to
/opt/edb
:mv /var/lib/edb/as17/data /opt/edb/
Create a file
edb-as-17.service
under/etc/systemd/system
to include the location of a new data directory:.include /lib/systemd/system/edb-as-17.service [Service] Environment=PGDATA=/opt/edb/data PIDFile=/opt/edb/data/postmaster.pid
Use the semanage utility to set the context mapping for
/opt/edb/
. The mapping is written to the/etc/selinux/targeted/contexts/files/file.contexts.local
file.semanage fcontext --add --equal /var/lib/edb/as17/data /opt/edb
Apply the context mapping using the restorecon utility:
restorecon -rv /opt/edb/
Reload systemd to modify the service script:
systemctl daemon-reload
With the
/opt/edb
location labeled correctly with the context, start the service:systemctl start edb-as-17