Skip to content

Commit 22855b0

Browse files
committed
Improved "Choosing database" documentation page
1 parent 2cad7a6 commit 22855b0

File tree

1 file changed

+79
-23
lines changed

1 file changed

+79
-23
lines changed

docs/installation/choosing_database.md

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,96 @@ nav_order: 1
77

88
# Choosing database: SQLite or MySQL
99

10-
Part-DB saves its data in a [relational (SQL) database](https://en.wikipedia.org/wiki/Relational_database). Part-DB
11-
supports either the use of [SQLite](https://www.sqlite.org/index.html)
12-
or [MySQL](https://www.mysql.com/) / [MariaDB](https://mariadb.org/) (which are mostly the same, except for some minor
13-
differences).
10+
Part-DB saves its data in a [relational (SQL) database](https://en.wikipedia.org/wiki/Relational_database).
11+
12+
For this multiple database types are supported, currently these are:
13+
14+
* [SQLite](https://www.sqlite.org/index.html)
15+
* [MySQL](https://www.mysql.com/) / [MariaDB](https://mariadb.org/) (which are mostly the same, except for some minor
16+
differences)
17+
* [PostgreSQL](https://www.postgresql.org/)
18+
19+
All these database types allow for the same basic functionality and allow Part-DB to run. However, there are some minor
20+
differences between them, which might be important for you. Therefore the pros and cons of the different database types
21+
are listed here.
1422

1523
{: .important }
1624
You have to choose between the database types before you start using Part-DB and **you can not change it (easily) after
1725
you have started creating data**. So you should choose the database type for your use case (and possible future uses).
1826

1927
## Comparison
2028

21-
**SQLite** is the default database type which is configured out of the box. All data is saved in a single file (
22-
normally `var/app.db` in the Part-DB folder) and no additional installation or configuration besides Part-DB is needed.
23-
To use **MySQL/MariaDB** as database, you have to install and configure the MySQL server, configure it and create a
24-
database and user for Part-DB, which needs some additional work. When using docker you need an additional docker
25-
container, and volume for the data
29+
### SQLite
30+
31+
#### Pros
32+
33+
* **Easy to use**: No additional installation or configuration is needed, just start Part-DB and it will work out of the box
34+
* **Easy backup**: Just copy the SQLite file to a safe place, and you have a backup, which you can restore by copying it
35+
back. No need to work with SQL dumps
36+
37+
#### Cons
38+
39+
* **Performance**: SQLite is not as fast as MySQL or PostgreSQL, especially when using complex queries or many users.
40+
* **Emulated RegEx search**: SQLite does not support RegEx search natively. Part-DB can emulate it, however that is pretty slow.
41+
* **Emualted natural sorting**: SQLite does not support natural sorting natively. Part-DB can emulate it, but it is pretty slow.
42+
* **Limitations with Unicode**: SQLite has limitations in comparisons and sorting of Unicode characters, which might lead to
43+
unexpected behavior when using non-ASCII characters in your data. For example `µ` (micro sign) is not seen as equal to
44+
`μ` (greek minuscule mu), therefore searching for `µ` (micro sign) will not find parts containing `μ` (mu) and vice versa.
45+
The other databases behave more intuitive in this case.
46+
* **No advanced features**: SQLite do no support many of the advanced features of MySQL or PostgreSQL, which might be utilized
47+
in future versions of Part-DB
48+
49+
50+
### MySQL/MariaDB
51+
52+
**If possible, it is recommended to use MariaDB 10.7+ (instead of MySQL), as it supports natural sorting of columns natively.**
53+
54+
#### Pros
55+
56+
* **Performance**: Compared to SQLite, MySQL/MariaDB will probably perform better, especially in large databases with many
57+
users and high activity.
58+
* **Natural Sorting**: MariaDB 10.7+ supports natural sorting of columns. On other databases it has to be emulated, which is pretty
59+
slow.
60+
* **Native RegEx search**: MySQL supports RegEx search natively, which is faster than emulating it in PHP.
61+
* **Advanced features**: MySQL/MariaDB supports many advanced features, which might be utilized in future versions of Part-DB.
62+
* **Full Unicode support**: MySQL/MariaDB has better support for Unicode characters, which makes it more intuitive to use
63+
non-ASCII characters in your data.
64+
65+
#### Cons
66+
67+
* **Additional installation and configuration**: You have to install and configure the MySQL server, create a database and
68+
user for Part-DB, which needs some additional work compared to SQLite.
69+
* **Backup**: The MySQL database has to be dumped to a SQL file (using `mysqldump`). The `console partdb:backup` command can automate this.
70+
71+
72+
### PostgreSQL
2673

27-
When using **SQLite** The database can be backuped easily by just copying the SQLite file to a safe place. Ideally, the *
28-
*MySQL** database has to be dumped to a SQL file (using `mysqldump`). The `console partdb:backup` command can do this
29-
automatically
74+
#### Pros
75+
* **Performance**: PostgreSQL is known for its performance, especially in large databases with many users and high activity.
76+
* **Advanced features**: PostgreSQL supports many advanced features, which might be utilized in future versions of Part-DB.
77+
* **Full Unicode support**: PostgreSQL has better support for Unicode characters, which makes it more intuitive to use
78+
non-ASCII characters in your data.
79+
* **Native RegEx search**: PostgreSQL supports RegEx search natively, which is faster than emulating it in PHP.
80+
* **Native Natural Sorting**: PostgreSQL supports natural sorting of columns natively in all versions and in general the support for it
81+
is better than on MariaDB.
82+
* **Support of transactional DDL**: PostgreSQL supports transactional DDL, which means that if you encounter a problem during a schema change,
83+
the database will automatically rollback the changes. On MySQL/MariaDB you have to manually rollback the changes, by restoring from a database backup.
3084

31-
However, SQLite does not support certain operations like regex search, which has to be emulated by PHP and therefore is
32-
pretty slow compared to the same operation at MySQL. In the future, there might be features that may only be available, when
33-
using MySQL. Also, SQLite has limitations in comparisons and sorting of Unicode characters, which might lead to unexpected
34-
behavior when using non-ASCII characters in your data. For example `µ` (micro sign) is not seen as equal to `μ(greek minuscule mu),
35-
therefore searching for `µ` (micro sign) will not find parts containing `μ` (mu) and vice versa. In MySQL identical-looking characters are seen as equal, which is more intuitive in most cases.
85+
#### Cons
86+
* **New backend**: The support of postgresql is new, and it was not tested as much as the other backends. There might be some bugs caused by this.
87+
* **Additional installation and configuration**: You have to install and configure the PostgreSQL server, create a database and
88+
user for Part-DB, which needs some additional work compared to SQLite.
89+
* **Backup**: The PostgreSQL database has to be dumped to a SQL file (using `pg_dump`). The `console partdb:backup` command can automate this.
3690

37-
In general MySQL might perform better for big Part-DB instances with many entries, lots of users and high activity, than
38-
SQLite.
3991

40-
## Conclusion and Suggestion
92+
## Recommendation
4193

4294
When you are a hobbyist and use Part-DB for your own small inventory management with only you as user (or maybe sometimes
43-
a few other people), then the easy-to-use SQLite database will be fine.
95+
a few other people), then the easy-to-use SQLite database will be fine, as long as you can live with the limitations, stated above.
96+
However using MariaDB (or PostgreSQL), has no disadvantages in that situation (besides the initial setup requirements), so you might
97+
want to use it, to be prepared for future use cases.
4498

45-
When you are planning to have a very big database, with a lot of entries and many users which regularly (and
46-
concurrently) using Part-DB you should maybe use MySQL as this will scale better.
99+
When you are planning to have a very big database, with a lot of entries and many users which regularly using Part-DB, then you should
100+
use MariaDB or PostgreSQL, as they will perform better in that situation and allow for more advanced features.
101+
If you should use MariaDB or PostgreSQL depends on your personal preference and what you already have installed on your servers and
102+
what you are familiar with.

0 commit comments

Comments
 (0)