about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/databases/postgresql.xml
blob: 72d4a8249a321c936ac766bc4109e4e9a3c7e095 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<chapter xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         version="5.0"
         xml:id="module-postgresql">
 <title>PostgreSQL</title>
<!-- FIXME: render nicely -->
<!-- FIXME: source can be added automatically -->
 <para>
  <emphasis>Source:</emphasis>
  <filename>modules/services/databases/postgresql.nix</filename>
 </para>
 <para>
  <emphasis>Upstream documentation:</emphasis>
  <link xlink:href="http://www.postgresql.org/docs/"/>
 </para>
<!-- FIXME: more stuff, like maintainer? -->
 <para>
  PostgreSQL is an advanced, free relational database.
<!-- MORE -->
 </para>
 <section xml:id="module-services-postgres-configuring">
  <title>Configuring</title>

  <para>
   To enable PostgreSQL, add the following to your
   <filename>configuration.nix</filename>:
<programlisting>
<xref linkend="opt-services.postgresql.enable"/> = true;
<xref linkend="opt-services.postgresql.package"/> = pkgs.postgresql_11;
</programlisting>
   Note that you are required to specify the desired version of PostgreSQL
   (e.g. <literal>pkgs.postgresql_11</literal>). Since upgrading your
   PostgreSQL version requires a database dump and reload (see below), NixOS
   cannot provide a default value for
   <xref linkend="opt-services.postgresql.package"/> such as the most recent
   release of PostgreSQL.
  </para>

<!--
<para>After running <command>nixos-rebuild</command>, you can verify
whether PostgreSQL works by running <command>psql</command>:

<screen>
<prompt>$ </prompt>psql
psql (9.2.9)
Type "help" for help.

<prompt>alice=></prompt>
</screen>
-->

  <para>
   By default, PostgreSQL stores its databases in
   <filename>/var/lib/postgresql/$psqlSchema</filename>. You can override this using
   <xref linkend="opt-services.postgresql.dataDir"/>, e.g.
<programlisting>
<xref linkend="opt-services.postgresql.dataDir"/> = "/data/postgresql";
</programlisting>
  </para>
 </section>
 <section xml:id="module-services-postgres-upgrading">
  <title>Upgrading</title>

  <para>
   FIXME: document dump/upgrade/load cycle.
  </para>
 </section>
 <section xml:id="module-services-postgres-options">
  <title>Options</title>

  <para>
   A complete list of options for the PostgreSQL module may be found
   <link linkend="opt-services.postgresql.enable">here</link>.
  </para>
 </section>
 <section xml:id="module-services-postgres-plugins">
  <title>Plugins</title>

  <para>
   Plugins collection for each PostgreSQL version can be accessed with
   <literal>.pkgs</literal>. For example, for
   <literal>pkgs.postgresql_11</literal> package, its plugin collection is
   accessed by <literal>pkgs.postgresql_11.pkgs</literal>:
<screen>
<prompt>$ </prompt>nix repl '&lt;nixpkgs&gt;'

Loading '&lt;nixpkgs&gt;'...
Added 10574 variables.

<prompt>nix-repl&gt; </prompt>postgresql_11.pkgs.&lt;TAB&gt;&lt;TAB&gt;
postgresql_11.pkgs.cstore_fdw        postgresql_11.pkgs.pg_repack
postgresql_11.pkgs.pg_auto_failover  postgresql_11.pkgs.pg_safeupdate
postgresql_11.pkgs.pg_bigm           postgresql_11.pkgs.pg_similarity
postgresql_11.pkgs.pg_cron           postgresql_11.pkgs.pg_topn
postgresql_11.pkgs.pg_hll            postgresql_11.pkgs.pgjwt
postgresql_11.pkgs.pg_partman        postgresql_11.pkgs.pgroonga
...
</screen>
  </para>
  <para>
    To add plugins via NixOS configuration, set <literal>services.postgresql.extraPlugins</literal>:
<programlisting>
<xref linkend="opt-services.postgresql.package"/> = pkgs.postgresql_11;
<xref linkend="opt-services.postgresql.extraPlugins"/> = with pkgs.postgresql_11.pkgs; [
  pg_repack
  postgis
];
</programlisting>
  </para>
  <para>
   You can build custom PostgreSQL-with-plugins (to be used outside of NixOS) using
   function <literal>.withPackages</literal>. For example, creating a custom
   PostgreSQL package in an overlay can look like:
<programlisting>
self: super: {
  postgresql_custom = self.postgresql_11.withPackages (ps: [
    ps.pg_repack
    ps.postgis
  ]);
}
</programlisting>
  </para>
  <para>
    Here's a recipe on how to override a particular plugin through an overlay:
<programlisting>
self: super: {
  postgresql_11 = super.postgresql_11.override { this = self.postgresql_11; } // {
    pkgs = super.postgresql_11.pkgs // {
      pg_repack = super.postgresql_11.pkgs.pg_repack.overrideAttrs (_: {
        name = "pg_repack-v20181024";
        src = self.fetchzip {
          url = "https://github.com/reorg/pg_repack/archive/923fa2f3c709a506e111cc963034bf2fd127aa00.tar.gz";
          sha256 = "17k6hq9xaax87yz79j773qyigm4fwk8z4zh5cyp6z0sxnwfqxxw5";
        };
      });
    };
  };
}
</programlisting>
  </para>
 </section>
</chapter>