Skip to content

Commit 34cc410

Browse files
authored
Merge pull request #1963 from fluent/lynettemiles/sc-136259/update-fluent-bit-docs-pipeline-outputs-postgres
2 parents 80edef6 + 349577d commit 34cc410

File tree

3 files changed

+65
-59
lines changed

3 files changed

+65
-59
lines changed

pipeline/outputs/postgresql.md

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,82 @@
11
# PostgreSQL
22

3-
[PostgreSQL](https://www.postgresql.org) is a very popular and versatile open source database management system that supports the SQL language and that is capable of storing both structured and unstructured data, such as JSON objects.
3+
[PostgreSQL](https://www.postgresql.org) is an open source database management system that supports the SQL language and is capable of storing both structured and unstructured data, such as JSON objects.
44

5-
Given that Fluent Bit is designed to work with JSON objects, the `pgsql` output plugin allows users to send their data to a PostgreSQL database and store it using the `JSONB` type.
5+
Fluent Bit is designed to work with JSON objects, and the `pgsql` output plugin allows users to send their data to a PostgreSQL database and store it using the `JSONB` type.
66

77
PostgreSQL 9.4 or higher is required.
88

99
## Preliminary steps
1010

11-
According to the parameters you have set in the configuration file, the plugin will create the table defined by the `table` option in the database defined by the `database` option hosted on the server defined by the `host` option. It will use the PostgreSQL user defined by the `user` option, which needs to have the right privileges to create such a table in that database.
11+
According to the parameters set in the configuration file, the plugin creates the table defined by the `table` option in the database defined by the `database` option hosted on the server defined by the `host` option. It will use the PostgreSQL user defined by the `user` option, which must have the correct privileges to create such a table in that database.
1212

1313
{% hint style="info" %}
1414

15-
If you are not familiar with how PostgreSQL's users and grants system works, you might find useful reading the recommended links in the "References" section at the bottom.
15+
If you're not familiar with how PostgreSQL's users and grants system works, the links in the [References](#references) section might be helpful.
1616

1717
{% endhint %}
1818

19-
A typical installation normally consists of a self-contained database for Fluent Bit in which you can store the output of one or more pipelines. Ultimately, it is your choice to store them in the same table, or in separate tables, or even in separate databases based on several factors, including workload, scalability, data protection and security.
19+
A typical installation consists of a self-contained database for Fluent Bit in which you can store the output of one or more pipelines. You can store them in the same table, or in separate tables, or even in separate databases based on several factors, including workload, scalability, data protection, and security.
2020

21-
In this example, for the sake of simplicity, we use a single table called `fluentbit` in a database called `fluentbit` that is owned by the user `fluentbit`. Feel free to use different names. Preferably, for security reasons, do not use the `postgres` user \(which has `SUPERUSER` privileges\).
21+
This example uses a single table called `fluentbit` in a database called `fluentbit`, owned by the user `fluentbit`. In your environment, use names appropriate to your needs. For security reasons, don't use the `postgres` user which has `SUPERUSER` privileges.
2222

2323
### Create the `fluentbit` user
2424

25-
Generate a robust random password \(e.g. `pwgen 20 1`\) and store it safely. Then, as `postgres` system user on the server where PostgreSQL is installed, execute:
25+
Generate a robust random password (for example, `pwgen 20 1`) and store it safely. Then, as the `postgres` system user on the server where PostgreSQL is installed, execute:
2626

2727
```shell
2828
createuser -P fluentbit
2929
```
3030

31-
At the prompt, please provide the password that you previously generated.
31+
At the prompt, provide the password that you previously generated.
3232

3333
As a result, the user `fluentbit` without superuser privileges will be created.
3434

3535
If you prefer, instead of the `createuser` application, you can directly use the SQL command [`CREATE USER`](https://www.postgresql.org/docs/current/sql-createuser.html).
3636

3737
### Create the `fluentbit` database
3838

39-
As `postgres` system user, please run:
39+
As `postgres` system user, run:
4040

4141
```shell
4242
createdb -O fluentbit fluentbit
4343
```
4444

45-
This will create a database called `fluentbit` owned by the `fluentbit` user. As a result, the `fluentbit` user will be able to safely create the data table.
45+
This creates a database called `fluentbit` owned by the `fluentbit` user. As a result, the `fluentbit` user will be able to safely create the data table.
4646

4747
Alternatively, you can use the SQL command [`CREATE DATABASE`](https://www.postgresql.org/docs/current/sql-createdatabase.html).
4848

4949
### Connection
5050

51-
Make sure that the `fluentbit` user can connect to the `fluentbit` database on the specified target host. This might require you to properly configure the [`pg_hba.conf`](https://www.postgresql.org/docs/current/auth-pg-hba-conf.html) file.
52-
53-
## Configuration Parameters
54-
55-
| Key | Description | Default |
56-
|:---------------------|:------------------------------------------------------------------------------------------------------------------------------------|:-------------------|
57-
| `Host` | Hostname/IP address of the PostgreSQL instance | - \(127.0.0.1\) |
58-
| `Port` | PostgreSQL port | - \(5432\) |
59-
| `User` | PostgreSQL username | - \(current user\) |
60-
| `Password` | Password of PostgreSQL username | - |
61-
| `Database` | Database name to connect to | - \(current user\) |
62-
| `Table` | Table name where to store data | - |
63-
| `Connection_Options` | Specifies any valid [PostgreSQL connection options](https://www.postgresql.org/docs/devel/libpq-connect.html#LIBPQ-CONNECT-OPTIONS) | - |
64-
| `Timestamp_Key` | Key in the JSON object containing the record timestamp | date |
65-
| `Async` | Define if we will use async or sync connections | false |
66-
| `min_pool_size` | Minimum number of connection in async mode | 1 |
67-
| `max_pool_size` | Maximum amount of connections in async mode | 4 |
68-
| `cockroachdb` | Set to `true` if you will connect the plugin with a CockroachDB | false |
69-
| `workers` | The number of [workers](../../administration/multithreading.md#outputs) to perform flush operations for this output. | `0` |
51+
Ensure that the `fluentbit` user can connect to the `fluentbit` database on the specified target host. This might require you to properly configure the [`pg_hba.conf`](https://www.postgresql.org/docs/current/auth-pg-hba-conf.html) file.
52+
53+
## Configuration parameters
54+
55+
This plugin supports the following parameters:
56+
57+
| Key | Description | Default |
58+
|:----|:------------|:-------|
59+
| `Host` | Hostname/IP address of the PostgreSQL instance. | `- (127.0.0.1)`|
60+
| `Port` | PostgreSQL port. | `- (5432)` |
61+
| `User` | PostgreSQL username. | `- (current user)` |
62+
| `Password` | Password of PostgreSQL username. | `-` |
63+
| `Database` | Database name to connect to. | `- (current user)` |
64+
| `Table` | Table name where to store data. | `-` |
65+
| `Connection_Options` | Specifies any valid [PostgreSQL connection options](https://www.postgresql.org/docs/devel/libpq-connect.html#LIBPQ-CONNECT-OPTIONS). | `-` |
66+
| `Timestamp_Key` | Key in the JSON object containing the record timestamp. | `date` |
67+
| `Async` | Define if the plugin will use asynchronous or synchronous connections. | `false` |
68+
| `max_pool_size` | Maximum amount of connections in asynchronous mode. | `4`|
69+
| `min_pool_size` | Minimum number of connection in asynchronous mode. | `1` |
70+
| `cockroachdb` | Set to `true` if you will connect the plugin with a CockroachDB. | `false` |
71+
| `workers` | The number of [workers](../../administration/multithreading.md#outputs) to perform flush operations for this output. | `0` |
7072

7173
### Libpq
7274

73-
Fluent Bit relies on [libpq](https://www.postgresql.org/docs/current/libpq.html), the PostgreSQL native client API, written in C language. For this reason, default values might be affected by [environment variables](https://www.postgresql.org/docs/current/libpq-envars.html) and compilation settings. The above table, in brackets, list the most common default values for each connection option.
75+
Fluent Bit relies on [libpq](https://www.postgresql.org/docs/current/libpq.html), the PostgreSQL native client API. For this reason, default values might be affected by [environment variables](https://www.postgresql.org/docs/current/libpq-envars.html) and compilation settings. The previous table lists the most common default values for each connection option.
7476

75-
For security reasons, it is advised to follow the directives included in the [password file](https://www.postgresql.org/docs/current/libpq-pgpass.html) section.
77+
For security reasons, you're advised to follow the directives included in the [password file](https://www.postgresql.org/docs/current/libpq-pgpass.html) section.
7678

77-
## Configuration Example
79+
## Configuration example
7880

7981
In your main configuration file add the following section:
8082

@@ -83,7 +85,7 @@ In your main configuration file add the following section:
8385

8486
```yaml
8587
pipeline:
86-
88+
8789
outputs:
8890
- name: pgsql
8991
match: '*'
@@ -94,7 +96,7 @@ pipeline:
9496
database: fluentbit
9597
table: fluentbit
9698
connection_options: '-c statement_timeout=0'
97-
timestamp_key: ts
99+
timestamp_key: ts
98100
```
99101
100102
{% endtab %}
@@ -121,41 +123,41 @@ pipeline:
121123

122124
The output plugin automatically creates a table with the name specified by the `table` configuration option and made up of the following fields:
123125

124-
* `tag TEXT`
125-
* `time TIMESTAMP WITHOUT TIMEZONE`
126-
* `data JSONB`
126+
- `tag TEXT`
127+
- `time TIMESTAMP WITHOUT TIMEZONE`
128+
- `data JSONB`
127129

128-
As you can see, the timestamp does not contain any information about the time zone, and it is therefore referred to the time zone used by the connection to PostgreSQL \(`timezone` setting\).
130+
The timestamp doesn't contain any information about the time zone, and it's therefore referred to the time zone used by the connection to PostgreSQL (`timezone` setting).
129131

130-
For more information on the `JSONB` data type in PostgreSQL, please refer to the [JSON types](https://www.postgresql.org/docs/current/datatype-json.html) page in the official documentation, where you can find instructions on how to index or query the objects \(including `jsonpath` introduced in PostgreSQL 12\).
132+
For more information about the `JSONB` data type in PostgreSQL, refer to the [JSON types](https://www.postgresql.org/docs/current/datatype-json.html) page in the official documentation. You can find instructions on how to index or query the objects (including `jsonpath` introduced in PostgreSQL 12).
131133

132134
## Scalability
133135

134-
PostgreSQL 10 introduces support for declarative partitioning. In order to improve vertical scalability of the database, you can decide to partition your tables on _time ranges_ \(for example on a monthly basis\). PostgreSQL supports also subpartitions, allowing you to even partition by _hash_ your records \(version 11+\), and default partitions \(version 11+\).
136+
PostgreSQL includes support for declarative partitioning. To improve vertical scalability of the database, you can partition your tables on time ranges, such as on a monthly basis. PostgreSQL supports also sub-partitions, which let you partition your records by hash and default partitions.
135137

136-
For more information on horizontal partitioning in PostgreSQL, please refer to the [Table partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html) page in the official documentation.
138+
For more information on horizontal partitioning in PostgreSQL, refer to the [Table partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html) page in the official documentation.
137139

138-
If you are starting now, our recommendation at the moment is to choose the latest major version of PostgreSQL.
140+
Choose the latest major version of PostgreSQL if you're starting now.
139141

140-
## There's more ...
142+
## Additional information
141143

142-
PostgreSQL is a really powerful and extensible database engine. More expert users can indeed take advantage of `BEFORE INSERT` triggers on the main table and re-route records on normalised tables, depending on tags and content of the actual JSON objects.
144+
PostgreSQL is a powerful and extensible database engine. More expert users can take advantage of `BEFORE INSERT` triggers on the main table and reroute records on normalised tables, depending on tags and content of the actual JSON objects.
143145

144-
For example, you can use Fluent Bit to send HTTP log records to the _landing_ table defined in the configuration file. This table contains a `BEFORE INSERT` trigger \(a function in `plpgsql` language\) that _normalises_ the content of the JSON object and that inserts the record in another table \(with its own structure and partitioning model\). This kind of triggers allow you to _discard_ the record from the landing table by returning `NULL`.
146+
For example, you can use Fluent Bit to send HTTP log records to the `landing` table defined in the configuration file. This table contains a `BEFORE INSERT` trigger (a function in `plpgsql` language) that normalizes the content of the JSON object and that inserts the record in another table (with its own structure and partitioning model). This kind of trigger lets you discard the record from the landing table by returning `NULL`.
145147

146148
## References
147149

148-
Here follows a list of useful resources from the PostgreSQL documentation:
149-
150-
* [Database Roles](https://www.postgresql.org/docs/current/user-manag.html)
151-
* [`GRANT`](https://www.postgresql.org/docs/current/sql-grant.html)
152-
* [`CREATE USER`](https://www.postgresql.org/docs/current/sql-createuser.html)
153-
* [`CREATE DATABASE`](https://www.postgresql.org/docs/current/sql-createdatabase.html)
154-
* [The `pg_hba.conf` file](https://www.postgresql.org/docs/current/auth-pg-hba-conf.html)
155-
* [JSON types](https://www.postgresql.org/docs/current/datatype-json.html)
156-
* [Date/Time functions and operators](https://www.postgresql.org/docs/current/functions-datetime.html)
157-
* [Table partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html)
158-
* [libpq - C API for PostgreSQL](https://www.postgresql.org/docs/current/libpq.html)
159-
* [libpq - Environment variables](https://www.postgresql.org/docs/current/libpq-envars.html)
160-
* [libpq - password file](https://www.postgresql.org/docs/current/libpq-pgpass.html)
161-
* [Trigger functions](https://www.postgresql.org/docs/current/plpgsql-trigger.html)
150+
Refer to the following a list of resources from the PostgreSQL documentation:
151+
152+
- [Database Roles](https://www.postgresql.org/docs/current/user-manag.html)
153+
- [`GRANT`](https://www.postgresql.org/docs/current/sql-grant.html)
154+
- [`CREATE USER`](https://www.postgresql.org/docs/current/sql-createuser.html)
155+
- [`CREATE DATABASE`](https://www.postgresql.org/docs/current/sql-createdatabase.html)
156+
- [The `pg_hba.conf` file](https://www.postgresql.org/docs/current/auth-pg-hba-conf.html)
157+
- [JSON types](https://www.postgresql.org/docs/current/datatype-json.html)
158+
- [Date/Time functions and operators](https://www.postgresql.org/docs/current/functions-datetime.html)
159+
- [Table partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html)
160+
- [libpq - C API for PostgreSQL](https://www.postgresql.org/docs/current/libpq.html)
161+
- [libpq - Environment variables](https://www.postgresql.org/docs/current/libpq-envars.html)
162+
- [libpq - password file](https://www.postgresql.org/docs/current/libpq-pgpass.html)
163+
- [Trigger functions](https://www.postgresql.org/docs/current/plpgsql-trigger.html)

vale-styles/FluentBit/Headings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ exceptions:
6262
- Kinesis
6363
- Kubernetes
6464
- LaunchDarkly
65+
- Libpq
6566
- Linux
6667
- LogDNA
6768
- LTSV
@@ -77,6 +78,7 @@ exceptions:
7778
- OpenTelemetry
7879
- Opsgenie
7980
- PagerDuty
81+
- PostgreSQL
8082
- Prometheus
8183
- PromQL
8284
- REPL

vale-styles/FluentBit/Spelling-exceptions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Kube
102102
Kubernetes
103103
Kusto
104104
labelset
105+
libpq
105106
librdkafka
106107
loadgenerator
107108
logfmt
@@ -136,6 +137,7 @@ performant
136137
persistable
137138
Podman
138139
Postgres
140+
PostgreSQL
139141
PowerShell
140142
prepopulate
141143
preprocessor

0 commit comments

Comments
 (0)