Modifying the data directory location v16

On RHEL/CentOS 7.x or RHEL/Rocky Linux/AlmaLinux 8.x | 9.x

On a RHEL/CentOS 7.x or 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/as16/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-16.service /etc/systemd/system/
  • In the /etc/systemd/system/edb-as-15.service file, update the following values with the new location of the data directory:

  • Go to bin directory and initialize the cluster with the new location:

    ./edb-as-16-setup initdb
  • Start the EDB Postgres Advanced Server service:

    systemctl start edb-as-16

Configuring SELinux policy to change the data directory location on RHEL/CentOS 7.x or RHEL/Rocky Linux/AlmaLinux 8.x | 9.x

By default, the data files reside under the /var/lib/edb/as16/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-16
  • Check the status of SELinux using the getenforce or sestatus command:

    # getenforce
    # 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/as16/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/as16/data /opt/edb/
  • Create a file edb-as-16.service under /etc/systemd/system to include the location of a new data directory:

    .include /lib/systemd/system/edb-as-16.service
  • 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/as16/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-16