Tutorial: Start using Joe Bot for PostgreSQL query optimization
note
Joe bot is hosted and developed on GitLab.com. Why? GitLab Inc. is our (Postgres.ai) long-term client and an early adopter (see GitLab Development Docs). GitLab has an open-source version. Last but not least: GitLab uses PostgreSQL.
However, nowadays, not many open-source projects are hosted at GitLab.com unfortunately. ⭐️ Please support the project by giving a star on GitLab! It's on the main page of the Database Lab Engine repository, in the upper right corner:
]
Step 1. Requirements
- Set up Database Lab Engine (e.g., running on address https://dblab.domain.com) before configuring Joe Bot
:::note
Make sure the address used in
accessHost
is accessible from where you are going to run Joe Bot. ::: - Prepare any Linux machine with Docker. See the official documentation on how to install Docker on Linux
Step 2. Configure communication channels
There are two available types of communication with Joe:
- Web UI powered by Postgres.ai Console
- Slack
You can use both of them in parallel. If you can develop in Go language, feel free to implement more types of communication: see communication channels issues.
We need to define where to store the configuration file. We will use ~/.dblab/joe.yml
.
Configuration example:
Then, configure ways of communication with Joe.
Step 2a. Set up Joe in Postgres.ai Console ("Web UI")
If you don't need Web UI and prefer working with Joe only in messengers (such as Slack), comment out channelMapping: communicationTypes: webui
subsection in Jog config, and proceed to the next step.
Before configuring Web UI make sure you have a Postgres.ai account.
If you don't have a Postgres.ai account yet, see the guide on how to start working with Postgres.ai Console.
To configure Web UI:
First, get your
PLATFORM_TOKEN
. This token lets Joe Bot talk to Postgres.ai Platform to enable Web UI chat window, save the history of commands, and visualize query plans. In Postgres.ai Console, switch to proper organization and open theAccess Tokens
page. Save it to Joe config (platform: token
).Then, go to the
Joe instances
page in theSQL Optimization
sidebar section.Choose a project from the dropdown menu and press the
Add instance
button.Generate
Signing secret
. Put it in the configuration file (channelMapping: webui: <your channel name>: credentials: signingSecret
). We will add and verify the URL on the last step, so do not close the page.
Step 2b. Set up Joe bot in Slack
If you need to work with Joe bot in Slack, uncomment channelMapping: communicationTypes: slack
subsection in Joe config, and follow these instructions.
Configure a new Slack App in order to use Joe in Slack and add the app to your team Workspace. Joe Bot should be available with public URL calls from Slack.
Create "#db-lab" channel in your Slack Workspace (You can use another channel name).
- Use "Joe Bot" as App Name and select a proper team Workspace.
Grant permissions on the "OAuth & Permissions" page for the following "Scopes/Bot Token Scopes":
channels:history
chat:write
files:read
files:write
incoming-webhook
reactions:write
users.profile:read
users:read
Go to the "App Home" page and edit "App Display Name".
- Use "Joe Bot" as Display Name and "joe-bot" as the default username.
Enable Incoming Webhooks Feature.
Go to the "OAuth & Permissions" page and press "Install App to Workspace".
Allow access to your Workspace with requested permissions.
You will get
Bot User OAuth Access Token
which is required to run the Joe app (use asSLACK_CHAT_TOKEN
).Go to the "Basic Information" page to get
Signing Secret
from the "App Credentials" section (use asSLACK_SIGNING_SECRET
).
Now we have all tokens and ready to run Joe Bot.
Step 3. Run Joe Bot container
Launch Joe Bot container which immediately connects to the Database Lab instance(s) you've specified in the config file.
sudo docker run \--name joe_bot \--publish 2400:2400 \--restart=on-failure \--volume ~/.dblab/joe.yml:/home/config/config.yml \--detach \postgresai/joe:latestTo observe Joe logs use:
sudo docker logs -f joe_botNeed you to reconfigure or upgrade, you can stop and remove the container any time using
sudo docker stop joe_bot
andsudo docker rm joe_bot
and then launching it again as described above.Make a publicly accessible HTTP(S) server port specified in the configuration to receive requests from communication channels Request URL (e.g., http://35.200.200.200:2400, https://joe.dev.domain.com).
Instead of working using insecure HTTP, you can set up NGINX with SSL enabled and open port 443, similarly as described in "Secure Database Lab Engine".
Step 4. Verify the configuration
Step 4a. Finish the Web UI configuration
Return to the page of Joe configuration in the Console, enter the URL with the specific path
/webui/
. For example,https://joe.dev.domain.com/webui/
.Press the
Verify
button to check connection andAdd
the instance after the verification is passed.Choose the created instance and send a command.
Step 4b. Finish the Slack configuration
Enable Event Subscriptions Feature.
- Go to the "Event Subscriptions" page.
- Specify Request URL adding the specific path,
/slack/
(for example,https://joe.dev.domain.com/slack/
). URL will be verified by Slack API. - In the "Subscribe to Bot Events" dropdown-tab add
message.channels
. - Press "Save Changes".
Invite "Joe Bot" to "#db-lab" channel.
Send a command to the #db-lab channel. For example,
help
.
See available configuration options here.
Have questions?
Reach out to our team, we'll be happy to help! Use the Intercom widget located at the right bottom corner.