Configuring the Hue Server to Store Data in PostgreSQL

To configure the Hue Server to store data in PostgreSQL:

  1. Install required packages.

    To install on RHEL systems:

    $ sudo yum install postgresql-devel gcc python-devel

    To install on SLES systems:

    $ sudo zypper install postgresql-devel gcc python-devel

    To install on Ubuntu or Debian systems:

    $ sudo apt-get install postgresql-devel gcc python-devel
  2. Install the module that provides the connector to PostgreSQL.
    sudo -u hue /usr/share/hue/build/env/bin/pip install setuptools
    sudo -u hue /usr/share/hue/build/env/bin/pip install psycopg2
  3. Install the PostgreSQL server. To install PostgreSQL on a RHEL system:
    $ sudo yum install postgresql-server

    To install PostgreSQL on SLES systems:

    $ sudo zypper install postgresql-server

    To install PostgreSQL on Ubuntu or Debian systems:

    $ sudo apt-get install postgresql
  4. Initialize the data directories.
    $ service postgresql initdb
  5. Configure client authentication.
    1. Edit /var/lib/pgsql/data/pg_hba.conf.
    2. Set the authentication methods for local to trust and for host to password and add the following line at the end.
      host	hue	hue	0.0.0.0/0	md5
  6. Start the PostgreSQL server.
    $ su - postgres
    # /usr/bin/postgres -D /var/lib/pgsql/data > logfile 2>&1 &
  7. Configure PostgreSQL to listen on all network interfaces.
    1. Edit /var/lib/pgsql/data/postgresql.conf and set list_addresses.
      listen_addresses = ‘0.0.0.0’     # Listen on all addresses
  8. Create the hue database and grant privileges to a hue user to manage the database.
    # psql -U postgres
    postgres=# create database hue;
    postgres=# \c hue;
    You are now connected to database 'hue'.
    postgres=# create user hue with password 'secretpassword';
    postgres=# grant all privileges on database hue to hue;
    postgres=# \q
  9. Restart the PostgreSQL server.
    $ sudo service postgresql restart
  10. Verify connectivity.
    psql –h localhost –U hue –d hue 
    Password for user hue: secretpassword
  11. Configure the PostgreSQL server to start at boot. '

    On RHEL systems:

    $ sudo /sbin/chkconfig postgresql on
    $ sudo /sbin/chkconfig --list postgresql
    postgresql          0:off   1:off   2:on    3:on    4:on    5:on    6:off

    On SLES systems:

    $ sudo chkconfig --add postgresql

    On Ubuntu or Debian systems:

    $ sudo chkconfig postgresql on
  12. Using the Cloudera Manager Admin Console, click the service instance for the Hue database you are reconfiguring. The Hue service instance page in Cloudera Manager Admin Console appears.
  13. Click Configuration > View and Edit. In the Category pane, click Advanced under Service-Wide.
  14. Specify the settings for Hue Service Configuration Safety Valve:
    [desktop]
    [[database]]
    host=localhost
    port=5432
    engine=postgresql_psycopg2
    user=hue
    password=secretpassword
    name=hue
  15. Click Save Changes.
  16. The following steps are for restoring the Hue data to the new database. If you would like Hue to start from a fresh state, you can start your Hue service now.
  17. Click Actions and click Synchronize Database.
  18. Determine the foreign key ID.
    bash# su – postgres
    $ psql –h localhost –U hue –d hue
    postgres=# \d auth_permission;
  19. Drop the foreign key that you retrieved in the previous step.
    postgres=# ALTER TABLE auth_permission DROP CONSTRAINT content_type_id_refs_id_XXXXXX;
  20. Delete the rows in the django_content_type table.
    postgres=# TRUNCATE django_content_type CASCADE;
  21. In Hue service instance page, click Actions, and click Load Database. Confirm you want to load the database by clicking Load Database.
  22. Add back the foreign key you dropped.
    bash# su – postgres
    $ psql –h localhost –U hue –d hue 
    postgres=# ALTER TABLE auth_permission ADD CONSTRAINT content_type_id_refs_id_XXXXXX FOREIGN KEY (content_type_id) REFERENCES django_content_type(id) DEFERRABLE INITIALLY DEFERRED;