---
title: PostgreSQL instances should have the 'log_hostname' database flag set to 'on'
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > OOTB Rules > PostgreSQL instances should have the
  'log_hostname' database flag set to 'on'
---

# PostgreSQL instances should have the 'log_hostname' database flag set to 'on'
 
## Description{% #description %}

PostgreSQL only logs the IP address of the connecting hosts. The `log_hostname` flag controls the logging of hostnames, in addition to the IP addresses logged. The performance hit depends on the configuration of the environment and the host name resolution setup. This parameter can only be set in the `postgresql.conf` file or on the server's command line.

## Rationale{% #rationale %}

Logging hostnames allows for the association of a hostname with the IP address at the time of connection. This information helps with incident response efforts, particularly in an environment that utilizes dynamic IP addresses. Logging hostnames may incur overhead on server performance because DNS resolution will be required to convert the IP address to hostname. Depending on the setup, the overhead may be non-negligible. Enabling the log_hostname flag on PostgreSQL databases is recommended.

## Impact{% #impact %}

Using the command line to set custom flags on certain instances will cause all omitted flags to be reset to defaults. This may cause you to lose custom flags and could result in unforeseen complications or instance restarts. Because of this, it is recommended that you apply these flag changes during a period of low usage.

## Remediation{% #remediation %}

### From the console{% #from-the-console %}

1. Go to the [Cloud SQL Instances page](https://console.cloud.google.com/sql/instances) in the Google Cloud console.
1. Select the PostgreSQL instance for which you want to enable the database flag.
1. Click **Edit**.
1. Scroll down to the Flags section.
1. Click **Add item** to set a flag that has not been set on the instance before. Choose the flag `log_hostname` from the drop-down menu and select the value **On**.
1. Click **Save**.
1. Confirm your changes under the Flags section on the Overview page.

### From the command line{% #from-the-command-line %}

1. Configure the `log_hostname` database flag for every Cloud SQL PosgreSQL database instance using the below command.

```
 gcloud sql instances patch <INSTANCE_NAME> --database-flags log_hostname=on
```

Note: This command will overwrite all database flags previously set. To keep flags previously set and add new ones, include the values for all flags you want set on the instance; any flag not specifically included is set to its default value. For flags that do not take a value, specify the flag name followed by an equals sign (=).

## Default value{% #default-value %}

By default `log_hostname` is off.

## References{% #references %}

1. [https://cloud.google.com/sql/docs/postgres/flags](https://cloud.google.com/sql/docs/postgres/flags)
1. [https://www.postgresql.org/docs/current/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT](https://www.postgresql.org/docs/current/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT)

## Additional Information{% #additional-information %}

WARNING: This patch modifies database flag values, which may require your instance to be restarted. Check the list of [supported flags](https://cloud.google.com/sql/docs/postgres/flags) to see if your instance will be restarted when this patch is submitted.

Note: Some database flag settings can affect instance availability or stability and remove the instance from the Cloud SQL SLA. For information about these flags, see Operational Guidelines.

Note: Configuring the above flag does not require restarting the Cloud SQL instance.

## CIS controls{% #cis-controls %}

Version 8, 8.5 - Collect Detailed Audit Logs

- Configure detailed audit logging for enterprise assets containing sensitive data. Include event source, date, username, timestamp, source addresses, destination addresses, and other useful elements that could assist in a forensic investigation.
