Air-gapped

Info

PostgreSQL version 16.9 or higher is required.

Info

To install PostgreSQL in an air-gapped environment, download the required packages on a preparation machine and then transfer them to the air-gapped server. The preparation machine should have internet access and run the same operating system version as the target server.

Debian, Ubuntu

Prepare packages

  1. On the preparation machine, run commands.

# Set PostgreSQL version, replace "16" by the version you want POSTGRESQL_VERSION=16 # Install apt-rdepends sudo apt install -y apt-rdepends # Automated repository configuration sudo apt install -y postgresql-common echo "" | sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh # Automated get VERSION_CODENAME source /etc/os-release echo "Using VERSION_CODENAME: $VERSION_CODENAME" # Add PostgreSQL software repository sudo tee /etc/apt/sources.list.d/pgdg.sources <<EOF Types: deb deb-src URIs: https://apt.postgresql.org/pub/repos/apt Suites: $(echo $VERSION_CODENAME)-pgdg Architectures: amd64 Components: main Signed-By: /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc EOF sudo apt update # Download package mkdir -p postgresql-$POSTGRESQL_VERSION-offline && cd postgresql-$POSTGRESQL_VERSION-offline apt-get download postgresql-$POSTGRESQL_VERSION postgresql-contrib # Download dependencies too apt-rdepends -p postgresql-$POSTGRESQL_VERSION \ | grep -v "^ " \ | grep -v "^debconf" \ | xargs -I {} bash -c 'apt-get download "{}" || true' cd ..
  1. Copy the postgresql-<version>-offline folder to a USB drive or secure transfer medium.

  2. Move it to the air-gapped server.

Install PostgreSQL

  1. On the target server, insert the USB drive or secure transfer medium.

  2. Run the commands below in the postgresql-<version>-offline folder.

# Install sudo dpkg -i ./*.deb # Configures PostgreSQL to start automatically whenever the system boots sudo systemctl enable --now postgresql # Setup login password sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '<your_password>';"

Open connection

  1. Locate the PostgreSQL data directory on your server.

/etc/postgresql/<version>/main/
  1. To allow remote connections, open the postgresql.conf file and configure the following setting:

listen_addresses = '*'
  1. To allow MetaDefender Cluster services to access the database, open the pg_hba.conf file and add the following rule.

hostssl all all 0.0.0.0/0 scram-sha-256
  1. Restart the PostgreSQL service to apply the changes.

sudo systemctl restart postgresql

Rocky, RHEL 9

Prepare packages

  1. On the preparation machine, run commands.

# Set PostgreSQL version, replace "16" by the version you want POSTGRESQL_VERSION=16 # Install the repository RPM sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm # Disable the built-in PostgreSQL module sudo dnf -qy module disable postgresql # download packages (not install) mkdir -p postgresql-$POSTGRESQL_VERSION-offline \ && cd postgresql-$POSTGRESQL_VERSION-offline \ && sudo dnf download --resolve --alldeps --downloaddir . postgresql$POSTGRESQL_VERSION-server \ && sudo dnf download --resolve --alldeps --downloaddir . postgresql$POSTGRESQL_VERSION-contrib \ && cd ..
  1. Copy the postgresql-<version>-offline folder to a USB drive or secure transfer medium.

  2. Move it to the air-gapped server.

Install PostgreSQL

  1. On the target server, insert the USB drive or secure transfer medium.

  2. Run the commands below in the postgresql-<version>-offline folder.

# Set PostgreSQL version, replace "16" by the version you want POSTGRESQL_VERSION=16 # Install sudo dnf install -y ./*.rpm --disablerepo * --nobest --skip-broken # Configures PostgreSQL to start automatically whenever the system boots sudo /usr/pgsql-$POSTGRESQL_VERSION/bin/postgresql-$POSTGRESQL_VERSION-setup initdb sudo systemctl enable --now postgresql-$POSTGRESQL_VERSION # Setup login password sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '<your_password>';"
Warning

Sometimes, other dependencies require upgrading. Example:


You should manually download the dependencies using the command dnf download --resolve --alldeps --downloaddir . <package_names> . Then copy them to the postgresql-<version>-offline folder and install again.

Open connection

  1. Locate the PostgreSQL data directory on your server.

/var/lib/pgsql/16/data
  1. To allow remote connections, open the postgresql.conf file and configure the following setting:

listen_addresses = '*'
  1. To allow MetaDefender Cluster services to access the database, open the pg_hba.conf file and add the following rule.

host all all 0.0.0.0/0 scram-sha-256
  1. Restart the PostgreSQL service to apply the changes.

sudo systemctl restart postgresql-16