Configuring a PostgreSQL Database for Ranger or Ranger KMS

Complete the following steps to configure a PostgreSQL database instance for Ranger or Ranger KMS.

Configuring a PostgreSQL Database for Ranger or Ranger KMS on RHEL/Centos

  1. Run the following command to install PostgreSQL server:
    sudo yum install postgresql-server
  2. Initialize the Postgres database and start PostgreSQL:
    sudo postgresql-setup initdb
    sudo systemctl start postgresql
  3. Optional: Configure PostgreSQL to start on boot:
    sudo systemctl enable postgresql
  4. Update the postgresql.conf file, which is usually found in /var/lib/pgsql/data or /var/lib/postgresql/data:
    • Uncomment and change #listen_addresses = 'localhost' to listen_addresses = '*'
    • Uncomment the #port = line and specify the port number (the default is 5432)
    • Optional: Uncomment and change #standard_conforming_strings= to standard_conforming_strings = off
  5. Update the pg_hba.conf file, which is usually found in /var/lib/pgsql/data or /etc/postgresql/<version>/main:
    • Add the following line to allow connection to the Ranger database from any host:

      host    ranger          rangeradmin     0.0.0.0/0               md5
  6. Restart PostgreSQL:
    sudo systemctl restart postgresql
  7. The PostgreSQL database administrator should be used to create the Ranger databases. The following series of commands could be used to create the rangeradmin user and grant it adequate privileges. Be sure to replace 'password' with a strong password.
    echo "CREATE DATABASE ranger;" | sudo -u postgres psql -U postgres
    echo "CREATE USER rangeradmin WITH PASSWORD 'password';" | sudo -u postgres psql -U postgres
    echo "GRANT ALL PRIVILEGES ON DATABASE ranger TO rangeradmin;" | sudo -u postgres psql -U postgres
  8. Install the PostgreSQL JDBC driver. If you would like to use the PostgreSQL JDBC driver version shipped with the OS repositories, run the following command:
    yum install postgresql-jdbc*
    You can also download the JDBC driver from the official PostgreSQL JDBC Driver website – https://jdbc.postgresql.org/.
  9. Rename the Postgres JDBC driver .jar file to postgresql-connector-java.jarand copy it to the /usr/share/java directory. The following copy command can be used if the Postgres JDBC driver .jar file is installed from the OS repositories:
    cp /usr/share/java/postgresql-jdbc.jar /usr/share/java/postgresql-connector-java.jar
  10. Confirm that the .jar file is in the Java share directory:
    ls /usr/share/java/postgresql-connector-java.jar
  11. Change the access mode of the .jar file to 644:
    chmod 644 /usr/share/java/postgresql-connector-java.jar
Ensure that the Ranger Solr and Ranger HDFS plugins are enabled. See Additional Steps for Apache Ranger for details.

Configuring a PostgreSQL Database for Ranger on Ubuntu

  1. Run the following command to install PostgreSQL server:
    apt-get install postgresql-server
  2. Initialize the Postgres database and start PostgreSQL:
    sudo postgresql-setup initdb
    sudo systemctl start postgresql
  3. Optional: Configure PostgreSQL to start on boot:
    sudo systemctl enable postgresql
  4. Edit the /var/lib/pgsql/data/postgresql.conf file:
    • Uncomment and change #listen_addresses = 'localhost' to listen_addresses = '*' *
    • Uncomment the #port = line and specify the port number (the default is 5432)
    • Optional: Uncomment and change #standard_conforming_strings= to standard_conforming_strings = off
  5. Update the /var/lib/pgsql/data/pg_hba.conf file to allow connection to the Ranger database from any host:
    • Add the following line:

      host    ranger          rangeradmin     0.0.0.0/0               md5
  6. Restart PostgreSQL:
    sudo systemctl restart postgresql
  7. The PostgreSQL database administrator should be used to create the Ranger databases. The following series of commands could be used to create the rangeradmin user and grant it adequate privileges. Be sure to replace 'password' with a strong password.
    echo "CREATE DATABASE ranger;" | sudo -u postgres psql -U postgres
    echo "CREATE USER rangeradmin WITH PASSWORD 'password';" | sudo -u postgres psql -U postgres
    echo "GRANT ALL PRIVILEGES ON DATABASE ranger TO rangeradmin;" | sudo -u postgres psql -U postgres
  8. Install the PostgreSQL connector:
    apt-get install postgresql-jdbc
  9. Copy the connector .jar file to the Java share directory:
    cp /usr/share/java/postgresql-jdbc.jar /usr/share/java/postgresql-connector-java.jar
  10. Confirm that the .jar file is in the Java share directory:
    ls /usr/share/java/postgresql-connector-java.jar
  11. Change the access mode of the .jar file to 644:
    chmod 644 /usr/share/java/postgresql-connector-java.jar
Ensure that the Ranger Solr and Ranger HDFS plugins are enabled. See the following topic, Additional Steps for Ranger, for details.