Postgresql 中文操作指南

17.4. Building and Installation with Meson #

17.4.1. Short Version #

meson setup build --prefix=/usr/local/pgsql
cd build
ninja
su
ninja install
adduser postgres
mkdir -p /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test

长版本是本节的其余部分。

The long version is the rest of this section.

17.4.2. Installation Procedure #

Note

如果您正在升级现有系统,请务必阅读 Section 19.6,其中包含有关升级集群的说明。

If you are upgrading an existing system be sure to read Section 19.6, which has instructions about upgrading a cluster.

*Uninstallation: * 要撤销安装,您可以使用 ninja uninstall 命令。

*Uninstallation: * To undo the installation, you can use the ninja uninstall command.

*Cleaning: * 安装之后,您可以通过使用 ninja clean 命令从源树中移除构建文件来释放磁盘空间。

*Cleaning: * After the installation, you can free disk space by removing the built files from the source tree with the ninja clean command.

17.4.3. meson setup Options #

meson setup 的命令行选项如下所述。此列表并非详尽(使用 meson configure --help 获取詳尽列表)。此处未介绍的选项用于高级用例,并在标准 Meson documentation 中进行记录。这些参数也可以与 meson setup 一起使用。

meson setup's command-line options are explained below. This list is not exhaustive (use meson configure --help to get one that is). The options not covered here are meant for advanced use-cases, and are documented in the standard Meson documentation. These arguments can be used with meson setup as well.

17.4.3.1. Installation Locations #

这些选项控制了 ninja install (或 meson install)将把文件放在何处。—​prefix 选项(例如 Section 17.4.1)对于大多数情况来说已经足够。如果你有特殊需求,你可以使用本节中描述的其他选项自定义安装子目录。但请注意,更改不同子目录的相对位置可能会使安装不可重定位,这意味着你无法在安装后移动它。(mandoc 位置不受此限制影响。)对于可重定位安装,你可能需要使用稍后描述的 -Drpath=false 选项。

These options control where ninja install (or meson install) will put the files. The —​prefix option (example Section 17.4.1) is sufficient for most cases. If you have special needs, you can customize the installation subdirectories with the other options described in this section. Beware however that changing the relative locations of the different subdirectories may render the installation non-relocatable, meaning you won’t be able to move it after installation. (The man and doc locations are not affected by this restriction.) For relocatable installs, you might want to use the -Drpath=false option described later.

  • —​prefix=_PREFIX_ #

    • Install all files under the directory PREFIX instead of /usr/local/pgsql (on Unix based systems) or _current drive letter:/usr/local/pgsql_ (on Windows). The actual files will be installed into various subdirectories; no files will ever be installed directly into the PREFIX directory.

  • —​bindir=_DIRECTORY_ #

    • Specifies the directory for executable programs. The default is _PREFIX/bin_.

  • —​sysconfdir=_DIRECTORY_ #

    • Sets the directory for various configuration files, _PREFIX/etc_ by default.

  • —​libdir=_DIRECTORY_ #

    • Sets the location to install libraries and dynamically loadable modules. The default is _PREFIX/lib_.

  • —​includedir=_DIRECTORY_ #

    • Sets the directory for installing C and C++ header files. The default is _PREFIX/include_.

  • —​datadir=_DIRECTORY_ #

    • Sets the directory for read-only data files used by the installed programs. The default is _PREFIX/share_. Note that this has nothing to do with where your database files will be placed.

  • —​localedir=_DIRECTORY_ #

    • Sets the directory for installing locale data, in particular message translation catalog files. The default is _DATADIR/locale_.

  • —​mandir=_DIRECTORY_ #

    • The man pages that come with PostgreSQL will be installed under this directory, in their respective man_x subdirectories. The default is DATADIR/man_.

Note

我们煞费苦心,才使得 PostgreSQL 能够安装在共享安装位置(例如 /usr/local/include)中,而不会干扰系统中其他部分的名称空间。首先,字符串“/postgresql”将自动追加到 datadirsysconfdirdocdir,除非展开的完整目录名中已经包含字符串“postgres”或“pgsql”。例如,如果你选择 /usr/local 作为前缀,则文档将安装到 /usr/local/doc/postgresql 中,但如果前缀是 /opt/postgres,则该文档将位于 /opt/postgres/doc 中。客户端接口的公用 C 头文件将被安装到 includedir 中,并且是名称空间清除的。内部头文件和服务器头文件则安装到 includedir 下的私有目录中。请参阅各个接口的文档,以了解有关如何访问其头文件的信息。最后,在适当的情况下,还将在 libdir 下创建一个私有子目录,用于可动态加载的模块。

