Configure the Kong Gateway datastore on Linux
After installing the database, configure kong.conf to connect to PostgreSQL,
run kong migrations bootstrap to initialize the schema, then start Kong Gateway.
Prerequisites
Install PostgreSQL
Install PostgreSQL using the following steps:
Configure PostgreSQL authentication (RHEL only)
On Red Hat–based distributions, PostgreSQL defaults to ident or peer
authentication. Kong Gateway requires password-based authentication.
Edit the active pg_hba.conf file and update local and localhost rules to use md5,
then restart PostgreSQL:
sudo systemctl restart postgresql
By default, the pg_hba.conf file is located at /var/lib/pgsql/data/pg_hba.conf.
Configure environment variables
Set the following variables so that kong.conf can interact with the datastore:
export KONG_DATABASE=postgres
export KONG_PG_HOST=127.0.0.1
export KONG_PG_PORT=5432
export KONG_PG_USER=kong
export KONG_PG_PASSWORD=super_secret
export KONG_PG_DATABASE=kong
Configure PostgreSQL
-
Switch to the default PostgreSQL user:
sudo -i -u postgresCopied! -
Start the PostgreSQL shell:
psqlCopied! -
Create a
konguser and password:CREATE USER kong WITH PASSWORD 'super_secret';Copied! -
Create a database titled
kongand assign the user as an owner:CREATE DATABASE kong OWNER kong;Copied! -
Exit PostgreSQL:
\quitCopied! -
Exit the PostgreSQL shell:
exitCopied!
Run a Kong Gateway database migration
kong migrations is used to configure the database for the first time.
Running bootstrap forces Kong Gateway to bootstrap the database set up in the previous step and run all of the migrations:
sudo -E kong migrations bootstrap
This command must be run as the root user.
This command must be run with
sudo -Eto preserve the environment variables set in the prerequisites. If thekongcommand is not found when running withsudo, you can create a symlink so it is available from the default PATH:sudo ln -s /usr/local/bin/kong /usr/bin/kong
Validate
You can validate that the datastore was configured correctly by starting Kong Gateway.