-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Update documentation for query logging performance improvements (#5243) #5366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/modern-docs
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ NOTE: You can click on the variable name to jump to its definition | |
| | --------------------------------------------------------------------- | ------------- | | ||
| | [pgsql-auditlog_filename](#pgsql-auditlog_filename) | NULL | | ||
| | [pgsql-auditlog_filesize](#pgsql-auditlog_filesize) | 104857600 | | ||
| | [pgsql-auditlog_flush_timeout](#pgsql-auditlog_flush_timeout) | 1000 | | ||
| | [pgsql-auditlog_flush_size](#pgsql-auditlog_flush_size) | 4096 | | ||
| | [pgsql-aurora_max_lag_ms_only_read_from_replicas](#pgsql-aurora_max_lag_ms_only_read_from_replicas) | 2 | | ||
| | [pgsql-authentication_method](#pgsql-authentication_method) | 3 | | ||
| | [pgsql-auto_increment_delay_multiplex](#pgsql-auto_increment_delay_multiplex) | 5 | | ||
|
|
@@ -43,6 +45,9 @@ NOTE: You can click on the variable name to jump to its definition | |
| | [pgsql-eventslog_filename](#pgsql-eventslog_filename) | NULL | | ||
| | [pgsql-eventslog_filesize](#pgsql-eventslog_filesize) | 104857600 | | ||
| | [pgsql-eventslog_format](#pgsql-eventslog_format) | 1 | | ||
| | [pgsql-eventslog_flush_timeout](#pgsql-eventslog_flush_timeout) | 1000 | | ||
| | [pgsql-eventslog_flush_size](#pgsql-eventslog_flush_size) | 4096 | | ||
| | [pgsql-eventslog_rate_limit](#pgsql-eventslog_rate_limit) | 1 | | ||
| | [pgsql-firewall_whitelist_enabled](#pgsql-firewall_whitelist_enabled) | false | | ||
| | [pgsql-free_connections_pct](#pgsql-free_connections_pct) | 10 | | ||
| | [pgsql-handle_unknown_charset](#pgsql-handle_unknown_charset) | 1 | | ||
|
|
@@ -135,6 +140,40 @@ Maximum size of the PostgreSQL audit log file. | |
|
|
||
| **Description**: Specifies the size limit for individual PostgreSQL audit log files before they are rotated. | ||
|
|
||
|
|
||
| ### `pgsql-auditlog_flush_timeout` | ||
|
|
||
| Timeout for writting logs to PostgreSQL audit log file. | ||
|
|
||
| | | | | | ||
| | -------------------- | ----------- | ---------------------------- | | ||
| | **System Variable** | **Name** | pgsql-auditlog_flush_timeout | | ||
| | | **Dynamic** | Yes | | ||
| | **Permitted Values** | **Type** | Integer (milliseconds) | | ||
| | | **Default** | 1000 | | ||
| | | **Minimum** | 0 | | ||
| | | **Maximum** | | | ||
|
|
||
| **Description**: Specifies the timeout to write the buffered audit log entries to the | ||
| audit log file. The default value is 1000 (1 second). | ||
|
|
||
| ### `pgsql-auditlog_flush_size` | ||
|
|
||
| Size threshold for writting logs to PostgreSQL audit log file. | ||
|
||
|
|
||
| | | | | | ||
| | -------------------- | ----------- | -------------------------- | | ||
| | **System Variable** | **Name** | pgsql-auditlog_flush_size | | ||
| | | **Dynamic** | Yes | | ||
| | **Permitted Values** | **Type** | Integer (bytes) | | ||
| | | **Default** | 4096 | | ||
| | | **Minimum** | 0 | | ||
| | | **Maximum** | | | ||
|
|
||
| **Description**: This variable defines the flush size to write the buffered audit log entries to the | ||
| audit log file. If the size of the buffer goes beyond this value, | ||
| the contents of the buffer are written to the file. The default value is 4096. | ||
|
|
||
| ### `pgsql-aurora_max_lag_ms_only_read_from_replicas` | ||
|
|
||
| **Description**: Not supported. | ||
|
|
@@ -458,6 +497,56 @@ Format of the PostgreSQL events log. | |
|
|
||
| **Description**: Sets the logging format for PostgreSQL events. Currently, only format `1` (Binary) is supported. | ||
|
|
||
| ### `pgsql-eventslog_flush_timeout` | ||
|
|
||
| Timeout for writting logs to the PostgreSQL events log. | ||
|
||
|
|
||
| | | | | | ||
| | -------------------- | ----------- | ----------------------------- | | ||
| | **System Variable** | **Name** | pgsql-eventslog_flush_timeout | | ||
| | | **Dynamic** | Yes | | ||
| | **Permitted Values** | **Type** | Integer (milliseconds) | | ||
| | | **Default** | 1000 | | ||
| | | **Minimum** | 0 | | ||
| | | **Maximum** | | | ||
|
|
||
| **Description**: This variable defines the flush timeout to write the buffered event log entries to the | ||
| events log file. The default value is 1000 (1 second). | ||
|
|
||
| ### `pgsql-eventslog_flush_size` | ||
|
|
||
| Size threshold for writting logs to the PostgreSQL events log. | ||
|
||
|
|
||
| | | | | | ||
| | -------------------- | ----------- | -------------------------- | | ||
| | **System Variable** | **Name** | pgsql-eventslog_flush_size | | ||
| | | **Dynamic** | Yes | | ||
| | **Permitted Values** | **Type** | Integer (bytes) | | ||
| | | **Default** | 4096 | | ||
| | | **Minimum** | 0 | | ||
| | | **Maximum** | | | ||
|
|
||
| **Description**: This variable defines the flush size to write the buffered event log entries to the | ||
| events log file. If the size of the buffer goes beyond this value, | ||
| the contents of the buffer are written to the file. The default value is 4096. | ||
|
|
||
| ### `pgsql-eventslog_rate_limit` | ||
|
|
||
| Sampling rate for the PostgreSQL events log. | ||
|
|
||
| | | | | | ||
| | -------------------- | ----------- | -------------------------- | | ||
| | **System Variable** | **Name** | pgsql-eventslog_rate_limit | | ||
| | | **Dynamic** | Yes | | ||
| | **Permitted Values** | **Type** | Integer | | ||
| | | **Default** | 1 | | ||
| | | **Minimum** | 1 | | ||
| | | **Maximum** | | | ||
|
|
||
| **Description**: This variable defines the sampling rate for event logs. To log all | ||
| events, set this variable to 1. If the variable is set to N, where N > 1, the number of logs written to the file | ||
| will be approximately equal to 1/N. The default value is 1. | ||
|
|
||
| ### `pgsql-firewall_whitelist_enabled` | ||
|
|
||
| Enables the firewall whitelist for PostgreSQL. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ If you changed the variable `mysql-eventslog_format` to `2` (logging queries in | |
| and/or you would only like to log queries matching certain criteria, you need additional query rules in the | ||
| following manner: If you don't trust Bob, you can log all of Bob's queries: | ||
|
|
||
| ```sql | ||
| ```sqlhttps://proxysql.com/documentation/global-variables/mysql-variables/#mysql-auditlog_filename | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| INSERT INTO mysql_query_rules (rule_id, active, username, log, apply) VALUES (1, 1, 'Bob', 1, 0); | ||
| ``` | ||
|
|
||
|
|
@@ -130,6 +130,48 @@ Example of JSON logging: | |
| {"client":"127.0.0.1:39960","digest":"0x98A2503010E9E4C8","duration_us":1492,"endtime":"2019-07-14 18:06:04.013779","endtime_timestamp_us":1563091564013779,"event":"COM_STMT_EXECUTE","hostgroup_id":0,"query":"SELECT id,id2 FROM test1 WHERE id < ?","rows_affected":0,"rows_sent":4099,"schemaname":"test","server":"127.0.0.1:3306","starttime":"2019-07-14 18:06:04.012287","starttime_timestamp_us":1563091564012287,"thread_id":4,"username":"sbtest"} | ||
| ``` | ||
|
|
||
| ## Sampling | ||
|
|
||
| A new variable `mysql-eventslog_rate_limit` is introduced to control the sampling rate for event logs. When set to `1` (default), | ||
| all events are logged to the file. When set to a value greater than `1`, the number of events logged to the file will be | ||
| approximately equal to `1/N`, where `N` is the value set for the variable. | ||
|
||
|
|
||
| **To log all events (default)** | ||
|
|
||
| ```sql | ||
| SET mysql-eventslog_rate_limit=1; | ||
| LOAD MYSQL VARIABLES TO RUNTIME; | ||
| SAVE MYSQL VARIABLES TO DISK; | ||
| ``` | ||
|
|
||
| **To log events at a certain sampling rate** | ||
|
|
||
| ```sql | ||
| SET mysql-eventslog_rate_limit=100; | ||
| LOAD MYSQL VARIABLES TO RUNTIME; | ||
| SAVE MYSQL VARIABLES TO DISK; | ||
| ``` | ||
|
|
||
| ## Logging at high RPS | ||
|
|
||
| Logging queries at high throughput often requires tuning `mysql-eventslog_flush_timeout` and `mysql-eventslog_flush_size`. | ||
| These variables determine when the log entries stored in temporary buffers are flushed to the file on disk. | ||
|
|
||
| **Time based flush** | ||
|
|
||
| `mysql-eventslog_flush_timeout` triggers a flush when the time elapsed since the last flush exceeds the specified timeout value. | ||
|
|
||
| **Size based flush** | ||
|
|
||
| `mysql-eventslog_flush_size` triggers a flush when the buffer size (in bytes) exceeds the specified limit. Note that each worker thread maintains its own temporary buffer for log entries. Therefore, this variable should be tuned based on the available hardware resources. Increasing this value will increase memory consumption, roughly calculated as the number of worker threads multiplied by the flush size. | ||
|
|
||
| ```sql | ||
| SET mysql-eventslog_flush_timeout=5000; | ||
| SET mysql-eventslog_flush_size=16*1024; | ||
| LOAD MYSQL VARIABLES TO RUNTIME; | ||
| SAVE MYSQL VARIABLES TO DISK; | ||
| ``` | ||
|
|
||
| ## Related Issues and Feature Requests | ||
|
|
||
| Here's some related discussion on this feature. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo:
writtingshould bewriting.