[PGTune](https://pgtune.leopard.in.ua/) is a useful tool for generating configuration files for your PostgreSQL database. It is highly recommended that you generate a config using this tool as it can increase stability and performance.
When you install PostgreSQL, it'll create a new user on your system that acts as the "superuser" of the database. You'll need to run Postgres commands as this user; however, you can run a command as that user without switching to it by using `sudo`.
First, you'll need to create a user that the bot can interact with as well as the database itself:
```sh
sudo su - postgres -c "createuser esmbot"
sudo su - postgres -c "createdb esmbot"
```
Then, launch the PostgreSQL shell for the next few commands:
```sh
sudo -u postgres psql
```
If you want to give the user a password, you can do so like this:
```sql
ALTER USER esmbot WITH PASSWORD 'new_password';
```
Once you're inside the shell, you'll need to make sure the bot owns the database and has permissions:
The database is now accessible by the bot, but the bot may not function yet as the tables to add/get data are still missing. To fix that, you'll need to add them. Luckily, the bot comes with a script to automate this. First, exit the PostgreSQL shell by typing `\q`, then make the script executable and run it by entering the following commands:
If you get an error like `error: permission denied for table counts` when attempting to run the bot, try running these commands in the PostgreSQL shell: