--- slug: /send-data/opentelemetry-collector/remote-management/source-templates/postgresql title: PostgreSQL Source Template sidebar_label: PostgreSQL description: Learn about the Sumo Logic PostgreSQL source template for OpenTelemetry. canonical: https://www.sumologic.com/help/docs/send-data/opentelemetry-collector/remote-management/source-templates/postgresql/ --- import useBaseUrl from '@docusaurus/useBaseUrl'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; PostgreSQL icon OpenTelemetry color icon 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. ## Fields creation in Sumo Logic for PostgreSQL If not already present, the following [Fields](/docs/manage/fields/) are created as part of source template creation. - **`sumo.datasource`**. Fixed value of **postgresql**. - **`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`. - **`db.cluster.name`**. User configured. Enter a uniquely identifiable name for your PostgreSQL cluster to show in the Sumo Logic dashboards. - **`db.node.name`**. Includes the value of the hostname of the machine which is being monitored. ## Prerequisites ### For metrics collection - 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). - 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). - Make sure to set the PostgreSQL user's password as an environment variable for the OpenTelemetry agent. Refer to [Setting Environment Variables with Secret Values for Source Templates](../st-with-secrets.md). :::note For Sumo Logic OpenTelemetry Collector versions below 0.116, metric collection supports only PostgreSQL version 16 and earlier. With Sumo Logic OpenTelemetry collector version 0.116 and above, metric collection also supports PostgreSQL version 17. ::: ### For logs collection Configure logging in PostgreSQL: 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//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 2. Connect to the database server (using SSH) in a terminal window. 3. Open `postgresql.conf` configuration file. 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). ```sumo log_destination = 'stderr' logging_collector = on log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' log_truncate_on_rotation = off log_rotation_age = 1d log_min_duration_statement = 250 log_connections = on log_duration = on log_hostname = on log_timezone = 'UTC' log_min_messages = 'WARNING' log_line_prefix = '%m [%p] %q%u@%d ' ``` 5. Save the `postgresql.conf` file and restart the postgresql server: ```sh sudo service postgresql restart ``` Ensure that the otelcol has adequate permissions to access all log file paths. Execute the following command: ```bash sudo setfacl -R -m d:u:otelcol-sumo:r-x,u:otelcol-sumo:r-x,g:otelcol-sumo:r-x ``` import LogsCollectionPrereqisites from '../../../../../reuse/apps/logs-collection-prereqisites.md'; import OtelWindowsLogPrereq from '../../../../../reuse/apps/opentelemetry/log-collection-prerequisite-windows.md'; ## Configuring the PostgreSQL source template You can follow the below steps to set a remotely managed OpenTelemetry collector and push the source template to it. ### Step 1: Set up remotely managed OpenTelemetry collector import CollectorInstallation from '../../../../../reuse/apps/opentelemetry/collector-installation.md'; ### Step 2: Configure the source template import PostgresqlConfigureSourceTemplate from '../../../../../reuse/send-data/postgresql-configure-source-template.md'; import TimestampParsing from '../../../../../reuse/apps/opentelemetry/timestamp-parsing.md'; **Processing Rules**. You can add **processing rules** for logs/metrics collected. To learn more, refer to [Processing Rules](../../processing-rules/index.md). ### Step 3: Push the source template to the desired remotely managed collectors import DataConfiguration from '../../../../../reuse/apps/opentelemetry/data-configuration.md'; :::info Refer to the [changelog](changelog.md) for information on periodic updates to this source template. :::