|
| 1 | +--- |
| 2 | +title: Bootstrapping the Configuration Database |
| 3 | +--- |
| 4 | + |
| 5 | +## Choosing a Database |
| 6 | + |
| 7 | +pgwatch supports any database that supports the PostgreSQL wire protocol. This includes: |
| 8 | + |
| 9 | +- PostgreSQL |
| 10 | +- TimescaleDB |
| 11 | +- CitusDB |
| 12 | +- CockroachDB |
| 13 | +- many more |
| 14 | + |
| 15 | +We will use PostgreSQL in this guide. But the steps are similar for other databases. It's up to you to choose the database that best fits your needs and set it up accordingly. |
| 16 | + |
| 17 | +## Creating the Database |
| 18 | + |
| 19 | +First, we need to create a database for storing the configuration. We will use the `psql` command-line tool to create the database. You can also use a GUI tool like pgAdmin to create the database. |
| 20 | + |
| 21 | +Let's assume we want to create a database named `pgwatch` on a completely fresh PostgreSQL installation. |
| 22 | +It is wise to use a special role for the configuration database, so we will create a role named `pgwatch` and assign it to the `pgwatch` database. |
| 23 | + |
| 24 | +```terminal |
| 25 | +$ psql -U postgres -h localhost -p 5432 -d postgres |
| 26 | +psql (17.2) |
| 27 | +
|
| 28 | +postgres=# CREATE ROLE pgwatch WITH LOGIN PASSWORD 'pgwatchadmin'; |
| 29 | +CREATE ROLE |
| 30 | +
|
| 31 | +postgres=# CREATE DATABASE pgwatch OWNER pgwatch; |
| 32 | +CREATE DATABASE |
| 33 | +``` |
| 34 | + |
| 35 | +That's it! We have created a database named `pgwatch` with the owner `pgwatch`. Now we can proceed to the next step. |
| 36 | + |
| 37 | +## Init (optional) |
| 38 | + |
| 39 | +pgwatch will automatically create the necessary tables and indexes in the database when it starts. But in case |
| 40 | +you want to create the schema as a separate step, you can use the `config init` command-line command. The only thing you |
| 41 | +need is to provide the connection string to the database. |
| 42 | + |
| 43 | +```terminal |
| 44 | +pgwatch --sources=postgresql://pgwatch:pgwatchadmin@localhost/pgwatch config init |
| 45 | +``` |
| 46 | + |
| 47 | +Or you can use the `config init` command with the `--metrics` flag, since metrics and sources share the same database. |
| 48 | + |
| 49 | +```terminal |
| 50 | +pgwatch --metrics=postgresql://pgwatch:pgwatchadmin@localhost/pgwatch config init |
| 51 | +``` |
| 52 | + |
| 53 | +## Usage |
| 54 | + |
| 55 | +You can now configure pgwatch to use the `pgwatch` database as the configuration database for storing monitored sources, |
| 56 | +metric deinitions and presets. |
| 57 | + |
| 58 | +```terminal |
| 59 | +$ pgwatch --sources=postgresql://pgwatch:pgwatchadmin@localhost/pgwatch --sink=postgresql://[email protected]/measurements |
| 60 | +... |
| 61 | +[INFO] [metrics:75] [presets:17] [sources:2] sources and metrics refreshed |
| 62 | +... |
| 63 | +``` |
| 64 | + |
| 65 | +!!! info |
| 66 | + Even though configuration database can hold both sources and metrics definitions, |
| 67 | + you are free to use any combination of configurations. For example, you can use a database |
| 68 | + for metrics and YAML file for sources, or vice versa. |
| 69 | + |
| 70 | +That's it! You have successfully bootstrapped the configuration database for pgwatch. |
| 71 | + |
| 72 | +If now you want to see the tables created by pgwatch in the configuration database, you can connect to the database |
| 73 | +using the `psql` command-line tool and list the tables. |
| 74 | + |
| 75 | +```terminal |
| 76 | +$ psql postgresql://pgwatch:pgwatchadmin@localhost/pgwatch |
| 77 | +psql (17.2) |
| 78 | +
|
| 79 | +pgwatch=# \dt pgwatch.* |
| 80 | + List of relations |
| 81 | + Schema | Name | Type | Owner |
| 82 | +---------+-----------+-------+--------- |
| 83 | + pgwatch | metric | table | pgwatch |
| 84 | + pgwatch | migration | table | pgwatch |
| 85 | + pgwatch | preset | table | pgwatch |
| 86 | + pgwatch | source | table | pgwatch |
| 87 | +(4 rows) |
| 88 | +``` |
| 89 | + |
| 90 | +You may examine these tables to understand how pgwatch stores metrics and presets definitions, as well as what sources and how to monitor in the database. |
0 commit comments