Care has been taken to make it possible to install PostgreSQL into shared installation locations (such as /usr/local/include) without interfering with the namespace of the rest of the system. First, the string “/postgresql” is automatically appended to datadir, sysconfdir, and docdir, unless the fully expanded directory name already contains the string “postgres” or “pgsql”. For example, if you choose /usr/local as prefix, the documentation will be installed in /usr/local/doc/postgresql, but if the prefix is /opt/postgres, then it will be in /opt/postgres/doc. The public C header files of the client interfaces are installed into includedir and are namespace-clean. The internal header files and the server header files are installed into private directories under includedir. See the documentation of each interface for information about how to access its header files. Finally, a private subdirectory will also be created, if appropriate, under libdir for dynamically loadable modules.

17.4.3.2. PostgreSQL Features #

本节中描述的选项可用于构建各种可选 PostgreSQL 功能。其中大多数需要其他软件,如 Section 17.1 中所述,并且如果找到所需的软件,它们将自动启用。你可以通过手动将这些功能设置为 enabled 以要求它们或设置为 disabled 以不使用它们来更改此行为。

The options described in this section enable building of various optional PostgreSQL features. Most of these require additional software, as described in Section 17.1, and will be automatically enabled if the required software is found. You can change this behavior by manually setting these features to enabled to require them or disabled to not build with them.

要指定 PostgreSQL 特定选项,选项的名称必须冠以 -D

To specify PostgreSQL-specific options, the name of the option must be prefixed by -D.

  • -Dnls={ auto | enabled | disabled } #

    • Enables or disables Native Language Support (NLS), that is, the ability to display a program’s messages in a language other than English. Defaults to auto and will be enabled automatically if an implementation of the Gettext API is found.

  • -Dplperl={ auto | enabled | disabled } #

    • Build the PL/Perl server-side language. Defaults to auto.

  • -Dplpython={ auto | enabled | disabled } #

    • Build the PL/Python server-side language. Defaults to auto.

  • -Dpltcl={ auto | enabled | disabled } #

    • Build the PL/Tcl server-side language. Defaults to auto.

  • -Dtcl_version=_TCL_VERSION_ #

    • Specifies the Tcl version to use when building PL/Tcl.

  • -Dicu={ auto | enabled | disabled } #

    • Build with support for the ICU library, enabling use of ICU collation features (see Section 24.2). Defaults to auto and requires the ICU4C package to be installed. The minimum required version of ICU4C is currently 4.2.

  • -Dllvm={ auto | enabled | disabled } #

    • Build with support for LLVM based JIT compilation (see Chapter 32). This requires the LLVM library to be installed. The minimum required version of LLVM is currently 3.9. Disabled by default.

    • llvm-config will be used to find the required compilation options. llvm-config, and then llvm-config-$version for all supported versions, will be searched for in your PATH. If that would not yield the desired program, use LLVM_CONFIG to specify a path to the correct llvm-config.

  • -Dlz4={ auto | enabled | disabled } #

    • Build with LZ4 compression support. Defaults to auto.

  • -Dzstd={ auto | enabled | disabled } #

    • Build with Zstandard compression support. Defaults to auto.

  • -Dssl={ auto | _LIBRARY }_ #

    • Build with support for SSL (encrypted) connections. The only LIBRARY supported is openssl. This requires the OpenSSL package to be installed. Building with this will check for the required header files and libraries to make sure that your OpenSSL installation is sufficient before proceeding. The default for this option is auto.

  • -Dgssapi={ auto | enabled | disabled } #

    • Build with support for GSSAPI authentication. MIT Kerberos is required to be installed for GSSAPI. On many systems, the GSSAPI system (a part of the MIT Kerberos installation) is not installed in a location that is searched by default (e.g., /usr/include, /usr/lib). In those cases, PostgreSQL will query pkg-config to detect the required compiler and linker options. Defaults to auto. meson configure will check for the required header files and libraries to make sure that your GSSAPI installation is sufficient before proceeding.

  • -Dldap={ auto | enabled | disabled } #

    • Build with LDAP support for authentication and connection parameter lookup (see Section 34.18 and Section 21.10 for more information). On Unix, this requires the OpenLDAP package to be installed. On Windows, the default WinLDAP library is used. Defaults to auto. meson configure will check for the required header files and libraries to make sure that your OpenLDAP installation is sufficient before proceeding.

  • -Dpam={ auto | enabled | disabled } #

    • Build with PAM (Pluggable Authentication Modules) support. Defaults to auto.

  • -Dbsd_auth={ auto | enabled | disabled } #

    • Build with BSD Authentication support. (The BSD Authentication framework is currently only available on OpenBSD.) Defaults to auto.

  • -Dsystemd={ auto | enabled | disabled } #

    • Build with support for systemd service notifications. This improves integration if the server is started under systemd but has no impact otherwise; see Section 19.3 for more information. Defaults to auto. libsystemd and the associated header files need to be installed to use this option.

  • -Dbonjour={ auto | enabled | disabled } #

    • Build with support for Bonjour automatic service discovery. Defaults to auto and requires Bonjour support in your operating system. Recommended on macOS.

  • -Duuid=_LIBRARY_ #

    • Build the uuid-ossp module (which provides functions to generate UUIDs), using the specified UUID library. LIBRARY must be one of:

  • -Dlibxml={ auto | enabled | disabled } #

    • Build with libxml2, enabling SQL/XML support. Defaults to auto. Libxml2 version 2.6.23 or later is required for this feature.

    • To use a libxml2 installation that is in an unusual location, you can set pkg-config-related environment variables (see its documentation).

  • -Dlibxslt={ auto | enabled | disabled } #

    • Build with libxslt, enabling the xml2 module to perform XSL transformations of XML. -Dlibxml must be specified as well. Defaults to auto.

