# Access Logs

The logs that are generated by a database are stored temporarily on the same disk as the database. We provide logs for connections, disconnections, waiting for locks, DDL statements, any statement that ran for at least 500 ms, and any statement that caused an error.

We do not provide an option to change this configuration. For more information, refer to the [<mark style="color:blue;">PostgreSQL Documentation</mark>](https://www.postgresql.org/docs/current/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT).

In order to conserve disk space, log files are rotated according to size. Logs should not consume more than 175 MB of disk storage. The files are continuously monitored and log messages are shipped to a central storage location with a retention policy of 30 days.

By using your cluster ID, you can fetch the logs for that cluster via our API.

## Request logs

The endpoint for fetching logs has four optional query parameters:

| **Parameter** | **Description**                                                                           | **Default Value** | **Possible Values**                            |
| ------------- | ----------------------------------------------------------------------------------------- | ----------------- | ---------------------------------------------- |
| **start**     | Retrieve log lines after this timestamp (format: RCF3339)                                 | 30 days ago       | Between 30 days ago and now (before **end**).  |
| **end**       | Retrieve log line before this timestamp (format: RFC3339)                                 | now               | Between 30 days ago and now (after **start**). |
| **direction** | Direction in which the logs are sorted and limited                                        | BACKWARD          | BACKWARD or FORWARD.                           |
| **limit**     | Maximum number of log lines to retrieve. Which log lines are cut depends on **direction** | 100               | Between 1 and 5000.                            |

So if you omit all parameters, you get the latest 100 log lines.

```bash
curl --include \
    --request GET \
    --user "clientname@ionos.com:Mb2.r5oHf-0t" \
    --header "Content-Type: application/json" \
    https://api.ionos.com/databases/postgresql/clusters/498ae72f-411f-11eb-9d07-046c59cc737e/logs?start=2022-01-05T12:00:00Z&end=2022-01-05T13:00:00Z&direction=FORWARD&limit=2
```

## Response

The response will contain the logs separated per instance and look similar to this (of course with different timestamps and log contents.

```json
{
  "instances": [
    {
      "name": "ionos-498ae72f-411f-11eb-9d07-046c59cc737e-by6qu3m-1",
      "messages": [
        {
          "time": "2022-01-05T12:00:29.793Z",
          "message": "2022-01-05 12:00:29.793 UTC,,,107077,\"[local]\",61d5885d.1a245,1,\"\",2022-01-05 12:00:29 UTC,,0,LOG,00000,\"connection received: host=[local]\",,,,,,,,,\"\",\"not initialized\""
        },
        {
          "time": "2022-01-05T12:00:29.794Z",
          "message": "2022-01-05 12:00:29.794 UTC,\"postgres\",\"test\",107078,\"[local]\",61d5885d.1a246,2,\"authentication\",2022-01-05 12:00:29 UTC,9/73319,0,LOG,00000,\"connection authorized: user=postgres database=test application_name=pgq ticker\",,,,,,,,,\"\",\"client backend\""
        }
      ]
    }
  ]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ionos.com/cloud/databases/postgresql/api/v1-api/access-logs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
