1<!-- doc/src/sgml/docguide.sgml -->
2
3<appendix id="docguide">
4 <title>Documentation</title>
5
6 <para>
7  <productname>PostgreSQL</productname> has four primary documentation
8  formats:
9
10  <itemizedlist>
11   <listitem>
12    <para>
13     Plain text, for pre-installation information
14    </para>
15   </listitem>
16   <listitem>
17    <para>
18     <acronym>HTML</acronym>, for on-line browsing and reference
19    </para>
20   </listitem>
21   <listitem>
22    <para>
23     PDF, for printing
24    </para>
25   </listitem>
26   <listitem>
27    <para>
28     man pages, for quick reference.
29    </para>
30   </listitem>
31  </itemizedlist>
32
33  Additionally, a number of plain-text <filename>README</filename> files can
34  be found throughout the <productname>PostgreSQL</productname> source tree,
35  documenting various implementation issues.
36 </para>
37
38 <para>
39  <acronym>HTML</acronym> documentation and man pages are part of a
40  standard distribution and are installed by default.  PDF
41  format documentation is available separately for
42  download.
43 </para>
44
45 <sect1 id="docguide-docbook">
46  <title>DocBook</title>
47  <para>
48   The documentation sources are written in
49   <firstterm>DocBook</firstterm>, which is a markup language
50   defined in <acronym>XML</acronym>.  In what
51   follows, the terms DocBook and <acronym>XML</acronym> are both
52   used, but technically they are not interchangeable.
53  </para>
54
55  <para>
56  <productname>DocBook</productname> allows an author to specify the
57   structure and content of a technical document without worrying
58   about presentation details.  A document style defines how that
59   content is rendered into one of several final forms.  DocBook is
60   maintained by the <ulink url="https://www.oasis-open.org">
61   OASIS group</ulink>.  The <ulink url="https://www.oasis-open.org/docbook/">
62   official DocBook site</ulink> has good introductory and reference documentation and
63   a complete O'Reilly book for your online reading pleasure.  The
64   <ulink url="http://newbiedoc.sourceforge.net/metadoc/docbook-guide.html">
65   NewbieDoc Docbook Guide</ulink> is very helpful for beginners.
66   The <ulink url="https://www.freebsd.org/docproj/docproj.html">
67   FreeBSD Documentation Project</ulink> also uses DocBook and has some good
68   information, including a number of style guidelines that might be
69   worth considering.
70  </para>
71 </sect1>
72
73
74 <sect1 id="docguide-toolsets">
75  <title>Tool Sets</title>
76
77  <para>
78   The following tools are used to process the documentation.  Some
79   might be optional, as noted.
80
81   <variablelist>
82    <varlistentry>
83     <term><ulink url="https://www.oasis-open.org/docbook/">DocBook DTD</ulink></term>
84     <listitem>
85      <para>
86       This is the definition of DocBook itself.  We currently use version
87       4.2; you cannot use later or earlier versions.  You need
88       the <acronym>XML</acronym> variant of the DocBook DTD, not
89       the <acronym>SGML</acronym> variant.
90      </para>
91     </listitem>
92    </varlistentry>
93
94    <varlistentry>
95     <term><ulink url="https://github.com/docbook/wiki/wiki/DocBookXslStylesheets">DocBook XSL Stylesheets</ulink></term>
96     <listitem>
97      <para>
98       These contain the processing instructions for converting the
99       DocBook sources to other formats, such as
100       <acronym>HTML</acronym>.
101      </para>
102
103      <para>
104       The minimum required version is currently 1.77.0, but it is recommended
105       to use the latest available version for best results.
106      </para>
107     </listitem>
108    </varlistentry>
109
110    <varlistentry>
111     <term><ulink url="http://xmlsoft.org/">Libxml2</ulink> for <command>xmllint</command></term>
112     <listitem>
113      <para>
114       This library and the <command>xmllint</command> tool it contains are
115       used for processing XML.  Many developers will already
116       have <application>Libxml2</application> installed, because it is also
117       used when building the PostgreSQL code.  Note, however,
118       that <command>xmllint</command> might need to be installed from a
119       separate subpackage.
120      </para>
121     </listitem>
122     </varlistentry>
123
124    <varlistentry>
125     <term><ulink url="http://xmlsoft.org/XSLT/">Libxslt</ulink> for <command>xsltproc</command></term>
126     <listitem>
127      <para>
128       <command>xsltproc</command> is an XSLT processor, that is, a program to
129       convert XML to other formats using XSLT stylesheets.
130      </para>
131     </listitem>
132    </varlistentry>
133
134    <varlistentry>
135     <term><ulink url="https://xmlgraphics.apache.org/fop/">FOP</ulink></term>
136     <listitem>
137      <para>
138       This is a program for converting, among other things, XML to PDF.
139      </para>
140     </listitem>
141    </varlistentry>
142   </variablelist>
143  </para>
144
145  <para>
146   We have documented experience with several installation methods for
147   the various tools that are needed to process the documentation.
148   These will be described below.  There might be some other packaged
149   distributions for these tools. Please report package status to the
150   documentation mailing list, and we will include that information
151   here.
152  </para>
153
154  <para>
155   You can get away with not installing DocBook XML and the DocBook XSLT
156   stylesheets locally, because the required files will be downloaded from the
157   Internet and cached locally.  This may in fact be the preferred solution if
158   your operating system packages provide only an old version of these files,
159   or if no packages are available at all.
160   If you want to prevent any attempt to access the Internet while building
161   the documentation, you need to pass the <option>--nonet</option> option
162   to <command>xmllint</command> and <command>xsltproc</command>; see below
163   for an example.
164  </para>
165
166  <sect2>
167   <title>Installation on Fedora, RHEL, and Derivatives</title>
168
169   <para>
170    To install the required packages, use:
171<programlisting>
172yum install docbook-dtds docbook-style-xsl fop libxslt
173</programlisting>
174   </para>
175  </sect2>
176
177  <sect2>
178   <title>Installation on FreeBSD</title>
179
180   <para>
181    To install the required packages with <command>pkg</command>, use:
182<programlisting>
183pkg install docbook-xml docbook-xsl fop libxslt
184</programlisting>
185   </para>
186
187   <para>
188    When building the documentation from the <filename>doc</filename>
189    directory you'll need to use <command>gmake</command>, because the
190    makefile provided is not suitable for FreeBSD's <command>make</command>.
191   </para>
192  </sect2>
193
194  <sect2>
195   <title>Debian Packages</title>
196
197   <para>
198    There is a full set of packages of the documentation tools
199    available for <productname>Debian GNU/Linux</productname>.
200    To install, simply use:
201<programlisting>
202apt-get install docbook-xml docbook-xsl fop libxml2-utils xsltproc
203</programlisting>
204   </para>
205  </sect2>
206
207  <sect2>
208   <title>macOS</title>
209
210   <para>
211    On macOS, you can build the HTML and man documentation without installing
212    anything extra.  If you want to build PDFs or want to install a local copy
213    of DocBook, you can get those from your preferred package manager.
214   </para>
215
216   <para>
217    If you use MacPorts, the following will get you set up:
218<programlisting>
219sudo port install docbook-xml-4.2 docbook-xsl fop
220</programlisting>
221    If you use Homebrew, use this:
222<programlisting>
223brew install docbook docbook-xsl fop
224</programlisting>
225   </para>
226  </sect2>
227
228  <sect2 id="docguide-toolsets-configure">
229   <title>Detection by <command>configure</command></title>
230
231  <para>
232   Before you can build the documentation you need to run the
233   <filename>configure</filename> script, as you would when building
234   the <productname>PostgreSQL</productname> programs themselves.
235   Check the output near the end of the run; it should look something
236   like this:
237<screen>
238checking for xmllint... xmllint
239checking for xsltproc... xsltproc
240checking for fop... fop
241checking for dbtoepub... dbtoepub
242</screen>
243   If <filename>xmllint</filename> or <filename>xsltproc</filename> is not
244   found, you will not be able to build any of the documentation.
245   <filename>fop</filename> is only needed to build the documentation in
246   PDF format.
247   <filename>dbtoepub</filename> is only needed to build the documentation
248   in EPUB format.
249  </para>
250
251  <para>
252   If necessary, you can tell <filename>configure</filename> where to find
253   these programs, for example
254<screen>
255./configure ... XMLLINT=/opt/local/bin/xmllint ...
256</screen>
257   Also, if you want to ensure that <filename>xmllint</filename>
258   and <filename>xsltproc</filename> will not perform any network access,
259   you can do something like
260<screen>
261./configure ... XMLLINT="xmllint --nonet" XSLTPROC="xsltproc --nonet" ...
262</screen>
263  </para>
264  </sect2>
265 </sect1>
266
267 <sect1 id="docguide-build">
268  <title>Building the Documentation</title>
269
270  <para>
271   Once you have everything set up, change to the directory
272   <filename>doc/src/sgml</filename> and run one of the commands
273   described in the following subsections to build the
274   documentation. (Remember to use GNU make.)
275  </para>
276
277  <sect2>
278   <title>HTML</title>
279
280   <para>
281    To build the <acronym>HTML</acronym> version of the documentation:
282<screen>
283<prompt>doc/src/sgml$ </prompt><userinput>make html</userinput>
284</screen>
285    This is also the default target.  The output appears in the
286    subdirectory <filename>html</filename>.
287   </para>
288
289   <para>
290    To produce HTML documentation with the stylesheet used on <ulink
291    url="https://www.postgresql.org/docs/current/">postgresql.org</ulink> instead of the
292    default simple style use:
293<screen>
294<prompt>doc/src/sgml$ </prompt><userinput>make STYLE=website html</userinput>
295</screen>
296   </para>
297 </sect2>
298
299 <sect2>
300  <title>Manpages</title>
301
302  <para>
303   We use the DocBook XSL stylesheets to
304   convert <productname>DocBook</productname>
305   <sgmltag>refentry</sgmltag> pages to *roff output suitable for man
306   pages.  To create the man pages, use the command:
307<screen>
308<prompt>doc/src/sgml$ </prompt><userinput>make man</userinput>
309</screen>
310  </para>
311 </sect2>
312
313  <sect2>
314   <title>PDF</title>
315
316   <para>
317    To produce a PDF rendition of the documentation
318    using <productname>FOP</productname>, you can use one of the following
319    commands, depending on the preferred paper format:
320
321    <itemizedlist>
322     <listitem>
323      <para>
324       For A4 format:
325<screen>
326<prompt>doc/src/sgml$ </prompt><userinput>make postgres-A4.pdf</userinput>
327</screen>
328      </para>
329     </listitem>
330
331     <listitem>
332      <para>
333       For U.S. letter format:
334<screen>
335<prompt>doc/src/sgml$ </prompt><userinput>make postgres-US.pdf</userinput>
336</screen>
337      </para>
338     </listitem>
339    </itemizedlist>
340   </para>
341
342   <para>
343    Because the PostgreSQL documentation is fairly
344    big, <productname>FOP</productname> will require a significant amount of
345    memory.  Because of that, on some systems, the build will fail with a
346    memory-related error message.  This can usually be fixed by configuring
347    Java heap settings in the configuration
348    file <filename>~/.foprc</filename>, for example:
349<programlisting>
350# FOP binary distribution
351FOP_OPTS='-Xmx1500m'
352# Debian
353JAVA_ARGS='-Xmx1500m'
354# Red Hat
355ADDITIONAL_FLAGS='-Xmx1500m'
356</programlisting>
357    There is a minimum amount of memory that is required, and to some extent
358    more memory appears to make things a bit faster.  On systems with very
359    little memory (less than 1 GB), the build will either be very slow due to
360    swapping or will not work at all.
361   </para>
362
363   <para>
364    Other XSL-FO processors can also be used manually, but the automated build
365    process only supports FOP.
366   </para>
367  </sect2>
368
369  <sect2>
370   <title>Plain Text Files</title>
371
372   <para>
373    The installation instructions are also distributed as plain text,
374    in case they are needed in a situation where better reading tools
375    are not available.  The <filename>INSTALL</filename> file
376    corresponds to <xref linkend="installation"/>, with some minor
377    changes to account for the different context.  To recreate the
378    file, change to the directory <filename>doc/src/sgml</filename>
379    and enter <userinput>make INSTALL</userinput>.  Building text output
380    requires <productname>Pandoc</productname> version 1.13 or newer as an
381    additional build tool.
382   </para>
383
384   <para>
385    In the past, the release notes and regression testing instructions
386    were also distributed as plain text, but this practice has been
387    discontinued.
388   </para>
389  </sect2>
390
391  <sect2>
392   <title>Syntax Check</title>
393
394   <para>
395    Building the documentation can take very long.  But there is a
396    method to just check the correct syntax of the documentation
397    files, which only takes a few seconds:
398<screen>
399<prompt>doc/src/sgml$ </prompt><userinput>make check</userinput>
400</screen>
401   </para>
402  </sect2>
403 </sect1>
404
405
406 <sect1 id="docguide-authoring">
407  <title>Documentation Authoring</title>
408
409   <para>
410    The documentation sources are most conveniently modified with an editor
411    that has a mode for editing XML, and even more so if it has some awareness
412    of XML schema languages so that it can know about
413    <productname>DocBook</productname> syntax specifically.
414   </para>
415
416   <para>
417    Note that for historical reasons the documentation source files are named
418    with an extension <filename>.sgml</filename> even though they are now XML
419    files.  So you might need to adjust your editor configuration to set the
420    correct mode.
421   </para>
422
423   <sect2>
424    <title>Emacs</title>
425
426    <para>
427     <productname>nXML Mode</productname>, which ships with
428     <productname>Emacs</productname>, is the most common mode for editing
429     <acronym>XML</acronym> documents with <productname>Emacs</productname>.
430     It will allow you to use <application>Emacs</application> to insert tags
431     and check markup consistency, and it supports
432     <productname>DocBook</productname> out of the box.  Check the <ulink
433     url="https://www.gnu.org/software/emacs/manual/html_mono/nxml-mode.html">
434     nXML manual</ulink> for detailed documentation.
435    </para>
436
437    <para>
438     <filename>src/tools/editors/emacs.samples</filename> contains
439     recommended settings for this mode.
440    </para>
441   </sect2>
442
443 </sect1>
444
445
446 <sect1 id="docguide-style">
447  <title>Style Guide</title>
448
449  <sect2>
450   <title>Reference Pages</title>
451
452   <para>
453    Reference pages should follow a standard layout.  This allows
454    users to find the desired information more quickly, and it also
455    encourages writers to document all relevant aspects of a command.
456    Consistency is not only desired among
457    <productname>PostgreSQL</productname> reference pages, but also
458    with reference pages provided by the operating system and other
459    packages.  Hence the following guidelines have been developed.
460    They are for the most part consistent with similar guidelines
461    established by various operating systems.
462   </para>
463
464   <para>
465    Reference pages that describe executable commands should contain
466    the following sections, in this order.  Sections that do not apply
467    can be omitted.  Additional top-level sections should only be used
468    in special circumstances; often that information belongs in the
469    <quote>Usage</quote> section.
470
471    <variablelist>
472     <varlistentry>
473      <term>Name</term>
474      <listitem>
475       <para>
476        This section is generated automatically.  It contains the
477        command name and a half-sentence summary of its functionality.
478       </para>
479      </listitem>
480     </varlistentry>
481
482     <varlistentry>
483      <term>Synopsis</term>
484      <listitem>
485       <para>
486        This section contains the syntax diagram of the command.  The
487        synopsis should normally not list each command-line option;
488        that is done below.  Instead, list the major components of the
489        command line, such as where input and output files go.
490       </para>
491      </listitem>
492     </varlistentry>
493
494     <varlistentry>
495      <term>Description</term>
496      <listitem>
497       <para>
498        Several paragraphs explaining what the command does.
499       </para>
500      </listitem>
501     </varlistentry>
502
503     <varlistentry>
504      <term>Options</term>
505      <listitem>
506       <para>
507        A list describing each command-line option.  If there are a
508        lot of options, subsections can be used.
509       </para>
510      </listitem>
511     </varlistentry>
512
513     <varlistentry>
514      <term>Exit Status</term>
515      <listitem>
516       <para>
517        If the program uses 0 for success and non-zero for failure,
518        then you do not need to document it.  If there is a meaning
519        behind the different non-zero exit codes, list them here.
520       </para>
521      </listitem>
522     </varlistentry>
523
524     <varlistentry>
525      <term>Usage</term>
526      <listitem>
527       <para>
528        Describe any sublanguage or run-time interface of the program.
529        If the program is not interactive, this section can usually be
530        omitted.  Otherwise, this section is a catch-all for
531        describing run-time features.  Use subsections if appropriate.
532       </para>
533      </listitem>
534     </varlistentry>
535
536     <varlistentry>
537      <term>Environment</term>
538      <listitem>
539       <para>
540        List all environment variables that the program might use.
541        Try to be complete; even seemingly trivial variables like
542        <envar>SHELL</envar> might be of interest to the user.
543       </para>
544      </listitem>
545     </varlistentry>
546
547     <varlistentry>
548      <term>Files</term>
549      <listitem>
550       <para>
551        List any files that the program might access implicitly.  That
552        is, do not list input and output files that were specified on
553        the command line, but list configuration files, etc.
554       </para>
555      </listitem>
556     </varlistentry>
557
558     <varlistentry>
559      <term>Diagnostics</term>
560      <listitem>
561       <para>
562        Explain any unusual output that the program might create.
563        Refrain from listing every possible error message.  This is a
564        lot of work and has little use in practice.  But if, say, the
565        error messages have a standard format that the user can parse,
566        this would be the place to explain it.
567       </para>
568      </listitem>
569     </varlistentry>
570
571     <varlistentry>
572      <term>Notes</term>
573      <listitem>
574       <para>
575        Anything that doesn't fit elsewhere, but in particular bugs,
576        implementation flaws, security considerations, compatibility
577        issues.
578       </para>
579      </listitem>
580     </varlistentry>
581
582     <varlistentry>
583      <term>Examples</term>
584      <listitem>
585       <para>
586        Examples
587       </para>
588      </listitem>
589     </varlistentry>
590
591     <varlistentry>
592      <term>History</term>
593      <listitem>
594       <para>
595        If there were some major milestones in the history of the
596        program, they might be listed here.  Usually, this section can
597        be omitted.
598       </para>
599      </listitem>
600     </varlistentry>
601
602     <varlistentry>
603      <term>Author</term>
604      <listitem>
605       <para>
606        Author (only used in the contrib section)
607       </para>
608      </listitem>
609     </varlistentry>
610
611     <varlistentry>
612      <term>See Also</term>
613      <listitem>
614       <para>
615        Cross-references, listed in the following order: other
616        <productname>PostgreSQL</productname> command reference pages,
617        <productname>PostgreSQL</productname> SQL command reference
618        pages, citation of <productname>PostgreSQL</productname>
619        manuals, other reference pages (e.g., operating system, other
620        packages), other documentation.  Items in the same group are
621        listed alphabetically.
622       </para>
623      </listitem>
624     </varlistentry>
625
626    </variablelist>
627   </para>
628
629   <para>
630    Reference pages describing SQL commands should contain the
631    following sections: Name, Synopsis, Description, Parameters,
632    Outputs, Notes, Examples, Compatibility, History, See
633    Also.  The Parameters section is like the Options section, but
634    there is more freedom about which clauses of the command can be
635    listed.  The Outputs section is only needed if the command returns
636    something other than a default command-completion tag.  The Compatibility
637    section should explain to what extent
638    this command conforms to the SQL standard(s), or to which other
639    database system it is compatible.  The See Also section of SQL
640    commands should list SQL commands before cross-references to
641    programs.
642   </para>
643  </sect2>
644
645 </sect1>
646</appendix>
647