Skip to content

Commit 9b290ae

Browse files
committed
PS-10190 [DOCS] - Binary Log UDFs functions documentation incomplete 8.4
modified: docs/binlogging-replication-improvements.md
1 parent 098dd9f commit 9b290ae

File tree

1 file changed

+135
-62
lines changed

1 file changed

+135
-62
lines changed

docs/binlogging-replication-improvements.md

Lines changed: 135 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -165,139 +165,212 @@ mysql> SET binlog_ddl_skip_rewrite = ON;
165165

166166
## Point-in-Time Recovery with `binlog_utils_udf`
167167

168-
Use the binlog_utils_udf component to assist with Point-in-Time Recovery (PiTR).
169-
The component installs user-defined functions (UDFs) that help you map GTIDs to
170-
binary log files and inspect the contents and timestamps of binlog files.
168+
Point-in-Time Recovery (PiTR) allows you to restore a database to any specific moment in time using binary logs. The `binlog_utils_udf` component provides user-defined functions (UDFs) that simplify PiTR operations by helping you:
171169

172-
### Functions
170+
* Map Global Transaction Identifiers (GTIDs) to specific binary log files
171+
* Inspect binary log contents and timestamps
172+
* Locate the exact binary log files needed for recovery operations
173173

174-
| Function | Returns | Description |
175-
|-----------------------------------------|----------------------|-------------------------------------------------------------------------|
176-
| get_binlog_by_gtid(gtid) | STRING (binlog name) | Returns the binlog file that contains the specified GTID. |
177-
| get_last_gtid_from_binlog(binlog) | STRING (GTID) | Returns the last GTID found in the specified binlog. |
178-
| get_gtid_set_by_binlog(binlog) | STRING (GTID set) | Returns all GTIDs found in the specified binlog. |
179-
| get_binlog_by_gtid_set(gtid_set) | STRING (binlog name) | Returns the first binlog file that contains at least one GTID from the specified set. |
180-
| get_first_record_timestamp_by_binlog(binlog) | INTEGER (timestamp) | Returns the timestamp of the first event in the specified binlog. |
181-
| get_last_record_timestamp_by_binlog(binlog) | INTEGER (timestamp) | Returns the timestamp of the last event in the specified binlog. |
174+
These functions are particularly useful when you need to determine which binary log files contain specific transactions or events during recovery planning.
182175

183-
### Notes
176+
### Prerequisites
184177

185-
* Timestamp-returning functions provide values with microsecond precision in
186-
UNIX time. Each value represents the number of microseconds since
187-
1970-01-01 00:00:00 UTC.
178+
Before using the `binlog_utils_udf` component, ensure the following requirements are met:
188179

189-
* Functions that accept a binlog name require a short file name only. Do not
190-
include a path. If the input contains a path separator (/), the server
191-
returns an error.
180+
* Percona Server for MySQL: The component is only available in Percona Server for MySQL, not in standard MySQL
192181

193-
* The server reads binlogs from the current binlog directory defined by the
194-
@@log_bin_basename system variable.
182+
* Binary logging enabled: The server must have binary logging enabled (`log_bin` system variable set to `ON`)
195183

196-
* Functions that return a binlog file name return the short name (no path).
184+
* GTID enabled: For GTID-related functions, GTID must be enabled (`gtid_mode` set to `ON`)
197185

198-
### Install the component
186+
* MySQL privileges: You need `SYSTEM_VARIABLES_ADMIN` privilege to install components. For binary log operations, `BINLOG_ADMIN` privilege may also be required. The `SUPER` privilege is deprecated in MySQL 8.0+ and should be replaced with specific dynamic privileges
199187

200-
Install the component once on each server where you want to use these UDFs.
188+
#### Install the component
189+
190+
Install the component on each server where you plan to use these functions:
201191

202192
```{.bash data-prompt="mysql>"}
203193
mysql> INSTALL COMPONENT 'file://component_binlog_utils_udf';
204194
```
205195

206-
You can confirm installation by checking the list of registered functions:
196+
#### Verify installation
197+
198+
Confirm the component is loaded successfully:
199+
200+
```{.bash data-prompt="mysql>"}
201+
mysql> SELECT * FROM mysql.component WHERE component_urn = 'file://component_binlog_utils_udf';
202+
```
203+
204+
The query should return one row if the component is installed. You can also verify by checking for the available functions:
207205

208206
```{.bash data-prompt="mysql>"}
209-
mysql> SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES \G
207+
mysql> SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
208+
-> WHERE ROUTINE_NAME LIKE 'get_%' AND ROUTINE_TYPE = 'FUNCTION';
210209
```
211210

