Installing the psycopg2 Python package for PostgreSQL database

If you are using PostgreSQL as a backend database for Data Explorer on Cloudera Base on premises 7.3.x, then you must install a version of the psycopg2 package to be at least 2.9.6 on all Data Explorer hosts. The psycopg2 package is automatically installed as a dependency of Cloudera Manager Agent, but the version installed is often lower than 2.9.3.

Before you begin, you must disable the postgresql10 section from the cloudera-manager.repo file as follows:
  1. SSH in to the Cloudera Manager host as an Administrator.
  2. Locate the repository file (e.g., /etc/yum.repos.d/cloudera-manager.repo on RHEL/CentOS/OEL or /etc/apt/sources.list.d/ on Ubuntu).
  3. Set enabled=0 under the [postgresql10] section as follows:
    [postgresql10]
    name=Postgresql 10
    baseurl=https://archive.cloudera.com/postgresql10/redhat8/
    gpgkey=https://archive.cloudera.com/postgresql10/redhat8/RPM-GPG-KEY-PGDG-10
    enabled=0 
    gpgcheck=1
    module_hotfixes=true
  4. Save the file and exit.

The following steps apply to RHEL 8, RHEL 9, and Rocky Linux 9:

  1. SSH into the Data Explorer server host as a root user.
  2. Before you install psycopg2-binary package, run the following pip command to install dependencies and to ensure smooth psycopg2 installation:
    yum install -y postgresql postgresql-devel python3-devel gcc
  3. Install the psycopg2-binary package as follows:
    Python 3.12
    python3.12 -m pip install --upgrade pip
    python3.12 -m pip install psycopg2-binary
    python3.12 -m pip show psycopg2-binary
    Python 3.11
    python3.11 -m pip install psycopg2-binary
    python3.11 -m pip show psycopg2-binary
    Python 3.9
    python3.9 -m pip install psycopg2-binary
    python3.9 -m pip show psycopg2-binary
    Python 3.8
    python3.8 -m pip install psycopg2-binary
    python3.8 -m pip show psycopg2-binary
  4. Repeat these steps on all the Data Explorer server hosts.
If you get the "Error: pg_config executable not found" error while installing the psycopg2-binary package, then run the following commands to install the postgresql, postgresql-devel, python-devel packages:
yum install postgresql postgresql-devel python-devel

The following steps apply to RHEL 9, as the minimum version of Python is 3.11:

  1. SSH into the Data Explorer server host as a root user.
  2. Install pip for Python as follows:
    dnf install -y postgresql postgresql-devel python3.12-devel gcc
  3. Add the /usr/local/bin path to the PATH environment variable:
    export PATH=$PATH:/usr/local/bin
    echo $PATH
  4. Install the psycopg2-binary package as follows:
    Python 3.12
    python3.12 -m pip install --upgrade pip
    python3.12 -m pip install psycopg2-binary
    Python 3.11
    python3.11 -m pip install --upgrade pip
    python3.11 -m pip install psycopg2-binary
  5. Repeat these steps on all the Data Explorer server hosts.
If you get the "Error: pg_config executable not found" error while installing the psycopg2-binary package, then run the following commands to install the postgresql, postgresql-devel, python-devel packages:
yum install postgresql postgresql-devel python-devel
  1. SSH into the Data Explorer host as a root user.
  2. Install the psycopg2 package dependencies for SLES by running the following commands:
    zypper install xmlsec1
     zypper install xmlsec1-devel
     zypper install xmlsec1-openssl-devel
  3. Install the postgresql-devel package corresponding to your database version by running the following command:
    zypper -n postgresql[***DB-VERSION***]-devel
  4. Add the location of the installed postgresql-devel package to the PATH environment variable by running the following command:
    export PATH=$PATH:/usr/local/bin
  5. Install the psycopg2 package by running the following command:
    pip3.12 install psycopg2==2.9.6 --ignore-installed
  1. SSH into the Data Explorer host as a root user.
  2. Install the psycopg2 package dependencies for Ubuntu by running the following commands:
    apt-get install -y xmlsec1
    apt-get install libxmlsec1-openssl
    apt-get install libpq-dev python3-pip -y
  3. Install the python3-dev and libpq-dev packages by running the following command:
    apt install python3-dev libpq-dev
  4. Add the location of the installed postgresql-devel package to the PATH environment variable by running the following command:
    export PATH=$PATH:/usr/local/bin
  5. Install the psycopg2 package by running the following command:
    pip3.12 install psycopg2==2.9.6 --ignore-installed