Postgres Installation Guide
Codacy requires a working installation of Postgres to work. Depending on the number of projects you are running you might need different requirements.
4 cores CPU
8 GB RAM
Minimum 500 GB+ Hard Drive - this will depend on the number of projects you have. For tailored information, please, contact us at email@example.com.
If you already have a Postgres installation, jump directly to step 1.3.
Codacy officially supports Postgres version 9.4. Codacy requires 'UTF-8' encoding. Make sure that your database character set is correctly configured. For more information see https://www.postgresql.org/docs/9.4/static/multibyte.html
1 - Postgres
Here are some quick steps to have a running Postgres installation on Ubuntu 16.04.
1.1 - Configure system locale to support UTF-8
Before installing postgres, you'll need to make sure your system locale is configured to use UTF-8. You can check your current locale by running:
You can change your locale to a UTF-8 variant by running:
1.2 - Install postgres
First, ensure that you install postgres 9.4 following the instructions described here.
1.3 - Run postgres
Installing PostgreSQL on Ubuntu should start the service by default. However, let's check that it's running with:
sudo systemctl status postgresql
If PostgreSQL is running, you'll see output that includes the text
Active: active (exited).
If you see
Active: inactive (dead), start the PostgreSQL service using the following command:
sudo systemctl start postgresql
PostgreSQL also needs to be enabled to start on reboot. Do that with this command:
sudo systemctl enable postgresql
1.4 - Allow external connections
In order to access PostgreSQL from a different machine, you need to do additional configurations to allow external connections.
Using Nano (or vim/emacs/other), edit your
postgresql.conf file. We're specifically looking for a line that says
listen_addresses. We're going to modify where PostgreSQL is listening on.
# /etc/postgresql/9.4/main/postgresql.conf #--------------------------------------------------------- # CONNECTIONS AND AUTHENTICATION #--------------------------------------------------------- # - Connection Settings - listen_addresses = '*'
Next we're going to edit our
pg_hba.conf file and configure it to allow remote connections. At the very end of the file, add the following line:
# /etc/postgresql/9.4/main/pg_hba.conf host all all 0.0.0.0/0 md5
This is a rule that basically tells PostgreSQL to allow anyone to access the instance, as long as they have proper credentials.
If you want to whitelist your IP only, you can use your network/mask instead of
0.0.0.0/0 (for example: 18.104.22.168/32).
Note: Despite being not recommended, if you're running postgres on the same machine where codacy is and you want to whitelist just the codacy's IP address, you have to whitelist a range of IP addresses because codacy runs inside docker and it won't have always the same IP address inside the docker network. Therefore, you should first obtain the address of the docker network interface with an
ifconfig and then whitelist the ip addresses according to it (for example,
Finally, restart postgres:
sudo service postgresql restart
Note: Actual file locations may change depending on what package and operating system you use. Just google where to find your postgres conf file and you'll be fine.
1.5 - Creating a user
It is advised that you create a particular user that will only be able to access Codacy specific databases. To do so, using the
psql shell, create a user:
sudo -u postgres psql
You can change the user/password to suit your security needs.
Make sure that you can connect to the Postgres database using the newly created user. For additional settings, follow the steps in the Postgres documentation.
Connecting psql Client Using the Google Cloud SQL Proxy Docker Image
If you are connecting to your postgres instance through a docker container proxy, we recommend that you configure the following:
- Make sure your postgres docker container is configured with --restart always
- In the Codacy control panel, the "Database hostname" option should be set with the IP address or DNS of the Codacy instance itself