Currently, when using the preferences database for development, debugging, and problem locating, developers are unable to view the content information in the database files, such as metadata and user data.
To improve developers' work efficiency, the database debugging tool allows developers to view the preference_kv and preference_xml databases on devices.
The preference storage mode corresponding to the preference_kv database is GSKV mode, and that corresponding to the preference_xml database is XML mode.
The preferences database debugging tool is available since HarmonyOS 6.0.0.
Before using the Preferences debugging tool, switch to the target application path and then run the arkdata command to access this tool. (You need to use ArkData to configure relevant parameters to open the preferences database, and only after the database is successfully opened can you use the Preferences tool to add, delete, modify, and query data.)
The following table describes the parameters supported by the arkdata command.
| Parameter | Value Type | Description |
|---|---|---|
| -t | String | Database type, which is used to access the corresponding database debugging tool. Value range: {preference_kv, preference_xml, vector} |
| -f | String | Full path of the database file, which includes the file name. The path cannot end with a slash (/). |
| -p | Integer | Database pagesize, a database opening configuration parameter, indicates the size of a single page to be stored. The default value is 32; allowed values are 4, 8, 16, 32, and 64. |
| -c | Integer | Database cacheSize (or bufferPoolSize), a database opening configuration parameter, indicates the size of the memory cache pool. The default value is 2048; allowed values are 2048 and 4096. |
| -h | N/A | Help information about the program. |
The -p and -c parameters of the preferences database debugging tool are invalid. If the values of pagesize and cachesize are within the specified range, the default values 32 and 2048 are used. If the values are beyond the specified range, an error is reported.
C:\Users\*****>hdc shell $ cd /data/app/el1/100/base/com.test.myapplication // Go to the target app path. (The current path is an example. Go to the path based on your actual needs.) $ arkdata -t preference_kv // -f is not specified, indicating that no database file is specified. By default, a database named "arkdata" is created in the data/preference_kv directory of the current working directory. Enter ".help" for usage hints.
When opening the database in the path of a non-target application, if the -f parameter is missing (which would trigger the default folder creation), the process of creating the data/preference_kv folder hierarchy in the current directory fails. The error information is as follows:
C:\Users\*****>hdc shell $ arkdata -t preference_kv [unsucc]Failed to create directory ./data/preference_kv : Permission denied
When opening the database in the path of a non-target application, the .db file fails to be created in the specified path. The error information is as follows:
C:\Users\*****>hdc shell $ arkdata -t preference_kv -f ./preference_kv [GMDB SERVER] [GMERR-1013000] multi-process init init unsucc! [ERROR] open db fail, ret = -5000.
Cross-read and cross-write operations between databases preference_xml and preference_kv (which share the same name) are not allowed. When preference_kv opens a preference_xml database, an error is reported. When preference_xml opens a preference_kv database, the database is damaged. The error information is as follows:
$ ls ./data/preference_kv arkdata arkdata.ctrl.dwr arkdata.redo arkdata.undo arkdata.ctrl arkdata.map arkdata.safe $ ls ./data/preference_xml/ arkdata arkdata.lock $ arkdata -t preference_kv -f ./data/preference_xml/arkdata [GMDB SERVER] [GMERR-1019003] open-mode check init unsucc! [unsucc] open db fail, ret = -43000 $ arkdata -t preference_xml -f ./data/preference_kv/arkdata Enter ".help" for usage hints. preference_xml>>> /data/temp/./data/preference_kv/arkdata:1: parser error : Start tag expected, '<' not found ^
Run the arkdata --help command to view the parameters related to the entire graph store.
C:\Users\*****>hdc shell $ arkdata --help USAGE arkdata [option] OPTION -t|--type <preference_kv | preference_xml | vector>, it is mandatory -f|--file <database file path> -p|--pageSize <database pageSize> -c|--cacheSize <database cacheSize> -h|--help
The following table lists the commands supported by the preference_kv and preference_xml debugging tools.
| Command Format | Description |
|---|---|
| .help | Displays the help information. |
| .q | .quit | Exits the database interaction mode. |
| get key:{key name} | Queries the database based on the specified key. |
put key:{key name} value:{value} | Inserts a KV pair to the database or updates the KV pair. You need to input two lines of commands, where the first line uses key: as the keyword and the second line uses value: as the keyword. Example: put key:123 value:345 |
| delete key:{key name} | Deletes a KV pair. Example: delete key:123 |
| delete | Deletes all contents in the table. |
| scan | Scans the full table. Note: preference_xml supports full table query, but preference_kv does not. |
Numbers are of the int type by default. If a number is enclosed in quotation marks, the number is identified as string type.
Command line input data supports only the string, number, and boolean types. Other types will be converted to the string type.
Since hdc displays garbled characters when Chinese is used, the database debugging tool does not support Chinese.
Mobile phones and PCs/2-in-1 devices are supported.
After the preference_kv or preference_xml database is opened, you can run the .help command to view the supported commands.
preference_kv>>> .help
preference_xml>>> .help
Run the hdc shell command to enter the shell interaction mode.
You must switch to the path of the target debugging application, and then go to the path where the .db file is located. Run the arkdata -t preference_kv command (with -f set to the default value) or the arkdata -t preference_xml command (with -f set to the default value) to create a database.
C:\Users\*****>hdc shell $ cd /data/app/el1/100/database/com.test.myapplication // Go to the target application path. (The current path is an example. Go to the path based on your actual needs.) $ cd entry/rdb/ // Go to the path where the .db file exists. You need to have the read and write permissions on the .db file to create a new database. $ arkdata -t preference_kv Enter ".help" for usage hints. preference_kv>>>.q $ arkdata -t preference_xml Enter ".help" for usage hints. preference_xml>>> put key:1 // preference_xml needs to put a data record so that the database file can be created internally. ...>>> value:1 preference_xml>>> .q
Wait for the system to automatically generate the following files. The tag debug_hap_data_file indicates that the file is the target app file.
$ ls -lZ ./data/preference_kv/ total 148 -rw-rw---- 1 shell shell u:object_r:debug_hap_data_file:s0 73728 2025-08-12 20:31 arkdata -rw-rw---- 1 shell shell u:object_r:debug_hap_data_file:s0 4112 2025-08-12 20:31 arkdata.ctrl -rw-rw---- 1 shell shell u:object_r:debug_hap_data_file:s0 12304 2025-08-12 20:31 arkdata.ctrl.dwr -rw-rw---- 1 shell shell u:object_r:debug_hap_data_file:s0 0 2025-08-12 20:31 arkdata.map -rw-rw---- 1 shell shell u:object_r:debug_hap_data_file:s0 512 2025-08-12 20:31 arkdata.redo -rw-rw---- 1 shell shell u:object_r:debug_hap_data_file:s0 8 2025-08-12 20:31 arkdata.safe -rw-rw---- 1 shell shell u:object_r:debug_hap_data_file:s0 16384 2025-08-12 20:31 arkdata.undo $ ls -lZ ./data/preference_xml/ total 12 -rw-rw---- 1 root ddms u:object_r:debug_hap_data_file:s0 105 2025-09-05 15:11 arkdata -rw-rw---- 1 root ddms u:object_r:debug_hap_data_file:s0 0 2025-09-05 15:11 arkdata.lock
Open an existing database.
$ arkdata -t preference_kv -f ./data/preference_kv/arkdata Enter ".help" for usage hints. preference_kv>>>
At the preference_kv>>> prompt, you can insert a KV pair using the put command, and the following information is displayed.
preference_kv>>> put key:name ...>>> value:123 preference_kv>>> put key:id_name ...>>> value:'123' preference_kv>>> get key:name // Result without quotation marks. type int: 123 preference_kv>>> get key:id_name // Result with quotation marks. type string: 123
At the preference_xml>>> prompt, you can scan the full table using the scan command, and the following information is displayed.
preference_xml>>> scan ==========================PREFERENCES XML INFO============================ DataCount:7 ==========================PREFERENCES XML DATA============================ ==========================Data Index:1========================== key: 1 value: type int: 1 ==========================Data Index:2========================== key: 2 value: type int: 2 ==========================Data Index:3========================== key: 3 value: type int: 3 ==========================Data Index:4========================== key: 4 value: type int: 4 ==========================Data Index:5========================== key: 5 value: type int: 5 Press 'q' to quit, 'n' to continue: n ==========================Data Index:6========================== key: 6 value: type int: 6 ==========================Data Index:7========================== key: 7 value: type int: 7 preference_xml>>>
preference_kv does not support full table scanning. The following information is displayed.
preference_kv>>> scan [unsucc] Unable to parse command.
When the number of displayed data items reaches 5, the system asks you whether to continue displaying or exit. Enter q to exit the display or enter n to continue displaying.
At the preference_kv>>> prompt, you can run the get command to query the specified KV pair, and the following information is displayed.
preference_kv>>> get key:name No data for key = name // No value available.
The values queried with and without quotation marks are different. The following information is displayed.
preference_kv>>> put key:name1 ...>>> value:123 preference_kv>>> put key:name2 ...>>> value:'123' preference_kv>>> put key:name3 ...>>> value:true preference_kv>>> put key:name4 ...>>> value:'true' preference_kv>>> get key:name1 // Result of the number without quotation marks. type int: 123 preference_kv>>> get key:name2 // Result of the number with quotation marks. type string: 123 preference_kv>>> get key:name3 // Result of true without quotation marks. type bool: 1 preference_kv>>> get key:name4 // Result of true with quotation marks. type string: true
At the preference_kv>>> prompt, if the specified key exists, you can run the put command to update the KV pair. The following information is displayed.
preference_kv>>> put key:name ...>>> value:x preference_kv>>> get key:name type string: x preference_kv>>> put key:name ...>>> value:y preference_kv>>> get key:name type string: y
At the preference_kv>>> prompt, you can run the delete command to delete a specified KV pair. The following information is displayed.
preference_kv>>> get key:name type string: y preference_kv>>> delete key:name preference_kv>>> get key:name No data for key = name
If the delete command is used without specifying a KV pair, all data in the table is deleted. The following information is displayed.
preference_kv>>> get key:name type int: xx preference_kv>>> get key:id_name type int: yy preference_kv>>> delete preference_kv>>> get key:name No data for key = name preference_kv>>> get key:id_name No data for key = id_name
At the preference_kv>>> prompt, you can run the .q or .quit command to exit the database interaction mode. The following information is displayed.
preference_kv>>>.q $