You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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.
4
4
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.
6
6
7
7
PostgreSQL 9.4 or higher is required.
8
8
9
9
## Preliminary steps
10
10
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.
12
12
13
13
{% hint style="info" %}
14
14
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.
16
16
17
17
{% endhint %}
18
18
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.
20
20
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.
22
22
23
23
### Create the `fluentbit` user
24
24
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:
26
26
27
27
```shell
28
28
createuser -P fluentbit
29
29
```
30
30
31
-
At the prompt, please provide the password that you previously generated.
31
+
At the prompt, provide the password that you previously generated.
32
32
33
33
As a result, the user `fluentbit` without superuser privileges will be created.
34
34
35
35
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).
36
36
37
37
### Create the `fluentbit` database
38
38
39
-
As `postgres` system user, please run:
39
+
As `postgres` system user, run:
40
40
41
41
```shell
42
42
createdb -O fluentbit fluentbit
43
43
```
44
44
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.
46
46
47
47
Alternatively, you can use the SQL command [`CREATE DATABASE`](https://www.postgresql.org/docs/current/sql-createdatabase.html).
48
48
49
49
### Connection
50
50
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.
|`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)`|
|`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`|
70
72
71
73
### Libpq
72
74
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.
74
76
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.
76
78
77
-
## Configuration Example
79
+
## Configuration example
78
80
79
81
In your main configuration file add the following section:
80
82
@@ -83,7 +85,7 @@ In your main configuration file add the following section:
83
85
84
86
```yaml
85
87
pipeline:
86
-
88
+
87
89
outputs:
88
90
- name: pgsql
89
91
match: '*'
@@ -94,7 +96,7 @@ pipeline:
94
96
database: fluentbit
95
97
table: fluentbit
96
98
connection_options: '-c statement_timeout=0'
97
-
timestamp_key: ts
99
+
timestamp_key: ts
98
100
```
99
101
100
102
{% endtab %}
@@ -121,41 +123,41 @@ pipeline:
121
123
122
124
The output plugin automatically creates a table with the name specified by the `table` configuration option and made up of the following fields:
123
125
124
-
*`tag TEXT`
125
-
*`time TIMESTAMP WITHOUT TIMEZONE`
126
-
*`data JSONB`
126
+
-`tag TEXT`
127
+
-`time TIMESTAMP WITHOUT TIMEZONE`
128
+
-`data JSONB`
127
129
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).
129
131
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).
131
133
132
134
## Scalability
133
135
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.
135
137
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.
137
139
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.
139
141
140
-
## There's more ...
142
+
## Additional information
141
143
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.
143
145
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`.
145
147
146
148
## References
147
149
148
-
Here follows a list of useful resources from the PostgreSQL documentation:
0 commit comments