2 17.4. Building and Installation with Meson #
5 17.4.2. Installation Procedure
6 17.4.3. meson setup Options
7 17.4.4. meson Build Targets
9 17.4.1. Short Version #
11 meson setup build --prefix=/usr/local/pgsql
17 mkdir -p /usr/local/pgsql/data
18 chown postgres /usr/local/pgsql/data
20 /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
21 /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
22 /usr/local/pgsql/bin/createdb test
23 /usr/local/pgsql/bin/psql test
25 The long version is the rest of this section.
27 17.4.2. Installation Procedure #
30 The first step of the installation procedure is to configure the
31 build tree for your system and choose the options you would like.
32 To create and configure the build directory, you can start with the
36 The setup command takes a builddir and a srcdir argument. If no
37 srcdir is given, Meson will deduce the srcdir based on the current
38 directory and the location of meson.build. The builddir is
40 Running meson setup loads the build configuration file and sets up
41 the build directory. Additionally, you can also pass several build
42 options to Meson. Some commonly used options are mentioned in the
43 subsequent sections. For example:
44 # configure with a different installation prefix
45 meson setup build --prefix=/home/user/pg-install
47 # configure to generate a debug build
48 meson setup build --buildtype=debug
50 # configure to build with OpenSSL support
51 meson setup build -Dssl=openssl
53 Setting up the build directory is a one-time step. To reconfigure
54 before a new build, you can simply use the meson configure command
55 meson configure -Dcassert=true
57 meson configure's commonly used command-line options are explained
60 By default, Meson uses the Ninja build tool. To build PostgreSQL
61 from source using Meson, you can simply use the ninja command in
65 Ninja will automatically detect the number of CPUs in your computer
66 and parallelize itself accordingly. You can override the number of
67 parallel processes used with the command line argument -j.
68 It should be noted that after the initial configure step, ninja is
69 the only command you ever need to type to compile. No matter how
70 you alter your source tree (short of moving it to a completely new
71 location), Meson will detect the changes and regenerate itself
72 accordingly. This is especially handy if you have multiple build
73 directories. Often one of them is used for development (the "debug"
74 build) and others only every now and then (such as a "static
75 analysis" build). Any configuration can be built just by cd'ing to
76 the corresponding directory and running Ninja.
77 If you'd like to build with a backend other than ninja, you can use
78 configure with the --backend option to select the one you want to
79 use and then build using meson compile. To learn more about these
80 backends and other arguments you can provide to ninja, you can
81 refer to the Meson documentation.
83 If you want to test the newly built server before you install it,
84 you can run the regression tests at this point. The regression
85 tests are a test suite to verify that PostgreSQL runs on your
86 machine in the way the developers expected it to. Type:
89 (This won't work as root; do it as an unprivileged user.) See
90 Chapter 31 for detailed information about interpreting the test
91 results. You can repeat this test at any later time by issuing the
93 To run pg_regress and pg_isolation_regress tests against a running
94 postgres instance, specify --setup running as an argument to meson
96 4. Installing the Files
99 If you are upgrading an existing system be sure to read
100 Section 18.6, which has instructions about upgrading a cluster.
101 Once PostgreSQL is built, you can install it by simply running the
102 ninja install command.
105 This will install files into the directories that were specified in
106 Step 1. Make sure that you have appropriate permissions to write
107 into that area. You might need to do this step as root.
108 Alternatively, you can create the target directories in advance and
109 arrange for appropriate permissions to be granted. The standard
110 installation provides all the header files needed for client
111 application development as well as for server-side program
112 development, such as custom functions or data types written in C.
113 ninja install should work for most cases, but if you'd like to use
114 more options (such as --quiet to suppress extra output), you could
115 also use meson install instead. You can learn more about meson
116 install and its options in the Meson documentation.
118 Uninstallation: To undo the installation, you can use the ninja
121 Cleaning: After the installation, you can free disk space by removing
122 the built files from the source tree with the ninja clean command.
124 17.4.3. meson setup Options #
126 meson setup's command-line options are explained below. This list is
127 not exhaustive (use meson configure --help to get one that is). The
128 options not covered here are meant for advanced use-cases, and are
129 documented in the standard Meson documentation. These arguments can be
130 used with meson setup as well.
132 17.4.3.1. Installation Locations #
134 These options control where ninja install (or meson install) will put
135 the files. The --prefix option (example Section 17.4.1) is sufficient
136 for most cases. If you have special needs, you can customize the
137 installation subdirectories with the other options described in this
138 section. Beware however that changing the relative locations of the
139 different subdirectories may render the installation non-relocatable,
140 meaning you won't be able to move it after installation. (The man and
141 doc locations are not affected by this restriction.) For relocatable
142 installs, you might want to use the -Drpath=false option described
146 Install all files under the directory PREFIX instead of
147 /usr/local/pgsql (on Unix based systems) or current drive
148 letter:/usr/local/pgsql (on Windows). The actual files will be
149 installed into various subdirectories; no files will ever be
150 installed directly into the PREFIX directory.
153 Specifies the directory for executable programs. The default is
156 --sysconfdir=DIRECTORY #
157 Sets the directory for various configuration files, PREFIX/etc
161 Sets the location to install libraries and dynamically loadable
162 modules. The default is PREFIX/lib.
164 --includedir=DIRECTORY #
165 Sets the directory for installing C and C++ header files. The
166 default is PREFIX/include.
168 --datadir=DIRECTORY #
169 Sets the directory for read-only data files used by the
170 installed programs. The default is PREFIX/share. Note that this
171 has nothing to do with where your database files will be placed.
173 --localedir=DIRECTORY #
174 Sets the directory for installing locale data, in particular
175 message translation catalog files. The default is
179 The man pages that come with PostgreSQL will be installed under
180 this directory, in their respective manx subdirectories. The
181 default is DATADIR/man.
185 Care has been taken to make it possible to install PostgreSQL into
186 shared installation locations (such as /usr/local/include) without
187 interfering with the namespace of the rest of the system. First, the
188 string “/postgresql” is automatically appended to datadir, sysconfdir,
189 and docdir, unless the fully expanded directory name already contains
190 the string “postgres” or “pgsql”. For example, if you choose /usr/local
191 as prefix, the documentation will be installed in
192 /usr/local/doc/postgresql, but if the prefix is /opt/postgres, then it
193 will be in /opt/postgres/doc. The public C header files of the client
194 interfaces are installed into includedir and are namespace-clean. The
195 internal header files and the server header files are installed into
196 private directories under includedir. See the documentation of each
197 interface for information about how to access its header files.
198 Finally, a private subdirectory will also be created, if appropriate,
199 under libdir for dynamically loadable modules.
201 17.4.3.2. PostgreSQL Features #
203 The options described in this section enable building of various
204 optional PostgreSQL features. Most of these require additional
205 software, as described in Section 17.1, and will be automatically
206 enabled if the required software is found. You can change this behavior
207 by manually setting these features to enabled to require them or
208 disabled to not build with them.
210 To specify PostgreSQL-specific options, the name of the option must be
213 -Dnls={ auto | enabled | disabled } #
214 Enables or disables Native Language Support (NLS), that is, the
215 ability to display a program's messages in a language other than
216 English. Defaults to auto and will be enabled automatically if
217 an implementation of the Gettext API is found.
219 -Dplperl={ auto | enabled | disabled } #
220 Build the PL/Perl server-side language. Defaults to auto.
222 -Dplpython={ auto | enabled | disabled } #
223 Build the PL/Python server-side language. Defaults to auto.
225 -Dpltcl={ auto | enabled | disabled } #
226 Build the PL/Tcl server-side language. Defaults to auto.
228 -Dtcl_version=TCL_VERSION #
229 Specifies the Tcl version to use when building PL/Tcl.
231 -Dicu={ auto | enabled | disabled } #
232 Build with support for the ICU library, enabling use of ICU
233 collation features (see Section 23.2). Defaults to auto and
234 requires the ICU4C package to be installed. The minimum required
235 version of ICU4C is currently 4.2.
237 -Dllvm={ auto | enabled | disabled } #
238 Build with support for LLVM based JIT compilation (see
239 Chapter 30). This requires the LLVM library to be installed. The
240 minimum required version of LLVM is currently 14. Disabled by
243 llvm-config will be used to find the required compilation
244 options. llvm-config, and then llvm-config-$version for all
245 supported versions, will be searched for in your PATH. If that
246 would not yield the desired program, use LLVM_CONFIG to specify
247 a path to the correct llvm-config.
249 -Dlz4={ auto | enabled | disabled } #
250 Build with LZ4 compression support. Defaults to auto.
252 -Dzstd={ auto | enabled | disabled } #
253 Build with Zstandard compression support. Defaults to auto.
255 -Dssl={ auto | LIBRARY } #
256 Build with support for SSL (encrypted) connections. The only
257 LIBRARY supported is openssl. This requires the OpenSSL package
258 to be installed. Building with this will check for the required
259 header files and libraries to make sure that your OpenSSL
260 installation is sufficient before proceeding. The default for
263 -Dgssapi={ auto | enabled | disabled } #
264 Build with support for GSSAPI authentication. MIT Kerberos is
265 required to be installed for GSSAPI. On many systems, the GSSAPI
266 system (a part of the MIT Kerberos installation) is not
267 installed in a location that is searched by default (e.g.,
268 /usr/include, /usr/lib). In those cases, PostgreSQL will query
269 pkg-config to detect the required compiler and linker options.
270 Defaults to auto. meson configure will check for the required
271 header files and libraries to make sure that your GSSAPI
272 installation is sufficient before proceeding.
274 -Dldap={ auto | enabled | disabled } #
275 Build with LDAP support for authentication and connection
276 parameter lookup (see Section 32.18 and Section 20.10 for more
277 information). On Unix, this requires the OpenLDAP package to be
278 installed. On Windows, the default WinLDAP library is used.
279 Defaults to auto. meson configure will check for the required
280 header files and libraries to make sure that your OpenLDAP
281 installation is sufficient before proceeding.
283 -Dpam={ auto | enabled | disabled } #
284 Build with PAM (Pluggable Authentication Modules) support.
287 -Dbsd_auth={ auto | enabled | disabled } #
288 Build with BSD Authentication support. (The BSD Authentication
289 framework is currently only available on OpenBSD.) Defaults to
292 -Dsystemd={ auto | enabled | disabled } #
293 Build with support for systemd service notifications. This
294 improves integration if the server is started under systemd but
295 has no impact otherwise; see Section 18.3 for more information.
296 Defaults to auto. libsystemd and the associated header files
297 need to be installed to use this option.
299 -Dbonjour={ auto | enabled | disabled } #
300 Build with support for Bonjour automatic service discovery.
301 Defaults to auto and requires Bonjour support in your operating
302 system. Recommended on macOS.
305 Build the uuid-ossp module (which provides functions to generate
306 UUIDs), using the specified UUID library. LIBRARY must be one
309 + none to not build the uuid module. This is the default.
310 + bsd to use the UUID functions found in FreeBSD, and some other
312 + e2fs to use the UUID library created by the e2fsprogs project;
313 this library is present in most Linux systems and in macOS,
314 and can be obtained for other platforms as well
315 + ossp to use the OSSP UUID library
317 -Dlibcurl={ auto | enabled | disabled } #
318 Build with libcurl support for OAuth 2.0 client flows. Libcurl
319 version 7.61.0 or later is required for this feature. Building
320 with this will check for the required header files and libraries
321 to make sure that your Curl installation is sufficient before
322 proceeding. The default for this option is auto.
324 -Dliburing={ auto | enabled | disabled } #
325 Build with liburing, enabling io_uring support for asynchronous
326 I/O. Defaults to auto.
328 To use a liburing installation that is in an unusual location,
329 you can set pkg-config-related environment variables (see its
332 -Dlibnuma={ auto | enabled | disabled } #
333 Build with libnuma support for basic NUMA support. Only
334 supported on platforms for which the libnuma library is
335 implemented. The default for this option is auto.
337 -Dlibxml={ auto | enabled | disabled } #
338 Build with libxml2, enabling SQL/XML support. Defaults to auto.
339 Libxml2 version 2.6.23 or later is required for this feature.
341 To use a libxml2 installation that is in an unusual location,
342 you can set pkg-config-related environment variables (see its
345 -Dlibxslt={ auto | enabled | disabled } #
346 Build with libxslt, enabling the xml2 module to perform XSL
347 transformations of XML. -Dlibxml must be specified as well.
350 -Dselinux={ auto | enabled | disabled } #
351 Build with SElinux support, enabling the sepgsql extension.
354 17.4.3.3. Anti-Features #
356 -Dreadline={ auto | enabled | disabled } #
357 Allows use of the Readline library (and libedit as well). This
358 option defaults to auto and enables command-line editing and
359 history in psql and is strongly recommended.
361 -Dlibedit_preferred={ true | false } #
362 Setting this to true favors the use of the BSD-licensed libedit
363 library rather than GPL-licensed Readline. This option is
364 significant only if you have both libraries installed; the
365 default is false, that is to use Readline.
367 -Dzlib={ auto | enabled | disabled } #
368 Enables use of the Zlib library. It defaults to auto and enables
369 support for compressed archives in pg_dump, pg_restore and
370 pg_basebackup and is recommended.
372 17.4.3.4. Build Process Details #
374 --auto-features={ auto | enabled | disabled } #
375 Setting this option allows you to override the value of all
376 “auto” features (features that are enabled automatically if the
377 required software is found). This can be useful when you want to
378 disable or enable all the “optional” features at once without
379 having to set each of them manually. The default value for this
383 The default backend Meson uses is ninja and that should suffice
384 for most use cases. However, if you'd like to fully integrate
385 with Visual Studio, you can set the BACKEND to vs.
388 This option can be used to pass extra options to the C compiler.
390 -Dc_link_args=OPTIONS #
391 This option can be used to pass extra options to the C linker.
393 -Dextra_include_dirs=DIRECTORIES #
394 DIRECTORIES is a comma-separated list of directories that will
395 be added to the list the compiler searches for header files. If
396 you have optional packages (such as GNU Readline) installed in a
397 non-standard location, you have to use this option and probably
398 also the corresponding -Dextra_lib_dirs option.
400 Example: -Dextra_include_dirs=/opt/gnu/include,/usr/sup/include.
402 -Dextra_lib_dirs=DIRECTORIES #
403 DIRECTORIES is a comma-separated list of directories to search
404 for libraries. You will probably have to use this option (and
405 the corresponding -Dextra_include_dirs option) if you have
406 packages installed in non-standard locations.
408 Example: -Dextra_lib_dirs=/opt/gnu/lib,/usr/sup/lib.
410 -Dsystem_tzdata=DIRECTORY #
411 PostgreSQL includes its own time zone database, which it
412 requires for date and time operations. This time zone database
413 is in fact compatible with the IANA time zone database provided
414 by many operating systems such as FreeBSD, Linux, and Solaris,
415 so it would be redundant to install it again. When this option
416 is used, the system-supplied time zone database in DIRECTORY is
417 used instead of the one included in the PostgreSQL source
418 distribution. DIRECTORY must be specified as an absolute path.
419 /usr/share/zoneinfo is a likely directory on some operating
420 systems. Note that the installation routine will not detect
421 mismatching or erroneous time zone data. If you use this option,
422 you are advised to run the regression tests to verify that the
423 time zone data you have pointed to works correctly with
426 This option is mainly aimed at binary package distributors who
427 know their target operating system well. The main advantage of
428 using this option is that the PostgreSQL package won't need to
429 be upgraded whenever any of the many local daylight-saving time
430 rules change. Another advantage is that PostgreSQL can be
431 cross-compiled more straightforwardly if the time zone database
432 files do not need to be built during the installation.
434 -Dextra_version=STRING #
435 Append STRING to the PostgreSQL version number. You can use
436 this, for example, to mark binaries built from unreleased Git
437 snapshots or containing custom patches with an extra version
438 string, such as a git describe identifier or a distribution
439 package release number.
441 -Drpath={ true | false } #
442 This option is set to true by default. If set to false, do not
443 mark PostgreSQL's executables to indicate that they should
444 search for shared libraries in the installation's library
445 directory (see --libdir). On most platforms, this marking uses
446 an absolute path to the library directory, so that it will be
447 unhelpful if you relocate the installation later. However, you
448 will then need to provide some other way for the executables to
449 find the shared libraries. Typically this requires configuring
450 the operating system's dynamic linker to search the library
451 directory; see Section 17.5.1 for more detail.
454 If a program required to build PostgreSQL (with or without
455 optional flags) is stored at a non-standard path, you can
456 specify it manually to meson configure. The complete list of
457 programs for which this is supported can be found by running
458 meson configure. Example:
460 meson configure -DBISON=PATH_TO_BISON
462 17.4.3.5. Documentation #
464 See Section J.2 for the tools needed for building the documentation.
466 -Ddocs={ auto | enabled | disabled } #
467 Enables building the documentation in HTML and man format. It
470 -Ddocs_pdf={ auto | enabled | disabled } #
471 Enables building the documentation in PDF format. It defaults to
474 -Ddocs_html_style={ simple | website } #
475 Controls which CSS stylesheet is used. The default is simple. If
476 set to website, the HTML documentation will reference the
477 stylesheet for postgresql.org.
479 17.4.3.6. Miscellaneous #
482 Set NUMBER as the default port number for server and clients.
483 The default is 5432. The port can always be changed later on,
484 but if you specify it here then both server and clients will
485 have the same default compiled in, which can be very convenient.
486 Usually the only good reason to select a non-default value is if
487 you intend to run multiple PostgreSQL servers on the same
491 The default name of the Kerberos service principal used by
492 GSSAPI. postgres is the default. There's usually no reason to
493 change this unless you are building for a Windows environment,
494 in which case it must be set to upper case POSTGRES.
497 Set the segment size, in gigabytes. Large tables are divided
498 into multiple operating-system files, each of size equal to the
499 segment size. This avoids problems with file size limits that
500 exist on many platforms. The default segment size, 1 gigabyte,
501 is safe on all supported platforms. If your operating system has
502 “largefile” support (which most do, nowadays), you can use a
503 larger segment size. This can be helpful to reduce the number of
504 file descriptors consumed when working with very large tables.
505 But be careful not to select a value larger than is supported by
506 your platform and the file systems you intend to use. Other
507 tools you might wish to use, such as tar, could also set limits
508 on the usable file size. It is recommended, though not
509 absolutely required, that this value be a power of 2.
511 -Dblocksize=BLOCKSIZE #
512 Set the block size, in kilobytes. This is the unit of storage
513 and I/O within tables. The default, 8 kilobytes, is suitable for
514 most situations; but other values may be useful in special
515 cases. The value must be a power of 2 between 1 and 32
518 -Dwal_blocksize=BLOCKSIZE #
519 Set the WAL block size, in kilobytes. This is the unit of
520 storage and I/O within the WAL log. The default, 8 kilobytes, is
521 suitable for most situations; but other values may be useful in
522 special cases. The value must be a power of 2 between 1 and 64
525 17.4.3.7. Developer Options #
527 Most of the options in this section are only of interest for developing
528 or debugging PostgreSQL. They are not recommended for production
529 builds, except for --debug, which can be useful to enable detailed bug
530 reports in the unlucky event that you encounter a bug. On platforms
531 supporting DTrace, -Ddtrace may also be reasonable to use in
534 When building an installation that will be used to develop code inside
535 the server, it is recommended to use at least the --buildtype=debug and
538 --buildtype=BUILDTYPE #
539 This option can be used to specify the buildtype to use;
540 defaults to debugoptimized. If you'd like finer control on the
541 debug symbols and optimization levels than what this option
542 provides, you can refer to the --debug and --optimization flags.
544 The following build types are generally used: plain, debug,
545 debugoptimized and release. More information about them can be
546 found in the Meson documentation.
549 Compiles all programs and libraries with debugging symbols. This
550 means that you can run the programs in a debugger to analyze
551 problems. This enlarges the size of the installed executables
552 considerably, and on non-GCC compilers it usually also disables
553 compiler optimization, causing slowdowns. However, having the
554 symbols available is extremely helpful for dealing with any
555 problems that might arise. Currently, this option is recommended
556 for production installations only if you use GCC. But you should
557 always have it on if you are doing development work or running a
560 --optimization=LEVEL #
561 Specify the optimization level. LEVEL can be set to any of
565 Setting this option asks the compiler to treat warnings as
566 errors. This can be useful for code development.
568 -Dcassert={ true | false } #
569 Enables assertion checks in the server, which test for many
570 “cannot happen” conditions. This is invaluable for code
571 development purposes, but the tests slow down the server
572 significantly. Also, having the tests turned on won't
573 necessarily enhance the stability of your server! The assertion
574 checks are not categorized for severity, and so what might be a
575 relatively harmless bug will still lead to server restarts if it
576 triggers an assertion failure. This option is not recommended
577 for production use, but you should have it on for development
578 work or when running a beta version.
580 -Dtap_tests={ auto | enabled | disabled } #
581 Enable tests using the Perl TAP tools. Defaults to auto and
582 requires a Perl installation and the Perl module IPC::Run. See
583 Section 31.4 for more information.
585 -DPG_TEST_EXTRA=TEST_SUITES #
586 Enable additional test suites, which are not run by default
587 because they are not secure to run on a multiuser system,
588 require special software to run, or are resource intensive. The
589 argument is a whitespace-separated list of tests to enable. See
590 Section 31.1.3 for details. If the PG_TEST_EXTRA environment
591 variable is set when the tests are run, it overrides this
594 -Db_coverage={ true | false } #
595 If using GCC, all programs and libraries are compiled with code
596 coverage testing instrumentation. When run, they generate files
597 in the build directory with code coverage metrics. See
598 Section 31.5 for more information. This option is for use only
599 with GCC and when doing development work.
601 -Ddtrace={ auto | enabled | disabled } #
602 Enabling this compiles PostgreSQL with support for the dynamic
603 tracing tool DTrace. See Section 27.5 for more information.
605 To point to the dtrace program, the DTRACE option can be set.
606 This will often be necessary because dtrace is typically
607 installed under /usr/sbin, which might not be in your PATH.
609 -Dinjection_points={ true | false } #
610 Compiles PostgreSQL with support for injection points in the
611 server. Injection points allow to run user-defined code from
612 within the server in pre-defined code paths. This helps in
613 testing and in the investigation of concurrency scenarios in a
614 controlled fashion. This option is disabled by default. See
615 Section 36.10.14 for more details. This option is intended to be
616 used only by developers for testing.
618 -Dsegsize_blocks=SEGSIZE_BLOCKS #
619 Specify the relation segment size in blocks. If both -Dsegsize
620 and this option are specified, this option wins. This option is
621 only for developers, to test segment related code.
623 17.4.4. meson Build Targets #
625 Individual build targets can be built using ninja target. When no
626 target is specified, everything except documentation is built.
627 Individual build products can be built using the path/filename as
630 17.4.4.1. Code Targets #
633 Build everything other than documentation
636 Build backend and related modules
639 Build frontend binaries
642 Build contrib modules
645 Build procedural languages
647 17.4.4.2. Developer Targets #
650 Rewrite catalog data files into standard format
653 Expand all data files to include defaults
656 Update unicode data to new version
658 17.4.4.3. Documentation Targets #
661 Build documentation in multi-page HTML format
664 Build documentation in man page format
667 Build documentation in multi-page HTML and man page format
669 doc/src/sgml/postgres-A4.pdf #
670 Build documentation in PDF format, with A4 pages
672 doc/src/sgml/postgres-US.pdf #
673 Build documentation in PDF format, with US letter pages
675 doc/src/sgml/postgres.html #
676 Build documentation in single-page HTML format
679 Build documentation in all supported formats
681 17.4.4.4. Installation Targets #
684 Install postgres, excluding documentation
687 Install documentation in multi-page HTML and man page formats
690 Install documentation in multi-page HTML format
693 Install documentation in man page format
696 Like "install", but installed files are not displayed
699 Install postgres, including multi-page HTML and man page
703 Remove installed files
705 17.4.4.5. Other Targets #
708 Remove all build products
711 Run all enabled tests (including contrib)
714 Build everything, including documentation
717 List important targets