# rds-logs

Part of **RDS**

# ApsaraDB RDS Log Management Console Guide

## Operations Overview

| Operation | Console Navigation Path | Prerequisites | Description |
|----------|------------------------|---------------|-------------|
| View and Download Logs | Console > ApsaraDB RDS > Instances > Select Instance > Logs | An active ApsaraDB RDS instance; permissions to access the RDS console; basic understanding of log types (e.g., error logs, slow query logs) | View and download various log types (Error Log, Slow Query Log, Binlog, Audit Log) within a specified time range. |
| Query PostgreSQL Logs | RDS > Instances > Select Instance > Database Management > SQL Console | Your RDS instance runs PostgreSQL 11; if the extension cannot be created, update the minor engine version | Use the log_fdw extension to create foreign tables and query PostgreSQL CSV log files via standard SQL. |
| Enable SQL Explorer and Audit (MySQL/PostgreSQL) | Console > RDS > Instance Details > Autonomous Service > Audit | Subscribed to DAS Enterprise Edition; RAM user has AliyunRDSReadOnlyWithSQLLogArchiveAccess permission | Enable comprehensive SQL auditing and exploration features for security, compliance, and performance analysis. |
| Enable SQL Audit (PPAS) | RDS > Instances > Select Instance > Database Audit | An ApsaraDB RDS for PPAS instance must be created; sufficient permissions to modify audit settings | Turn on SQL Audit to record executed SQL statements on PPAS instances (disabled by default). |

## Operation Steps

### View and Download Logs

**Navigation**: Console > ApsaraDB RDS > Instances > Select Instance > Logs

**Prerequisites**:
- An active ApsaraDB RDS instance
- Permissions to access the RDS console
- Basic understanding of log types (e.g., error logs, slow query logs)

1. Navigate to the RDS console and select your target instance  
   - Element: **Instances** (link) — left navigation panel  
   - Notes: Ensure the instance is in Running status.

2. Click on the **Logs** tab for the selected instance  
   - Element: **Logs** (tab) — main content area  
   - Notes: Available log types may vary based on the database engine (MySQL, PostgreSQL, etc.).

3. Select a log type from the dropdown menu (e.g., Error Log, Slow Query Log)  
   - Element: **Log Type** (dropdown) — top of the logs table  
   - Notes: Some log types may be disabled by default; enable them in the instance configuration if needed.

4. Set the time range for log retrieval using the date picker  
   - Element: **Time Range** (date_input) — top of the logs table  
   - Notes: Maximum time range is typically 7 days.

5. Click **Download** to export the selected logs as a file  
   - Element: **Download** (button) — top-right corner  
   - Notes: Logs are downloaded in .txt format. Large files may take time to generate.

| Parameter | Type | Required | Options/Values | Description |
|-----------|------|----------|----------------|-------------|
| Log Type | dropdown | Yes | Error Log, Slow Query Log, Binlog, Audit Log | Specifies which type of log to view or download |
| Time Range | date_input | Yes | — | Sets the time period for which logs will be retrieved (default: Last 24 hours) |

### Query PostgreSQL Logs

**Navigation**: RDS > Instances > Select Instance > Database Management > SQL Console

**Prerequisites**:
- Your RDS instance runs PostgreSQL 11
- If the extension cannot be created, update the minor engine version of your instance

1. Connect to the RDS instance via SQL console  
   - Element: **SQL Console** (link) — main content area  
   - Notes: Access the SQL Console from the instance's management page.

2. Run the command to create the log_fdw extension  
   - Element: **Run** (button) — bottom of the SQL editor  
   - Notes: The command is: `CREATE EXTENSION log_fdw;`

3. Create a log server using the foreign data wrapper  
   - Element: **Run** (button) — bottom of the SQL editor  
   - Notes: Command: `CREATE SERVER log_server FOREIGN DATA WRAPPER log_fdw;`

4. List available log files using the list_postgres_log_files() function  
   - Element: **Run** (button) — bottom of the SQL editor  
   - Notes: Command: `SELECT * FROM list_postgres_log_files() ORDER BY 1;`

5. Create a foreign table for a specific log file  
   - Element: **Run** (button) — bottom of the SQL editor  
   - Notes: Command: `SELECT create_foreign_table_for_log_file('ft1', 'log_server', 'postgresql-2020-01-13_030618.csv');`

6. Query the foreign table to retrieve log entries  
   - Element: **Run** (button) — bottom of the SQL editor  
   - Notes: Command: `SELECT log_time, message FROM ft1 ORDER BY log_time DESC LIMIT 2;`

### Enable SQL Explorer and Audit (MySQL/PostgreSQL)

**Navigation**: Console > RDS > Instance Details > Autonomous Service > Audit

**Prerequisites**:
- Subscribed to DAS Enterprise Edition
- RAM user must have the AliyunRDSReadOnlyWithSQLLogArchiveAccess permission
- For MySQL transaction ID queries: `loose_rds_audit_log_version` set to MYSQL_V3 and minor engine version ≥ 20210930 (MySQL 8.0) or ≥ 20210630 (MySQL 5.7)