17.4.3.3. Anti-Features #

  • -Dreadline={ auto | enabled | disabled } #

    • Allows use of the Readline library (and libedit as well). This option defaults to auto and enables command-line editing and history in psql and is strongly recommended.

  • -Dlibedit_preferred={ true | false } #

    • Setting this to true favors the use of the BSD-licensed libedit library rather than GPL-licensed Readline. This option is significant only if you have both libraries installed; the default is false, that is to use Readline.

  • -Dzlib={ auto | enabled | disabled } #

    • Enables use of the Zlib library. It defaults to auto and enables support for compressed archives in pg_dump, pg_restore and pg_basebackup and is recommended.

  • -Dspinlocks={ true | false } #

    • This option is set to true by default; setting it to false will allow the build to succeed even if PostgreSQL has no CPU spinlock support for the platform. The lack of spinlock support will result in very poor performance; therefore, this option should only be changed if the build aborts and informs you that the platform lacks spinlock support. If setting this option to false is required to build PostgreSQL on your platform, please report the problem to the PostgreSQL developers.

  • -Datomics={ true | false } #

    • This option is set to true by default; setting it to false will disable use of CPU atomic operations. The option does nothing on platforms that lack such operations. On platforms that do have them, disabling atomics will result in poor performance. Changing this option is only useful for debugging or making performance comparisons.

