Wiki source code of Database Administration

Version 35.1 by Vincent Massol on 2016/09/29

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 XWiki uses by default a database to store its data. You will find on this page tips and tricks to administer and tune your database setup. For Installation please check the [[Installation guide>>InstallationWAR#HInstallandconfigureaRelationalDatabase]] which contains information on how to setup XWiki for multiple databases.
6
7 = Indexes =
8
9 To improve the performance of your XWiki instance when running with many documents you should run the following script to create indexes for your database (this has been tested for MySQL 5.0):
10
11 == Indexes for XWiki Enterprise versions after 4.3 ==
12
13 {{info}}
14 Even though we configured XWiki to let Hibernate create indexes by default, there are some limitations and some indexes cannot be created automatically for string columns longer than 255 chars ([[MySQL has a limit of 255 characters>>http://dev.mysql.com/doc/refman/5.7/en/column-indexes.html]] - See also [[InnoDB limits>>http://dev.mysql.com/doc/refman/5.7/en/innodb-restrictions.html]]). Thus, at the moment these indexes need to be created manually (for all databases since our default Hibernate configuration file doesn't specify creating indexes for those).
15
16 Note that the following indexes could be created automatically though and thus should be added in a future version of XWiki so that they don't need to be created manually:
17
18 {{code}}
19 create index xws_number on xwikistatsdoc (XWS_NUMBER);
20 create index xws_classname on xwikistatsdoc (XWS_CLASSNAME);
21 create index xwr_number on xwikistatsreferer (XWR_NUMBER);
22 create index xwr_classname on xwikistatsreferer (XWR_CLASSNAME);
23 create index xwv_classname on xwikistatsvisit (XWV_CLASSNAME);
24 create index xwv_number on xwikistatsvisit (XWV_NUMBER);
25 create index xda_docid1 on xwikiattrecyclebin (xda_docid);
26 {{/code}}
27 {{/info}}
28
29 The following are all the indexes you need to have set in you instance. Most of them are set automatically but as mentioned above some will need to be set manually.
30
31 {{code}}
32 create index xwl_value on xwikilargestrings (xwl_value(50));
33 create index xwd_parent on xwikidoc (xwd_parent(50));
34 create index xwd_class_xml on xwikidoc (xwd_class_xml(20));
35 create index xws_number on xwikistatsdoc (XWS_NUMBER);
36 create index xws_classname on xwikistatsdoc (XWS_CLASSNAME);
37 create index xwr_number on xwikistatsreferer (XWR_NUMBER);
38 create index xwr_classname on xwikistatsreferer (XWR_CLASSNAME);
39 create index xwr_referer on xwikistatsreferer (XWR_REFERER(50));
40 create index xwv_user_agent on xwikistatsvisit (XWV_USER_AGENT(255));
41 create index xwv_cookie on xwikistatsvisit (XWV_COOKIE(255));
42 create index xwv_classname on xwikistatsvisit (XWV_CLASSNAME);
43 create index xwv_number on xwikistatsvisit (XWV_NUMBER);
44 create index ase_page_date on activitystream_events (ase_page, ase_date);
45 create index xda_docid1 on xwikiattrecyclebin (xda_docid);
46 create index ase_param1 on activitystream_events (ase_param1(200));
47 create index ase_param2 on activitystream_events (ase_param2(200));
48 create index ase_param3 on activitystream_events (ase_param3(200));
49 create index ase_param4 on activitystream_events (ase_param4(200));
50 create index ase_param5 on activitystream_events (ase_param5(200));
51 {{/code}}
52
53 == Indexes for XWiki Enterprise versions after 3.2 ==
54
55 {{code}}
56 create index xwl_value on xwikilargestrings (xwl_value(50));
57 create index xwd_parent on xwikidoc (xwd_parent(50));
58 create index xwd_class_xml on xwikidoc (xwd_class_xml(20));
59 create index xws_number on xwikistatsdoc (XWS_NUMBER);
60 create index xws_classname on xwikistatsdoc (XWS_CLASSNAME);
61 create index xwr_number on xwikistatsreferer (XWR_NUMBER);
62 create index xwr_classname on xwikistatsreferer (XWR_CLASSNAME);
63 create index xwr_referer on xwikistatsreferer (XWR_REFERER(50));
64 create index xwv_user_agent on xwikistatsvisit (XWV_USER_AGENT(255));
65 create index xwv_cookie on xwikistatsvisit (XWV_COOKIE(255));
66 create index xwv_classname on xwikistatsvisit (XWV_CLASSNAME);
67 create index xwv_number on xwikistatsvisit (XWV_NUMBER);
68 create index ase_requestid on activitystream_events (ase_requestid(200));
69 create index ase_page_date on activitystream_events (ase_page, ase_date);
70 create index xda_docid1 on xwikiattrecyclebin (xda_docid);
71 create index ase_param1 on activitystream_events (ase_param1(200));
72 create index ase_param2 on activitystream_events (ase_param2(200));
73 create index ase_param3 on activitystream_events (ase_param3(200));
74 create index ase_param4 on activitystream_events (ase_param4(200));
75 create index ase_param5 on activitystream_events (ase_param5(200));
76 {{/code}}
77
78 {{info}}
79 * Most indexes are created automatically starting with XWiki Enterprise 3.2 and only the indexes listed above need to be created.
80 * For older versions every index must be created manually. You can see the full list of indexes that should be created for older versions below. There is now [[an application>>extensions:Extension.Check Config And Indexes Application]] that runs this script automatically on XE and XEM directly from your wiki.
81 {{/info}}
82
83 == Indexes for XWiki Enterprise versions before 3.2 ==
84
85 {{code}}
86 create index DOC_SPACE on xwikidoc (XWD_WEB);
87 create index DOC_NAME on xwikidoc (XWD_NAME);
88 create index DOC_FULLNAME on xwikidoc (XWD_FULLNAME);
89 create index DOC_TITLE on xwikidoc (XWD_TITLE);
90 create index DOC_PARENT on xwikidoc (XWD_PARENT(50));
91 create index DOC_CREATION_DATE on xwikidoc (XWD_CREATION_DATE);
92 create index DOC_DATE on xwikidoc (XWD_DATE);
93 create index DOC_CONTENT_UPDATE_DATE on xwikidoc (XWD_CONTENT_UPDATE_DATE);
94 create index DOC_CREATOR on xwikidoc (XWD_CREATOR);
95 create index DOC_AUTHOR on xwikidoc (XWD_AUTHOR);
96 create index DOC_CONTENT_AUTHOR on xwikidoc (XWD_CONTENT_AUTHOR);
97 create index DOC_LANGUAGE on xwikidoc (XWD_LANGUAGE);
98 create index DOC_DEFAULT_LANGUAGE on xwikidoc (XWD_DEFAULT_LANGUAGE);
99 create index DOC_CLASS_XML on xwikidoc (XWD_CLASS_XML(20));
100 create index DOC_MINOREDIT on xwikidoc (XWD_MINOREDIT);
101 create index DOC_HIDDEN on xwikidoc (XWD_HIDDEN);
102 create index OBJ_NAME on xwikiobjects (XWO_NAME);
103 create index OBJ_CLASSNAME on xwikiobjects (XWO_CLASSNAME);
104 create index OBJ_NUMBER on xwikiobjects (XWO_NUMBER);
105
106 create index XWINT_NAME on xwikiintegers (XWI_NAME);
107 create index XWINT_VALUE on xwikiintegers (XWI_VALUE);
108 create index XWLONG_NAME on xwikilongs (XWL_NAME);
109 create index XWLONG_VALUE on xwikilongs (XWL_VALUE);
110 create index XWFLOAT_NAME on xwikifloats (XWF_NAME);
111 create index XWFLOAT_VALUE on xwikifloats (XWF_VALUE);
112 create index XWDOUBLE_NAME on xwikidoubles (XWD_NAME);
113 create index XWDOUBLE_VALUE on xwikidoubles (XWD_VALUE);
114 create index XWDATE_NAME on xwikidates (XWS_NAME);
115 create index XWDATE_VALUE on xwikidates (XWS_VALUE);
116 create index XWSTR_NAME on xwikistrings (XWS_NAME);
117 create index XWSTR_VALUE on xwikistrings (XWS_VALUE);
118 create index XWLS_NAME on xwikilargestrings (XWL_NAME);
119 create index XWLS_VALUE on xwikilargestrings (XWL_VALUE(50));
120
121 create index xwr_isdiff on xwikircs(xwr_isdiff);
122 create index xws_name on xwikistatsdoc (XWS_NAME);
123 create index xws_number on xwikistatsdoc (XWS_NUMBER);
124 create index xws_classname on xwikistatsdoc (XWS_CLASSNAME);
125 create index xws_action on xwikistatsdoc (XWS_ACTION);
126 create index xws_page_views on xwikistatsdoc (XWS_PAGE_VIEWS);
127 create index xws_unique_visitors on xwikistatsdoc (XWS_UNIQUE_VISITORS);
128 create index xws_period on xwikistatsdoc (XWS_PERIOD);
129 create index xws_visits on xwikistatsdoc (XWS_VISITS);
130 create index xwr_number on xwikistatsreferer (XWR_NUMBER);
131 create index xwr_name on xwikistatsreferer (XWR_NAME);
132 create index xwr_classname on xwikistatsreferer (XWR_CLASSNAME);
133 create index xwr_referer on xwikistatsreferer (XWR_REFERER(50));
134 create index xwr_page_views on xwikistatsreferer (XWR_PAGE_VIEWS);
135 create index xwr_period on xwikistatsreferer (XWR_PERIOD);
136 create index xwv_start_date on xwikistatsvisit (XWV_START_DATE);
137 create index xwv_name on xwikistatsvisit (XWV_NAME);
138 create index xwv_page_views on xwikistatsvisit (XWV_PAGE_VIEWS);
139 create index xwv_page_saves on xwikistatsvisit (XWV_PAGE_SAVES);
140 create index xwv_downloads on xwikistatsvisit (XWV_DOWNLOADS);
141 create index xwv_end_date on xwikistatsvisit (XWV_END_DATE);
142 create index xwv_ip on xwikistatsvisit (XWV_IP);
143 create index xwv_user_agent on xwikistatsvisit (XWV_USER_AGENT(255));
144 create index xwv_cookie on xwikistatsvisit (XWV_COOKIE(255));
145 create index xwv_unique_id on xwikistatsvisit (XWV_UNIQUE_ID);
146 create index xwv_classname on xwikistatsvisit (XWV_CLASSNAME);
147 create index xwv_number on xwikistatsvisit (XWV_NUMBER);
148
149 create index xdd_fullname1 on xwikirecyclebin (xdd_fullname);
150 create index xdd_language on xwikirecyclebin (xdd_language);
151 create index xdd_date on xwikirecyclebin (xdd_date);
152 create index xdd_deleter on xwikirecyclebin (xdd_deleter);
153 create index xda_docid1 on xwikiattrecyclebin (xda_docid);
154 create index xda_doc_name on xwikiattrecyclebin (xda_doc_name);
155 create index xda_filename on xwikiattrecyclebin (xda_filename);
156 create index xda_date on xwikiattrecyclebin (xda_date);
157 create index xda_deleter on xwikiattrecyclebin (xda_deleter);
158
159 create index ase_requestid on activitystream_events (ase_requestid(200));
160 create index ase_stream on activitystream_events (ase_stream);
161 create index ase_date on activitystream_events (ase_date);
162 create index ase_type on activitystream_events (ase_type);
163 create index ase_application on activitystream_events (ase_application);
164 create index ase_user on activitystream_events (ase_user);
165 create index ase_wiki on activitystream_events (ase_wiki);
166 create index ase_space on activitystream_events (ase_space);
167 create index ase_page on activitystream_events (ase_page);
168 create index ase_page_date on activitystream_events (ase_page, ase_date);
169 {{/code}}
170
171 = Sanity Checks =
172
173 To verify the consistency of your XWiki database you can run the sanity check script. The script will select rows that are inconsistent with the logics of XWiki. If no rows are selected, it means the script itself can not detect any error.
174
175 * If you use **MySQL** as your database:
176 ** The following [[sanity check script>>attach:sanitycheck.sql]] has been tested for **MySQL 5.0** (also been reported to work with MS-SQL)
177 ** Another [[script>>attach:sanitycheckMySQL4.sql]] is a variant of the previous script for **MySQL 4.x** replacing some syntax with more ancient one (still reports errors in one command)
178 * If you use **postgresql** as your database:
179 ** Here is a [[modified version of the sanity check script>>attach:sanitycheck_postgresql.sql]], to be run in the "query" tool of pgAdmin. It is the same as the script for MySQL, except that the syntax for SQL comments is different.
180 ** pgAdmin is the GUI tool provided with postgresql to access the database. Run pgAdmin, select the ##xwiki## database, and choose the "Query" option in the "Tools" menu. Then just open the script and click on the play icon ("Execute query").
181
182 = Database browsing =
183
184 == DbVisualizer ==
185
186 [[DbVisualizer>>http://www.dbvis.com/download/]] natively supports these DBs:
187
188 * DB2 for Windows/Linux
189 * JavaDB/Derby
190 * MySQL
191 * PostgreSQL
192 * [[and more>>http://www.dbvis.com/features/tour/supported-databases/]]
193
194 Any DB using the corresponding JDBC driver:
195
196 * Example: HSQLDB by using the driver bundled with XWiki

Get Connected