PostgreSQL Database Log Files

RDS PostgreSQL generates query and error logs. We write auto-vacuum information and
rds_admin
actions to the error log. PostgreSQL also logs connections, disconnections, and
checkpoints
to the error log. For more information, see the Error
Reporting and Logging in the PostgreSQL documentation.

You can set the retention period for system logs using the
rds.log_retention_period parameter in the DB parameter group associated
with your DB instance. The unit for this parameter is minutes. For example, a setting
of
1440 would retain logs for one day. The default value is 4320 (three days). The
maximum
value is 10080 (seven days). Note that your instance must have enough allocated
storage to
contain the retained log files.

You can enable query logging for your PostgreSQL DB instance by setting two parameters
in the
DB parameter group associated with your DB instance: log_statement and
log_min_duration_statement. The log_statement parameter
controls which SQL statements are logged. We recommend setting this parameter to
all to log all statements when debugging issues in your DB
instance. The default value is none. Alternatively, you can set this
value to ddl to log all data definition language (DDL) statements
(CREATE, ALTER, DROP, and so on) or to mod to log all DDL and data
modification language (DML) statements (INSERT, UPDATE, DELETE, and so on).

The log_min_duration_statement parameter sets the limit in milliseconds of a
statement to be logged. All SQL statements that run longer than the parameter setting
are
logged. This parameter is disabled and set to minus 1 (-1) by default. Enabling
this
parameter can help you find unoptimized queries.

Additional information is written to the postgres.log file when you execute
a query that exceeds the duration parameter setting. The following example
shows the type of information written to the file after a query:

Publishing PostgreSQL Logs to
CloudWatch Logs

You can configure your Amazon RDS for PostgreSQL DB instance to publish log data to
a log group
in Amazon CloudWatch Logs. With CloudWatch Logs, you can perform real-time analysis
of the log data, and use
CloudWatch to create alarms and view metrics. You can use CloudWatch Logs to store
your log records in
highly durable storage.

Note

Publishing log files to CloudWatch Logs is only supported for PostgreSQL versions
9.6.6 and above and
10.4 and above.

Following are the log types that can be published to CloudWatch Logs for Amazon RDS
for PostgreSQL.

Postgresql log

Upgrade log

After you complete the configuration, Amazon RDS publishes the log events to log streams
within a
CloudWatch log group. For example, the PostgreSQL log data is stored within the
log group
/aws/rds/instance/my_instance/postgresql.
To view your Amazon CloudWatch Logs, open https://console.aws.amazon.com/cloudwatch/.

Other options might be required depending on the AWS CLI command you run.

Modify an instance to publish logs to CloudWatch Logs

The following example modifies an existing PostgreSQL DB instance to publish log files
to
CloudWatch Logs. The --cloudwatch-logs-export-configuration value is a
JSON object. The key for this object is EnableLogTypes, and its
value is an array of strings with any combination of postgresql
and upgrade.

The following example creates a PostgreSQL DB instance and publishes log files to
CloudWatch Logs.
The --enable-cloudwatch-logs-exports value is a JSON array of
strings. The strings can be any combination of postgresql and
upgrade.