General

Using Your Own Hub Database

CodeSonar uses PostgreSQL binaries that come with CodeSonar to automatically perform all actions associated with starting, running, and stopping the hub database. These include the actions needed to create, configure, administer, upgrade, start, and stop the database. The use of a database cluster that is not managed by the hub in this fashion is neither supported nor recommended.

If you wish to distribute the resource costs of the hub server and the hub database across multiple machines, we recommend that you use one or more satellite hubs: this allows users to access the web servers on the satellite hubs while the hub database runs on the primary hub, and is managed entirely by CodeSonar. If you experience difficulties with this approach, or are not certain it will satisfy your needs, contact CodeSecure support for assistance.

If do you wish to experiment with the unsupported use of your own PostgreSQL database in place of the CodeSonar hub database, this page provides an outline of the process.


If you want to use satellite hubs to distribute the resource costs of the hub server and the hub database across multiple machines, see the instructions in FAQ: How can I run my hub server and hub database on separate machines?. The remainder of this page does not apply.

To replace the hub database with your own PostgreSQL database, follow the steps below.

  1. Start a hub. This sets up the hub infrastructure for you to customize.
    The remainder of these instructions use hubdir to refer to directory you specified when starting the hub.
  2. Shut down the hub process. This is necessary for two reasons.
  3. Open file hubdir/settings.py for editing.
  4. Look at the definition of SQLALCHEMY_DATABASE_URL, which is reproduced below.
    SQLALCHEMY_DATABASE_URL = 'postgres://%(HUB_PGADDRESS)s/cshub'
    

    To change to a different database, you will need to change this definition to a URL (as a string) that reflects the database location. If your database runs as a daemon, you will need to specify the network address at which that daemon runs.

  5. Edit the definition of SQLALCHEMY_DATABASE_URL to contain the correct driver and location information for your database. See the SQLAlchemy manual for information about constructing the string:
    SQLAlchemy manual link Database Urls
    For example, suppose user pat with password pw wants to connect to database PatsDB on machine potato. Then the definition will be something like:
    postgres://pat:pw@potato:5432/PatsDB
  6. Save the file.
  7. Inspect the un-commented lines in hubdir/pgdata/postgresql.conf to see how the hub customizes the PostgreSQL configuration file.

    Where necessary, make corresponding changes in the postgresql.conf file for your database.

  8. If your database runs as a daemon, make sure it is running before you restart the hub.
  9. Restart the hub.