17.4.3.4. Build Process Details #

  • —​auto_features={ auto | enabled | disabled } #

    • Setting this option allows you to override the value of all “auto” features (features that are enabled automatically if the required software is found). This can be useful when you want to disable or enable all the “optional” features at once without having to set each of them manually. The default value for this parameter is auto.

  • —​backend=_BACKEND_ #

    • The default backend Meson uses is ninja and that should suffice for most use cases. However, if you’d like to fully integrate with Visual Studio, you can set the BACKEND to vs.

  • -Dc_args=_OPTIONS_ #

    • This option can be used to pass extra options to the C compiler.

  • -Dc_link_args=_OPTIONS_ #

    • This option can be used to pass extra options to the C linker.

  • -Dextra_include_dirs=_DIRECTORIES_ #

    • DIRECTORIES is a comma-separated list of directories that will be added to the list the compiler searches for header files. If you have optional packages (such as GNU Readline) installed in a non-standard location, you have to use this option and probably also the corresponding -Dextra_lib_dirs option.

    • Example: -Dextra_include_dirs=/opt/gnu/include,/usr/sup/include.

  • -Dextra_lib_dirs=_DIRECTORIES_ #

    • DIRECTORIES is a comma-separated list of directories to search for libraries. You will probably have to use this option (and the corresponding -Dextra_include_dirs option) if you have packages installed in non-standard locations.

    • Example: -Dextra_lib_dirs=/opt/gnu/lib,/usr/sup/lib.

  • -Dsystem_tzdata=_DIRECTORY_ #

    • PostgreSQL includes its own time zone database, which it requires for date and time operations. This time zone database is in fact compatible with the IANA time zone database provided by many operating systems such as FreeBSD, Linux, and Solaris, so it would be redundant to install it again. When this option is used, the system-supplied time zone database in DIRECTORY is used instead of the one included in the PostgreSQL source distribution. DIRECTORY must be specified as an absolute path. /usr/share/zoneinfo is a likely directory on some operating systems. Note that the installation routine will not detect mismatching or erroneous time zone data. If you use this option, you are advised to run the regression tests to verify that the time zone data you have pointed to works correctly with PostgreSQL.

    • This option is mainly aimed at binary package distributors who know their target operating system well. The main advantage of using this option is that the PostgreSQL package won’t need to be upgraded whenever any of the many local daylight-saving time rules change. Another advantage is that PostgreSQL can be cross-compiled more straightforwardly if the time zone database files do not need to be built during the installation.

  • -Dextra_version=_STRING_ #

    • Append STRING to the PostgreSQL version number. You can use this, for example, to mark binaries built from unreleased Git snapshots or containing custom patches with an extra version string, such as a git describe identifier or a distribution package release number.

  • -Drpath={ true | false } #

    • This option is set to true by default. If set to false, do not mark PostgreSQL’s executables to indicate that they should search for shared libraries in the installation’s library directory (see —​libdir). On most platforms, this marking uses an absolute path to the library directory, so that it will be unhelpful if you relocate the installation later. However, you will then need to provide some other way for the executables to find the shared libraries. Typically this requires configuring the operating system’s dynamic linker to search the library directory; see Section 17.5.1 for more detail.

  • -D_BINARY_NAME=PATH_ #

    • If a program required to build PostgreSQL (with or without optional flags) is stored at a non-standard path, you can specify it manually to meson configure. The complete list of programs for which this is supported can be found by running meson configure. Example:

meson configure -DBISON=PATH_TO_BISON

17.4.3.5. Documentation #

请参阅 Section J.2 了解构建文档所需的工具。

See Section J.2 for the tools needed for building the documentation.

  • -Ddocs={ auto | enabled | disabled } #

    • Enables building the documentation in HTML and man format. It defaults to auto.

  • -Ddocs_pdf={ auto | enabled | disabled } #

    • Enables building the documentation in PDF format. It defaults to auto.

  • -Ddocs_html_style={ simple | website } #

    • Controls which CSS stylesheet is used. The default is simple. If set to website, the HTML documentation will reference the stylesheet for postgresql.org.

17.4.3.6. Miscellaneous #

  • -Dpgport=_NUMBER_ #

    • Set NUMBER as the default port number for server and clients. The default is 5432. The port can always be changed later on, but if you specify it here then both server and clients will have the same default compiled in, which can be very convenient. Usually the only good reason to select a non-default value is if you intend to run multiple PostgreSQL servers on the same machine.

  • -Dkrb_srvnam=_NAME_ #

    • The default name of the Kerberos service principal used by GSSAPI. postgres is the default. There’s usually no reason to change this unless you are building for a Windows environment, in which case it must be set to upper case POSTGRES.

  • -Dsegsize=_SEGSIZE_ #

    • Set the segment size, in gigabytes. Large tables are divided into multiple operating-system files, each of size equal to the segment size. This avoids problems with file size limits that exist on many platforms. The default segment size, 1 gigabyte, is safe on all supported platforms. If your operating system has “largefile” support (which most do, nowadays), you can use a larger segment size. This can be helpful to reduce the number of file descriptors consumed when working with very large tables. But be careful not to select a value larger than is supported by your platform and the file systems you intend to use. Other tools you might wish to use, such as tar, could also set limits on the usable file size. It is recommended, though not absolutely required, that this value be a power of 2.

  • -Dblocksize=_BLOCKSIZE_ #

    • Set the block size, in kilobytes. This is the unit of storage and I/O within tables. The default, 8 kilobytes, is suitable for most situations; but other values may be useful in special cases. The value must be a power of 2 between 1 and 32 (kilobytes).

  • -Dwal_blocksize=_BLOCKSIZE_ #

    • Set the WAL block size, in kilobytes. This is the unit of storage and I/O within the WAL log. The default, 8 kilobytes, is suitable for most situations; but other values may be useful in special cases. The value must be a power of 2 between 1 and 64 (kilobytes).

