PostgreSQL
This guide covers the extra installation and configuration steps required to run CodeChecker servers with a PostgreSQL database as backend.
Alternatively, and by default, CodeChecker uses SQLite as database backend, and these steps are not mandatory for a successful installation.
Table of Contents
- List of runtime dependencies
- Installing dependencies and setting up a server
- Creating analysis databases
List of runtime dependencies
- PostgreSQL (>
9.3.5
) (optional) - At least one database connector library for PostgreSQL support required:
- psycopg2 (>
2.5.4
) or - pg8000 (>=
1.10.0
) - PyPi psycopg2
(Requires
lbpq
!) - PyPi pg8000
- psycopg2 (>
Installing dependencies and setting up a server
Tested on Ubuntu LTS 14.04.2
.
# Get the extra PostgreSQL packages.
sudo apt-get install libpq-dev postgresql \
postgresql-client-common postgresql-common \
python-dev
# Setup databases for CodeChecker.
#
# By default, only the installer-created 'postgres' user has access to
# database-specific binaries and actions.
# Switch to this daemon user.
sudo -i -u postgres
# Create a new user to be used for connecting to the database.
# (The password will be prompted for, and read from the standard input.)
createuser --login --pwprompt codechecker
# NOTE: For production systems, certain extra access control configuration
# should be done to make sure database access is secure. Refer to the
# PostgreSQL manual on connection control.
# Create the configuration database for CodeChecker.
createdb codechecker_config
# The newly created user must have privileges on its own database.
psql -c "GRANT ALL PRIVILEGES ON DATABASE codechecker_config TO codechecker;"
# Return to your normal shell via:
exit
# PGPASSFILE environment variable should be set to a 'pgpass' file.
# For format and further information see PostgreSQL documentation:
# http://www.postgresql.org/docs/current/static/libpq-pgpass.html
echo "*:5432:*:codechecker:my_password" >> ~/.pgpass
chmod 0600 ~/.pgpass
For format and further information on
pgpass
files, please refer to the PostgreSQL documentation.
At this point, you can normal continue with installing the necessary Python requirements and creating an install of CodeChecker:
# Set the created virtualenv as your environment.
source $PWD/venv/bin/activate
# Build and install a CodeChecker package.
make package
# For ease of access, add the build directory to PATH.
export PATH="$PWD/build/CodeChecker/bin:$PATH"
Once the package is installed and the PostgreSQL server is running, a
CodeChecker server can be started by specifying the configuration
database's connection arguments. (Read more about the CodeChecker server
command.)
The codechecker_config
database will contain server-specific configurations.
CodeChecker server --postgresql \
--db-host localhost --db-port 5432 \
--db-username codechecker --db-name codechecker_config
Creating analysis databases
At least one additional database must be created in which analysis reports will be stored. (Unlike the default SQLite mode, creation of this Default product is not automatic when PostgreSQL is used!)
# Switch to the daemon user.
sudo -i -u postgres
# Create database and give rights to the server user.
createdb default_product
# The newly created user must have privileges on its own database.
psql -c "GRANT ALL PRIVILEGES ON DATABASE default_product TO codechecker;"
For a product to be set up by the server, an empty database with rights given
must exist in advance. Once the database is created, a product can be
added via CodeChecker cmd products add
, or
via the Web interface.
CodeChecker cmd products add Default --name "Default Product" \
--postgresql \
--db-host localhost --db-port 5432 \
--db-username codechecker --db-name default_product
Once the product is configured, normal operations, such as store
and
browsing the results in the Web application, can commence.