Update PostgreSQL supported version in docs/database/postgres.txt
[lhc/web/wiklou.git] / docs / databases / postgres.txt
1 This document describes the state of Postgres support in MediaWiki.
2
3 == Overview ==
4
5 Support for PostgreSQL has been available since version 1.7
6 of MediaWiki, and is fairly well maintained. The main code
7 is very well integrated, while extensions are very hit and miss.
8 Still, it is probably the most supported database after MySQL.
9 Much of the work in making MediaWiki database-agnostic came
10 about through the work of creating Postgres support.
11
12 == Required versions ==
13
14 The current minimum version of PostgreSQL for MediaWiki is 9.2
15
16 == Database schema ==
17
18 Postgres has its own schema file at maintenance/postgres/tables.sql.
19
20 The goal is to keep this file as close as possible to the canonical
21 schema at maintenance/tables.sql, but without copying over
22 all the usage comments. General notes on the conversion:
23
24 * The use of a true TIMESTAMP rather than the text string that
25 MySQL uses is highly encouraged. There are still places in the
26 code (especially extensions) which make assumptions about the
27 textual nature of timestamp fields, but these can almost always
28 be programmed around.
29
30 * Although Postgres has a true BOOLEAN type, boolean columns
31 are always mapped to SMALLINT, as the code does not always treat
32 the column as a boolean (which is limited to accepting true,
33 false, 0, 1, t, or f)
34
35 * The default data type for all VARCHAR, CHAR, and VARBINARY
36 columns should simply be TEXT. The only exception is
37 when VARBINARY is used to store true binary data, such as
38 the math_inputhash column, in which case BYTEA should be used.
39
40 * All integer variants should generally be mapped to INTEGER.
41 There is small-to-no advantage in using SMALLINT versus
42 INTEGER in Postgres, and the possibility of running out of
43 room outweighs such concerns. The columns that are BIGINT
44 in other schemas should be INTEGER as well, as none of them
45 so far are even remotely likely to reach the 32 billion
46 limit of an INTEGER.
47
48 * Blobs (blob, tinyblog, mediumblob) should be mapped to TEXT
49 whenever possible, and to BYTEA if they are known to contain
50 binary data.
51
52 * All length modifiers on data types should be removed. If
53 they are on an INTEGER, it's probably an error, and if on
54 any text-based field, simply using TEXT is preferred.
55
56 * Sequences should be explicitly named rather than using
57 SERIAL, as the code can depend on having a specific name.
58
59 * Foreign keys should be used when possible. This makes things
60 both easier and harder in the code, but most of the major
61 problems have now been overcome. Always add an explicit ON DELETE
62 clause, and consider carefully what choice to use (all things
63 considered, prefer CASCADE).
64
65 * The use of CIDR should be done very carefully, because the code
66 will sometimes want to store things such as an empty string or
67 other non-IP value in the column. When in doubt, use TEXT.
68
69 * Indexes should be created using the original MySQL tables.sql
70 as a guide, but keeping in mind the ability of Postgres to use
71 partial indexes, functional indexes, and bitmaps. The index names
72 should be logical but are not too important, as they are never
73 referenced directly by the code (unlike sequence names). Most of
74 the indexes in the file as of this writing are there due to production
75 testing of expensive queries on a busy wiki.
76
77 == Keeping in sync with tables.sql ==
78
79 The script maintenance/postgres/compare_schemas.pl should be
80 periodically run. It will parse both "tables.sql" files and
81 produce any differences found. Such differences should be fixed
82 or exceptions specifically carved out by editing the script
83 itself. This script has also been very useful in finding problems
84 in maintenance/tables.sql itself, as it is very strict in the
85 format it expects things to be in. :)
86
87 == MySQL differences ==
88
89 The major differences between MySQL and Postgres are represented as
90 methods in the Database class. For example, implicitGroupby() is
91 true for MySQL and false for Postgres. This means that in those
92 places where the code does not add all the non-aggregate items
93 from the SELECT clause to the GROUP BY, we can add them in, but in
94 a conditional manner with the above method, as simply adding them
95 all in to the main query may cause performance problems with
96 MySQL.
97
98 == Getting help ==
99
100 In addition to the normal venues (MediaWiki mailing lists
101 and IRC channels), the #postgresql channel on irc.freenode.net
102 is a friendly and expert resource if you should encounter a
103 problem with your Postgres-enabled MediaWiki.