|
| 1 | +--- |
| 2 | +id: postgresql |
| 3 | +title: PostgreSQL Source Template |
| 4 | +sidebar_label: PostgreSQL |
| 5 | +description: Learn about the Sumo Logic PostgreSQL source template for OpenTelemetry. |
| 6 | +--- |
| 7 | + |
| 8 | +import useBaseUrl from '@docusaurus/useBaseUrl'; |
| 9 | +import Tabs from '@theme/Tabs'; |
| 10 | +import TabItem from '@theme/TabItem'; |
| 11 | + |
| 12 | +<head> |
| 13 | + <meta name="robots" content="noindex" /> |
| 14 | +</head> |
| 15 | + |
| 16 | +<p><a href="/docs/beta"><span className="beta">Beta</span></a></p> |
| 17 | + |
| 18 | +<img src={useBaseUrl('img/integrations/databases/postgresql.png')} alt="Thumbnail icon" width="100"/> <img src={useBaseUrl('img/send-data/otel-color.svg')} alt="Thumbnail icon" width="30"/> |
| 19 | + |
| 20 | +The PostgreSQL source template creates an OpenTelemetry configuration that can be pushed to a remotely managed OpenTelemetry collector (abbreviated as otelcol). By creating this source template and pushing the config to the appropriate OpenTelemetry agent, you can ensure collection of PostgreSQL logs and metrics to Sumo Logic. |
| 21 | + |
| 22 | +## Fields creation in Sumo Logic for PostgreSQL |
| 23 | + |
| 24 | +If not already present, the following [Fields](/docs/manage/fields/) are created as part of source template creation. |
| 25 | + |
| 26 | +- **`sumo.datasource`**. Fixed value of **postgresql**. |
| 27 | +- **`deployment.environment`**. This is a user-configured field set at the time of collector installation. It identifies the environment where the host resides, such as `dev`, `prod`, or `qa`. |
| 28 | +- **`db.cluster.name`**. User configured. Enter a uniquely identifiable name for your PostgreSQL cluster to show in the Sumo Logic dashboards. |
| 29 | +- **`db.node.name`**. Includes the value of the hostname of the machine which is being monitored. |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | +### For metrics collection |
| 34 | + |
| 35 | +The PostgreSQL metrics [receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/postgresqlreceiver) collects metrics by querying the PostgreSQL [statistics collector](https://www.postgresql.org/docs/13/monitoring-stats.html). |
| 36 | + |
| 37 | +The monitoring user which is used in the source template must be granted permission to SELECT permission for [pg_stat_database](https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW). |
| 38 | + |
| 39 | +### For logs collection |
| 40 | + |
| 41 | +Configure logging in PostgreSQL: |
| 42 | + |
| 43 | +1. Locate your local PostgreSQL postgresql.conf configuration file in the database data_directory. For more information, see the [PostgreSQL File Locations documentation](https://www.postgresql.org/docs/9.1/static/runtime-config-file-locations.html). By default it's located in `/var/lib/pgsql/<version>/data/postgresql.conf`. You can run SHOW config_file command inside your server's psql shell to get the location. After determining the location of conf file, modify the PostgreSQL postgresql.conf configuration file logging parameters |
| 44 | +2. Connect to the database server (using SSH) in a terminal window. |
| 45 | +3. Open `postgresql.conf` configuration file. |
| 46 | +4. Under the ERROR REPORTING AND LOGGING section of the file, use the following config parameters. For more information on the following parameters, [click here](https://www.postgresql.org/docs/12/static/runtime-config-logging.html). |
| 47 | + ```sql |
| 48 | + log_destination = 'stderr' |
| 49 | + logging_collector = on |
| 50 | + log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' |
| 51 | + log_truncate_on_rotation = off |
| 52 | + log_rotation_age = 1d |
| 53 | + log_min_duration_statement = 250 |
| 54 | + log_connections = on |
| 55 | + log_duration = on |
| 56 | + log_hostname = on |
| 57 | + log_timezone = 'UTC' |
| 58 | + log_min_messages = 'WARNING' |
| 59 | + log_line_prefix = '%m [%p] %q%u@%d ' |
| 60 | + ``` |
| 61 | +5. Save the `postgresql.conf` file and restart the postgresql server: |
| 62 | + ```sh |
| 63 | + sudo service postgresql restart |
| 64 | + ``` |
| 65 | +Ensure that the otelcol has adequate permissions to access all log file paths. Execute the following command: |
| 66 | + |
| 67 | +```bash |
| 68 | +sudo setfacl -R -m d:u:otelcol-sumo:r-x,u:otelcol-sumo:r-x,g:otelcol-sumo:r-x <PATH_TO_LOG_FILE> |
| 69 | +``` |
| 70 | + |
| 71 | +import LogsCollectionPrereqisites from '../../../../reuse/apps/logs-collection-prereqisites.md'; |
| 72 | + |
| 73 | +## Source template configuration |
| 74 | + |
| 75 | +You can follow the below steps to set a remotely managed OpenTelemetry collector and push the source template to it. |
| 76 | + |
| 77 | +### Step 1: Set up remotely managed OpenTelemetry collector |
| 78 | + |
| 79 | +import CollectorInstallation from '../../../../reuse/apps/opentelemetry/collector-installation.md'; |
| 80 | + |
| 81 | +<CollectorInstallation/> |
| 82 | + |
| 83 | +### Step 2: Configure the source template |
| 84 | + |
| 85 | +In this step, you will configure the yaml required for PostgreSQL collection. Below are the inputs required for configuration: |
| 86 | + |
| 87 | +- **Name**. Name of the source template. |
| 88 | +- **Description**. Description for the source template. |
| 89 | +- **Error Log Path**. Enter the path of the error log file for your PostgreSQL instance. |
| 90 | +- **Endpoint**. Enter the url of the server which needs to be monitored. Default endpoint is `localhost:5432`. |
| 91 | +- **UserName**. Enter the PostgreSQL username. |
| 92 | +- **Password Environment Variable Name**. Enter the PostgreSQL password environment variable name. |
| 93 | +- **Fields/Metadata**. You can provide any customer fields to be tagged with the data collected. By default, Sumo Logic tags `_sourceCategory` with the value otel/postgresql user needs to provide the value for `db.cluster.name`. |
| 94 | + |
| 95 | +import OtelLogAdvanceOption from '../../../../reuse/apps/opentelemetry/logs-advance-option-otel.md'; |
| 96 | + |
| 97 | +<OtelLogAdvanceOption/> |
| 98 | + |
| 99 | +**Processing Rules**. You can add **processing rules** for logs/metrics collected. To learn more, refer to [Processing Rules](../processing-rules/index.md). |
| 100 | + |
| 101 | +### Step 3: Push the source template to the desired remotely managed collectors |
| 102 | + |
| 103 | +import DataConfiguration from '../../../../reuse/apps/opentelemetry/data-configuration.md'; |
| 104 | + |
| 105 | +<DataConfiguration/> |
0 commit comments