17.4.3.7. Developer Options #

本节中的大多数选项仅对开发或调试 PostgreSQL 有用。除了 —​debug,它们不建议用于生产构建,在不幸遇到 bug 时,—​debug 可以用于启用详细的 bug 报告。在支持 DTrace 的平台上,在生产中也可以合理使用 -Ddtrace

Most of the options in this section are only of interest for developing or debugging PostgreSQL. They are not recommended for production builds, except for —​debug, which can be useful to enable detailed bug reports in the unlucky event that you encounter a bug. On platforms supporting DTrace, -Ddtrace may also be reasonable to use in production.

在构建将用于开发服务器内代码的安装时,建议至少使用 —​buildtype=debug-Dcassert 选项。

When building an installation that will be used to develop code inside the server, it is recommended to use at least the —​buildtype=debug and -Dcassert options.

  • —​buildtype=_BUILDTYPE_ #

    • This option can be used to specify the buildtype to use; defaults to debugoptimized. If you’d like finer control on the debug symbols and optimization levels than what this option provides, you can refer to the —​debug and —​optimization flags.

    • The following build types are generally used: plain, debug, debugoptimized and release. More information about them can be found in the Meson documentation.

  • —​debug #

    • Compiles all programs and libraries with debugging symbols. This means that you can run the programs in a debugger to analyze problems. This enlarges the size of the installed executables considerably, and on non-GCC compilers it usually also disables compiler optimization, causing slowdowns. However, having the symbols available is extremely helpful for dealing with any problems that might arise. Currently, this option is recommended for production installations only if you use GCC. But you should always have it on if you are doing development work or running a beta version.

  • —​optimization=LEVEL #

    • Specify the optimization level. LEVEL can be set to any of {0,g,1,2,3,s}.

  • —​werror #

    • Setting this option asks the compiler to treat warnings as errors. This can be useful for code development.

  • -Dcassert={ true | false } #

    • Enables assertion checks in the server, which test for many “cannot happen” conditions. This is invaluable for code development purposes, but the tests slow down the server significantly. Also, having the tests turned on won’t necessarily enhance the stability of your server! The assertion checks are not categorized for severity, and so what might be a relatively harmless bug will still lead to server restarts if it triggers an assertion failure. This option is not recommended for production use, but you should have it on for development work or when running a beta version.

  • -Dtap_tests={ auto | enabled | disabled } #

    • Enable tests using the Perl TAP tools. Defaults to auto and requires a Perl installation and the Perl module IPC::Run. See Section 33.4 for more information.

  • -DPG_TEST_EXTRA=_TEST_SUITES_ #

    • Enable test suites which require special software to run. This option accepts arguments via a whitespace-separated list. See Section 33.1.3 for details.

  • -Db_coverage={ true | false } #

    • If using GCC, all programs and libraries are compiled with code coverage testing instrumentation. When run, they generate files in the build directory with code coverage metrics. See Section 33.5 for more information. This option is for use only with GCC and when doing development work.

  • -Ddtrace={ auto | enabled | disabled } #

    • Enabling this compiles PostgreSQL with support for the dynamic tracing tool DTrace. See Section 28.5 for more information.

    • To point to the dtrace program, the DTRACE option can be set. This will often be necessary because dtrace is typically installed under /usr/sbin, which might not be in your PATH.

  • -Dsegsize_blocks=SEGSIZE_BLOCKS #

    • Specify the relation segment size in blocks. If both -Dsegsize and this option are specified, this option wins. This option is only for developers, to test segment related code.