postgres.txt 4.4 KB

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