@@ -190,3 +190,127 @@ The `django_session` table is used to store user sessions. Expired sessions are
190190docker exec -it seatable-server /bin/bash
191191seatable.sh python-env /opt/seatable/seatable-server-latest/dtable-web/manage.py clearsessions
192192```
193+
194+ ## Database Analysis Commands for SeaTable
195+
196+ Here's a concise guide for database analysis of a SeaTable Server.
197+
198+ ### Determine Database Table Sizes
199+
200+ Use the command line tool ` ncdu ` on ` /opt/mariadb ` for an easy-to-navigate overview of table sizes. Here is an example output. Typically operation_log is by far the biggest table of all.
201+
202+ === "Command"
203+
204+ ```bash
205+ $ cd /opt/mariadb
206+ $ ncdu
207+ ```
208+
209+ === "Result"
210+
211+ ```sql
212+ --- /opt/mariadb/dtable_db --------------------------
213+ 1.7 GiB [###########] operation_log.ibd
214+ 72.0 MiB [ ] django_session.ibd
215+ 60.0 MiB [ ] delete_operation_log.ibd
216+ 23.0 MiB [ ] activities.ibd
217+ 596.0 KiB [ ] dtable_external_apps.ibd
218+ ```
219+
220+ ### Analyze Operation Log
221+
222+ To find bases with the most operations:
223+
224+ === "Command"
225+
226+ ```sql
227+ SELECT dtable_uuid, COUNT(*) AS entry_count
228+ FROM operation_log
229+ GROUP BY dtable_uuid;
230+ ```
231+
232+ === "Result"
233+
234+ ```sql
235+ +----------------------------------+-------------+
236+ | dtable_uuid | entry_count |
237+ +----------------------------------+-------------+
238+ | 0114790c116d46fd8b9f2f9331fab623 | 2 |
239+ | 014a4d23b28147f180f790ae8146c053 | 37 |
240+ | 01bee901b3dc43df8df0ee58c0ab53a6 | 3312 |
241+ | 038a126c86c14b55896ceff03237e72a | 1 |
242+ | 04e403d181e14c41b9026d7f2d9b648b | 324 |
243+ | 0558d382ef804d5d9eb4e682a3eaa99d | 41 |
244+ ...
245+ ```
246+
247+ ### Identify Active Users (for a specific base)
248+
249+ For a specific base like ` 01bee901b3dc43df8df0ee58c0ab53a6 ` :
250+
251+ === "Command"
252+
253+ ```sql
254+ SELECT author, COUNT(*) AS entry_count
255+ FROM operation_log
256+ WHERE dtable_uuid = '01bee901b3dc43df8df0ee58c0ab53a6'
257+ GROUP BY author
258+ ORDER BY entry_count DESC;
259+ ```
260+
261+ === "Result"
262+
263+ ```sql
264+ +---------------------------------------------+-------------+
265+ | author | entry_count |
266+ +---------------------------------------------+-------------+
267+ | | 2633 |
268+ 269+ 270+ | dtable-web | 32 |
271+ 272+ ```
273+
274+ ### Analyze Change Frequency
275+
276+ To view changes over time:
277+
278+ === "Command"
279+
280+ ```sql
281+ SELECT FROM_UNIXTIME(FLOOR(op_time / 3600000) * 3600) AS hour_interval,
282+ COUNT(*) AS entry_count
283+ FROM operation_log
284+ WHERE dtable_uuid = '01bee901b3dc43df8df0ee58c0ab53a6'
285+ GROUP BY hour_interval
286+ ORDER BY hour_interval;
287+ ```
288+
289+ === "Result"
290+
291+ ```sql
292+ +---------------------+-------------+
293+ | hour_interval | entry_count |
294+ +---------------------+-------------+
295+ | 2024-09-12 13:00:00 | 7 |
296+ | 2024-09-12 14:00:00 | 50 |
297+ | 2024-09-12 15:00:00 | 83 |
298+ | 2024-09-12 16:00:00 | 63 |
299+ | 2024-09-12 17:00:00 | 53 |
300+ ```
301+
302+ ### Remove Base Entries
303+
304+ To safely remove all entries for a specific base from operation_log:
305+
306+ === "Command"
307+
308+ ```sql
309+ DELETE FROM operation_log WHERE dtable_uuid = '01bee901b3dc43df8df0ee58c0ab53a6';
310+ ```
311+
312+ === "Result"
313+
314+ ```sql
315+ Query OK, 3312 rows affected (0.094 sec)
316+ ```
0 commit comments