1. Navigate to the Audit section  
   - Element: **Autonomous Service > Audit** (menu) — left-side navigation pane  
   - Notes: This path applies to both MySQL and PostgreSQL instances.

2. Click **Enable DAS Enterprise Edition V3** (MySQL) or **Enable Audit Logs** (PostgreSQL)  
   - Element: **Enable DAS Enterprise Edition V3** (button) — main content area  
   - Notes: Image shows the button with a checkmark icon.

3. Select features to enable and confirm  
   - Element: **Open KMS** (button) — dialog box  
   - Notes: Confirm feature selection in the pop-up dialog.

4. Modify the data retention period  
   - Element: **Service Settings** (button) — main content area  
   - Notes: Opens the Service Settings page.

5. Set the new log retention period and save changes  
   - Element: **Save** (button) — Service Settings page  
   - Notes: DAS storage does not count against instance storage.

6. Export audit logs before disabling (optional but recommended)  
   - Element: **Export** (button) — Query Set section  
   - Notes: You can set a longer export time range using the ExportTimeRange field; export uses CSV format.

7. Download the exported file  
   - Element: **OK** (button) — export dialog  
   - Notes: File becomes available for download after processing.

8. Disable SQL Explorer and Audit (if needed)  
   - Element: **Service Settings** (button) — main content area  
   - Notes: Clear all checkboxes for SQL Explorer and Audit features and click Save. Logs are deleted immediately upon disable.

### Enable SQL Audit (PPAS)

**Navigation**: RDS > Instances > Select Instance > Database Audit

**Prerequisites**:
- An ApsaraDB RDS for PPAS instance must be created
- The user must have sufficient permissions to modify database audit settings

1. Navigate to the RDS console and select the target instance  
   - Element: **Instances** (link) — left navigation panel  
   - Notes: Ensure the instance is running.

2. Go to the **Database Audit** tab  
   - Element: **Database Audit** (tab) — main content area  
   - Notes: This tab is specific to PPAS instances.

3. Click the **Enable SQL Audit** button  
   - Element: **Enable SQL Audit** (button) — top-right corner  
   - Notes: The feature is disabled by default. Enabling it will start logging SQL statements.

4. Confirm the action in the dialog box  
   - Element: **Confirm** (button) — dialog box  
   - Notes: After enabling, you will be charged additional fees.

## FAQ

Q: Where can I find slow query logs for my RDS instance?
A: Navigate to Console > RDS > Instances > [Your Instance] > Logs, then select "Slow Query Log" from the Log Type dropdown.

Q: What happens if I disable SQL Explorer and Audit?
A: All stored audit logs are immediately deleted, and the storage space is released within approximately one hour. Export logs before disabling if you need to retain them.

Q: Can I query PostgreSQL logs without downloading them?
A: Yes, by using the log_fdw extension to create foreign tables that map to log files, allowing direct SQL queries against log data.

Q: What is the maximum time range I can query for SQL audit logs?
A: The maximum online query time range is 24 hours. However, when exporting logs, you can specify a longer time range.

Q: Are there any performance impacts from enabling SQL Audit on PPAS?
A: Yes, enabling SQL Audit may impact database performance due to continuous logging of SQL statements. It is disabled by default for this reason.

## Pricing & Billing

### Billing Model
Log downloads are charged per request. SQL Explorer and Audit is billed per GB-hour based on region and DAS Enterprise Edition usage. The log_fdw extension for PostgreSQL incurs no additional cost.

### Price Reference
| Region/Tier | Price |
|------------|-------|
| China (Hong Kong), Singapore | CNY 0.0122 per GB/hour |
| All other regions except China (Hong Kong) and Singapore | CNY 0.008 per GB/hour |
| China (Hangzhou), China (Shanghai), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Hohhot), China (Ulanqab), China (Shenzhen), China (Heyuan), China (Guangzhou), China (Chengdu) | USD 0.0012 per GB/hour |
| US (Silicon Valley), US (Virginia) | USD 0.0015 per GB/hour |
| Singapore, Japan (Tokyo), Germany (Frankfurt), UAE (Dubai), Malaysia (Kuala Lumpur), Indonesia (Jakarta), UK (London) | USD 0.0018 per GB/hour |
| Log Download | CNY 0.001 per request |

### Free Tier
- Log downloads: 100 free requests per month
- log_fdw extension: No additional cost; included in RDS instance pricing

### Billing Notes
- Log downloads are charged per request. Free tier resets monthly. Large log files may incur higher costs due to size limits (max 100 MB per download).
- After upgrading from legacy SQL Explorer to SQL Explorer and Audit, billing is handled by DAS Enterprise Edition.
- Storage packages or Savings Plans can offset SQL Explorer and Audit costs.
- For PPAS SQL Audit, additional fees apply after enabling; refer to the ApsaraDB RDS pricing page for details.
- Data is deleted immediately when SQL Explorer and Audit is disabled.