211+
### Available functions
212+
213+
The `binlog_utils_udf` component provides six functions for binary log analysis and GTID mapping:
214+
215+
| Function | Returns | Description | Use Case |
216+
|-----------------------------------------|----------------------|-------------------------------------------------------------------------|----------|
217+
| [`get_binlog_by_gtid(gtid)`](#find-binary-log-by-gtid) | STRING (binlog name) | Returns the binary log file that contains the specified GTID. | Find which binary log contains a specific transaction |
218+
| [`get_last_gtid_from_binlog(binlog)`](#get-last-gtid-from-binary-log) | STRING (GTID) | Returns the last GTID found in the specified binary log. | Identify the final transaction in a binary log file |
219+
| [`get_gtid_set_by_binlog(binlog)`](#get-all-gtids-from-binary-log) | STRING (GTID set) | Returns all GTIDs found in the specified binary log. | Get complete list of transactions in a binary log |
220+
| [`get_binlog_by_gtid_set(gtid_set)`](#find-binary-log-by-gtid-set) | STRING (binlog name) | Returns the first binary log file that contains at least one GTID from the specified set. | Find binary log containing any transaction from a GTID set |
221+
| [`get_first_record_timestamp_by_binlog(binlog)`](#get-first-event-timestamp) | INTEGER (timestamp) | Returns the timestamp of the first event in the specified binary log. | Determine when a binary log file started |
222+
| [`get_last_record_timestamp_by_binlog(binlog)`](#get-last-event-timestamp) | INTEGER (timestamp) | Returns the timestamp of the last event in the specified binary log. | Determine when a binary log file ended |
223+
224+
### Important notes
225+
226+
* CAST requirement: When using these user-defined functions, you must use CAST to return a result. String functions require `CAST(...AS CHAR)` and timestamp functions require `CAST(...AS UNSIGNED)`.
227+
228+
* Timestamp precision: Timestamp-returning functions provide values with microsecond precision in UNIX time format. Each value represents the number of microseconds since 1970-01-01 00:00:00 UTC.
229+
230+
* Binary log file names: Functions that accept a binary log name require only the short file name (for example, `binlog.000001`). Do not include the full path. If the input contains a path separator (`/`), the server returns an error.
231+
232+
* Binary log directory: The server reads binary logs from the directory defined by the `@@log_bin_basename` system variable.
233+
234+
* Return values: Functions that return binary log file names return only the short name without the path.
235+
236+
* Performance considerations: These functions read binary log files directly from disk. For large binary log files, the functions may take several seconds to complete.
237+
238+
212239

213240
### Usage examples
214241

215-
Replace the sample arguments with values from your environment. The examples
216-
show the typical way to call each function. For clarity, results are aliased.
242+
The following examples demonstrate how to use each function. Replace the sample arguments with values from your environment. All examples include the required CAST statements for proper function execution.
217243

218-
#### get_binlog_by_gtid()
244+
#### Find binary log by GTID
219245

220-
Locate the binlog that contains a GTID:
246+
Use `get_binlog_by_gtid()` to locate which binary log file contains a specific transaction:
221247

222248
```{.bash data-prompt="mysql>"}
223-
mysql> SELECT get_binlog_by_gtid('UUID-GROUP:1') AS binlog;
249+
mysql> SELECT CAST(get_binlog_by_gtid('550e8400-e29b-41d4-a716-446655440000:123') AS CHAR) AS binlog;
224250
```
225251

226-
#### get_last_gtid_from_binlog()
252+
Use case: When you know a specific GTID and need to find which binary log file contains that transaction for recovery purposes.
253+
254+
#### Get last GTID from binary log
227255

228-
Return the last GTID in a binlog
256+
Use `get_last_gtid_from_binlog()` to find the final transaction in a specific binary log file:
229257

230258
```{.bash data-prompt="mysql>"}
231-
mysql> SELECT get_last_gtid_from_binlog('binlog.000001') AS last_gtid;
259+
mysql> SELECT CAST(get_last_gtid_from_binlog('binlog.000001') AS CHAR) AS last_gtid;
232260
```
233261

234-
#### get_gtid_set_by_binlog()
262+
Use case: Determine the last transaction processed in a binary log file before rotating to the next file.
235263

236-
Return all GTIDs in a binlog
264+
#### Get all GTIDs from binary log
265+
266+
Use `get_gtid_set_by_binlog()` to retrieve all GTIDs contained in a specific binary log file:
237267

238268
```{.bash data-prompt="mysql>"}
239-
mysql> SELECT get_gtid_set_by_binlog('binlog.000001') AS gtid_set;
269+
mysql> SELECT CAST(get_gtid_set_by_binlog('binlog.000001') AS CHAR) AS gtid_set;
240270
```
241271

242-
#### get_binlog_by_gtid_set()
272+
Use case: Get a complete list of all transactions in a binary log file for analysis or replication setup.
273+
274+
#### Find binary log by GTID set
243275

244-
Find a binlog that contains any GTID in a set
276+
Use `get_binlog_by_gtid_set()` to find the first binary log file that contains any GTID from a specified set:
245277

246278
```{.bash data-prompt="mysql>"}
247-
mysql> SELECT get_binlog_by_gtid_set('UUID1:7,UUID1:8') AS binlog;
279+
mysql> SELECT CAST(get_binlog_by_gtid_set('550e8400-e29b-41d4-a716-446655440000:7,550e8400-e29b-41d4-a716-446655440000:8') AS CHAR) AS binlog;
248280
```
249281

250-
#### get_first_record_timestamp_by_binlog() and get_last_record_timestamp_by_binlog(binlog)
282+
Use case: When you have a set of GTIDs and need to find which binary log file contains at least one of those transactions.
283+
284+
#### Get binary log timestamps
251285

252-
Get the first event timestamp from a binlog. The function returns microseconds since the UNIX epoch. Use the tabs below to
253-
see the raw numeric value or a human-readable timestamp.
286+
Use timestamp functions to determine when events occurred in binary log files. These functions return microsecond-precision timestamps in UNIX time format.
254287

255-
=== "Raw Timestamp"
288+
##### Get first event timestamp
289+
290+
Find when the first event was written to a binary log file:
291+
292+
=== "Raw Timestamp (Microseconds)"
256293
```{.bash data-prompt="mysql>"}
257-
mysql> SELECT get_first_record_timestamp_by_binlog('binlog.000001') AS raw_ts;
294+
mysql> SELECT CAST(get_first_record_timestamp_by_binlog('binlog.000001') AS UNSIGNED) AS raw_ts;
258295
```
259296

260-
=== "Human-Readable"
297+
=== "Human-Readable Format"
261298
```{.bash data-prompt="mysql>"}
262299
mysql> SELECT FROM_UNIXTIME(
263-
get_first_record_timestamp_by_binlog('binlog.000001') DIV 1000000
300+
CAST(get_first_record_timestamp_by_binlog('binlog.000001') AS UNSIGNED) DIV 1000000
264301
) AS first_event_ts;
265302
```
266303

267-
Get the last event timestamp from a binlog
304+
Use case: Determine when a binary log file started receiving events, useful for recovery planning.
305+
306+
##### Get last event timestamp
268307

269-
=== "Raw Timestamp"
308+
Find when the last event was written to a binary log file:
309+
310+
=== "Raw Timestamp (Microseconds)"
270311
```{.bash data-prompt="mysql>"}
271-
mysql> SELECT get_last_record_timestamp_by_binlog('binlog.000001') AS raw_ts;
312+
mysql> SELECT CAST(get_last_record_timestamp_by_binlog('binlog.000001') AS UNSIGNED) AS raw_ts;
272313
```
273314

274-
=== "Human-Readable"
315+
=== "Human-Readable Format"
275316
```{.bash data-prompt="mysql>"}
276317
mysql> SELECT FROM_UNIXTIME(
277-
get_last_record_timestamp_by_binlog('binlog.000001') DIV 1000000
318+
CAST(get_last_record_timestamp_by_binlog('binlog.000001') AS UNSIGNED) DIV 1000000
278319
) AS last_event_ts;
279320
```
280321

322+
Use case: Determine when a binary log file stopped receiving events, useful for understanding binary log rotation timing.
323+
324+
325+
### Troubleshooting
326+
327+
#### Common issues
328+
329+
Function returns NULL: This usually indicates that the specified GTID or binary log file does not exist. Verify that:
330+
331+
* The GTID format is correct (UUID:transaction_id)
281332

282-
??? example "Expected output"
333+
* The binary log file exists in the binary log directory
283334

284-
```{.text .no-copy}
285-
+---------------+
286-
| binlog |
287-
+---------------+
288-
| binlog.000001 |
289-
+---------------+
290-
```
335+
* GTID is enabled on the server
291336

292-
Actual values depend on your server state and binlog contents.
337+
Error: "Unknown function": The component is not installed. Install the component using the `INSTALL COMPONENT` command.
338+
339+
Error: "Access denied": You need `SYSTEM_VARIABLES_ADMIN` privilege to install the component and `BINLOG_ADMIN` privilege for binary log operations. The `SUPER` privilege is deprecated in MySQL 8.0+.
340+
341+
Performance issues: These functions read binary log files directly from disk. For large binary log files, expect execution times of several seconds.
342+
343+
#### Verify binary log files
344+
345+
Check which binary log files are available:
346+
347+
```{.bash data-prompt="mysql>"}
348+
mysql> SHOW BINARY LOGS;
349+
```
350+
351+
#### Check GTID status
352+
353+
Verify GTID is enabled:
354+
355+
```{.bash data-prompt="mysql>"}
356+
mysql> SHOW VARIABLES LIKE 'gtid_mode';
357+
```
293358

294359
### Uninstall the component
295360

296-
Remove the component and all associated UDFs:
361+
Remove the component and all associated functions:
297362

298363
```{.bash data-prompt="mysql>"}
299364
mysql> UNINSTALL COMPONENT 'file://component_binlog_utils_udf';
300365
```
366+
367+
Verify removal:
368+
369+
```{.bash data-prompt="mysql>"}
370+
mysql> SELECT * FROM mysql.component WHERE component_urn = 'file://component_binlog_utils_udf';
371+
```
372+
373+
The query should return no rows if the component is successfully uninstalled.
301374

302375
## Limitations
303376

0 commit comments

Comments
 (0)