PostgreSQL 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.
Given that Fluent Bit is designed to work with JSON objects, the
pgsqloutput plugin allows users to send their data to a PostgreSQL database and store it using the
PostgreSQL 9.4 or higher is required.
According to the parameters you have set in the configuration file, the plugin will create the table defined by the
tableoption in the database defined by the
databaseoption hosted on the server defined by the
hostoption. It will use the PostgreSQL user defined by the
useroption, which needs to have the right privileges to create such a table in that database.
NOTE: 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.
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 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.
In this example, for the sake of simplicity, we use a single table called
fluentbitin a database called
fluentbitthat is owned by the user
fluentbit. Feel free to use different names. Preferably, for security reasons, do not use the
postgresuser (which has
Generate a robust random password (e.g.
pwgen 20 1) and store it safely. Then, as
postgressystem user on the server where PostgreSQL is installed, execute:
createuser -P fluentbit
At the prompt, please provide the password that you previously generated.
As a result, the user
fluentbitwithout superuser privileges will be created.
postgressystem user, please run:
createdb -O fluentbit fluentbit
This will create a database called
fluentbitowned by the
fluentbituser. As a result, the
fluentbituser will be able to safely create the data table.
In your main configuration file add the following section:
The output plugin automatically creates a table with the name specified by the
tableconfiguration option and made up of the following fields:
time TIMESTAMP WITHOUT TIMEZONE
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 (
For more information on the
JSONBdata type in PostgreSQL, please refer to the JSON types page in the official documentation, where you can find instructions on how to index or query the objects (including
jsonpathintroduced in PostgreSQL 12).
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+).
If you are starting now, our recommendation at the moment is to choose the latest major version of PostgreSQL.
PostgreSQL is a really powerful and extensible database engine. More expert users can indeed take advantage of
BEFORE INSERTtriggers on the main table and re-route records on normalised tables, depending on tags and content of the actual JSON objects.
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 INSERTtrigger (a function in
plpgsqllanguage) 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
Here follows a list of useful resources from the PostgreSQL documentation: