GreatSQL社区

搜索

reddey

postgres数据库的另类编译安装方法meson

reddey 已有 147 次阅读2025-6-6 10:17 |系统分类:运维实战


  昨天下午在看pgfans论坛的文章时,发现了波罗老师的一篇文章,里面讲到了一种不同以前PG编译安装的方法,以前编译安装通常是三板斧(configure&&make&&make install),不过新的编译安装方法适用PG17之后的数据库版本。波罗老师的文章链接如是:http://pgfans.cn/a/4006。我个人加入pgfans论坛不久,但在阅读波罗老师的文章时,发现大佬确实功力深厚,是我等学习的楷模。

1、编译安装PG数据库,我们先把各种依赖安装好。命令如下:

yum install -y git gcc make readline-devel zlib-devel perl-ExtUtils-Embed python3-devel openssl-devel  libxml2-devel libxslt-devel systemd-devel

yum install -y meson ninja-build

meso、 ninja-build这两个依赖安装时要注意,由于我个人使用的CENTOS 7系统,YUM源使用的阿里云源,没有meso、 ninja-build。我安装了epel源,才成功安装这两个依赖,命令如是:yum install -y epel-release。按照波罗老师的说法,使用meson安装,安装速度要比传统的安装要快些。

2、进入解压目录下,执行meson命令,创建build目录。

postgres@pg1 ~]$ cd postgresql-17.5/

[postgres@pg1 postgresql-17.5]$ meson setup build --prefix=/home/postgres/soft\

                -Dssl=openssl \

                 -Dlibxml=enabled \

                -Dsystemd=enabled

The Meson build system

Version: 0.55.1

Source dir: /home/postgres/postgresql-17.5

Build dir: /home/postgres/postgresql-17.5/build

Build type: native build

Project name: postgresql

Project version: 17.5

C compiler for the host machine: cc (gcc 4.8.5 "cc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)")

C linker for the host machine: cc ld.bfd 2.27-34

Host machine cpu family: x86_64

Host machine cpu: x86_64

Run-time dependency threads found: YES

Program perl found: YES

Program python3 found: YES

Program flex found: YES 2.5.37

Program bison found: YES 3.0.4

Program sed found: YES

Program prove found: YES

Program tar found: YES

Program gzip found: YES

Program lz4 found: YES

Program openssl found: YES

Program zstd found: NO

Program dtrace skipped: feature dtrace disabled

Program config/missing found: YES

Program cp found: YES

Program xmllint found: YES

Program xsltproc found: YES

Program wget found: YES

Program /usr/bin/meson found: YES

Check usable header "bsd_auth.h" : NO

Check usable header "dns_sd.h" : NO

Program fop found: NO

Found pkg-config: /bin/pkg-config (0.27.1)

Run-time dependency krb5-gssapi found: YES 1.15.1

Check usable header "gssapi/gssapi.h" with dependency krb5-gssapi: YES

Check usable header "gssapi/gssapi_ext.h" with dependency krb5-gssapi: YES

Checking for function "gss_store_cred_into" with dependency krb5-gssapi: YES

Run-time dependency ldap found: NO (tried pkgconfig)

Has header "ldap.h" : NO

Compiler for language cpp skipped: feature llvm disabled

Did not find CMake 'cmake'

Found CMake: NO

Run-time dependency icu-uc found: NO (tried pkgconfig and cmake)

Run-time dependency icu found: NO (tried cmake)

Run-time dependency libxml-2.0 found: YES 2.9.1

Run-time dependency libxslt found: YES 1.1.28

Run-time dependency liblz4 found: NO (tried pkgconfig and cmake)

Run-time dependency lz4 found: NO (tried cmake)

Run-time dependency tcl found: NO (tried pkgconfig and cmake)

Library tcl found: YES

Has header "tcl.h" with dependency -ltcl: YES

Run-time dependency pam found: NO (tried pkgconfig and cmake)

Library pam found: YES

Check usable header "security/pam_appl.h" with dependency -lpam: YES

Has header "perl.h" : YES

Message: CCFLAGS recommended by perl: -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64

Message: CCFLAGS for embedding perl: -I/usr/lib64/perl5/CORE

Message: LDFLAGS for embedding perl: "-L/usr/lib64/perl5/CORE -lperl -lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc"

Checking if "libperl" links: YES

Program python3 found: YES (/bin/python3)

Dependency python found: YES (pkgconfig)

Check usable header "Python.h" with dependency python: YES

Run-time dependency readline found: NO (tried pkgconfig and cmake)

Library readline found: YES

Has header "readline/history.h" with dependency -lreadline: YES

Has header "readline/readline.h" with dependency -lreadline: YES

Checking for function "append_history" with dependency -lreadline: YES

Checking for function "history_truncate_file" with dependency -lreadline: YES

Checking for function "rl_completion_matches" with dependency -lreadline: YES

Checking for function "rl_filename_completion_function" with dependency -lreadline: YES

Checking for function "rl_reset_screen_size" with dependency -lreadline: YES

Checking for function "rl_variable_bind" with dependency -lreadline: YES

Header has symbol "rl_completion_suppress_quote" with dependency -lreadline: YES

Header has symbol "rl_filename_quote_characters" with dependency -lreadline: YES

Header has symbol "rl_filename_quoting_function" with dependency -lreadline: YES

Run-time dependency libselinux found: YES 2.5

Run-time dependency libsystemd found: YES 219

Run-time dependency openssl found: YES 1.0.2k

Has header "openssl/ssl.h" with dependency openssl: YES

Has header "openssl/err.h" with dependency openssl: YES

Checking for function "CRYPTO_new_ex_data" with dependency openssl: YES

Checking for function "SSL_new" with dependency openssl: YES

Checking for function "SSL_CTX_set_cert_cb" with dependency openssl: YES

Checking for function "OPENSSL_init_ssl" with dependency openssl: NO

Checking for function "BIO_meth_new" with dependency openssl: NO

Checking for function "ASN1_STRING_get0_data" with dependency openssl: NO

Checking for function "HMAC_CTX_new" with dependency openssl: NO

Checking for function "HMAC_CTX_free" with dependency openssl: NO

Checking for function "CRYPTO_lock" with dependency openssl: YES

Checking for function "X509_get_signature_info" with dependency openssl: NO

Checking for function "SSL_CTX_set_num_tickets" with dependency openssl: NO

Run-time dependency zlib found: YES 1.2.7

Has header "zlib.h" with dependency zlib: YES

Message: Can't locate IPC/Run.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at config/check_modules.pl line 14.

BEGIN failed--compilation aborted at config/check_modules.pl line 14.

meson.build:1544: WARNING: Additional Perl modules are required to run TAP tests.

Run-time dependency libzstd found: NO (tried pkgconfig and cmake)

Run-time dependency zstd found: NO (tried cmake)

Checking if "c99" compiles: NO

Checking if "c99 with -std=c99" compiles: YES

Checking for size of "long" : 8

Checking for alignment of "short" : 2

Checking for alignment of "int" : 4

Checking for alignment of "long" : 8

Checking for alignment of "double" : 8

Checking for alignment of "long int" : 8

Checking for size of "void *" : 8

Checking for size of "size_t" : 8

Checking if "__int128" links: YES

Checking if "__int128 alignment bug" runs: YES

Checking for alignment of "__int128" : 16

Checking for size of "bool" : 1

Compiler for C supports arguments -Werror=format: YES

Compiler for C supports arguments -Werror=ignored-attributes: NO

Checking if "format gnu_printf" compiles: YES

Compiler for C supports function attribute visibility:default: YES

Compiler for C supports function attribute visibility:hidden: YES

Checking for function "__builtin_bswap16" : YES

Checking for function "__builtin_bswap32" : YES

Checking for function "__builtin_bswap64" : YES

Checking for function "__builtin_clz" : YES

Checking for function "__builtin_ctz" : YES

Checking for function "__builtin_constant_p" : YES

Checking for function "__builtin_frame_address" : YES

Checking for function "__builtin_popcount" : YES

Checking for function "__builtin_unreachable" : YES

Checking if "__builtin_types_compatible_p" compiles: YES

Checking if "__builtin_mul_overflow" links: NO

Checking if "__get_cpuid" links: YES

Checking if "__get_cpuid_count" links: NO

Checking if "__cpuidex" links: NO

Compiler for C supports arguments -fno-strict-aliasing: YES

Compiler for C supports arguments -fwrapv: YES

Compiler for C supports arguments -fexcess-precision=standard: YES

Compiler for C supports arguments -ftree-vectorize: YES

Compiler for C supports arguments -funroll-loops: YES

Compiler for C supports arguments -Wmissing-prototypes: YES

Compiler for C supports arguments -Wpointer-arith: YES

Compiler for C supports arguments -Werror=vla: YES

Compiler for C supports arguments -Werror=unguarded-availability-new: NO

Compiler for C supports arguments -Wendif-labels: YES

Compiler for C supports arguments -Wmissing-format-attribute: YES

Compiler for C supports arguments -Wimplicit-fallthrough=3: NO

Compiler for C supports arguments -Wcast-function-type: NO

Compiler for C supports arguments -Wshadow=compatible-local: NO

Compiler for C supports arguments -Wformat-security: YES

Compiler for C supports arguments -Wdeclaration-after-statement: YES

Compiler for C supports arguments -Wunused-command-line-argument: NO

Compiler for C supports arguments -Wcompound-token-split-by-macro: NO

Compiler for C supports arguments -Wformat-truncation: NO

Compiler for C supports arguments -Wstringop-truncation: NO

Compiler for C supports arguments -Wcast-function-type-strict: NO

Compiler for C supports arguments -Wall: YES

Compiler for C supports arguments -g: YES

Compiler for C supports arguments -O2: YES

Checking if "__sync_lock_test_and_set(char)" links: YES

Checking if "__sync_lock_test_and_set(int32)" links: YES

Checking if "__sync_val_compare_and_swap(int32)" links: YES

Checking if "__sync_val_compare_and_swap(int64)" links: YES

Checking if " __atomic_compare_exchange_n(int32)" links: YES

Checking if " __atomic_compare_exchange_n(int64)" links: YES

Checking if "XSAVE intrinsics without -mxsave" links: NO

Checking if "XSAVE intrinsics with -mxsave" links: NO

Checking if "AVX-512 popcount without -mavx512vpopcntdq -mavx512bw" links: NO

Checking if "AVX-512 popcount with -mavx512vpopcntdq -mavx512bw" links: NO

Checking if "_mm_crc32_u8 and _mm_crc32_u32 without -msse4.2" links: NO

Checking if "_mm_crc32_u8 and _mm_crc32_u32 with -msse4.2" links: YES

Checking if "x86_64: popcntq instruction" compiles: YES

Has header "atomic.h" : NO

Has header "copyfile.h" : NO

Has header "crtdefs.h" : NO

Has header "execinfo.h" : YES

Has header "getopt.h" : YES

Has header "ifaddrs.h" : YES

Has header "langinfo.h" : YES

Has header "mbarrier.h" : NO

Has header "strings.h" : YES

Has header "sys/epoll.h" : YES

Has header "sys/event.h" : NO

Has header "sys/personality.h" : YES

Has header "sys/prctl.h" : YES

Has header "sys/procctl.h" : NO

Has header "sys/signalfd.h" : YES

Has header "sys/ucred.h" : NO

Has header "termios.h" : YES

Has header "ucred.h" : NO

Checking if "test whether F_FULLFSYNC is declared" compiles: NO

Checking if "test whether fdatasync is declared" compiles: YES

Checking if "test whether posix_fadvise is declared" compiles: YES

Checking if "test whether strlcat is declared" compiles: NO

Checking if "test whether strlcpy is declared" compiles: NO

Checking if "test whether strnlen is declared" compiles: YES

Checking if "test whether preadv is declared" compiles: YES

Checking if "test whether pwritev is declared" compiles: YES

Checking if "test whether strchrnul is declared" compiles: YES

Checking for type "struct option" : YES

Checking if "opterr" links: YES

Checking if "optreset" links: NO

Checking for type "socklen_t" : YES

Checking whether type "struct sockaddr" has member "sa_len" : NO

Checking whether type "struct tm" has member "tm_zone" : YES

Checking if "global variable `timezone' exists" compiles: YES

Checking for type "union semun" : NO

Checking if "strerror_r" compiles: NO

Checking for type "locale_t" : YES

Checking if "typeof()" compiles: NO

Checking if "typeof()" compiles: YES

Checking if "wcstombs_l" compiles: NO

Checking if "wcstombs_l in xlocale.h" compiles: NO

Library m found: YES

Library rt found: YES

Library dl found: YES

Library util found: YES

Library getopt found: NO

Library gnugetopt found: NO

Library execinfo found: NO

Checking for function "backtrace_symbols" : YES

Checking for function "clock_gettime" : YES

Checking for function "copyfile" : NO

Checking for function "copy_file_range" : NO

Checking for function "dlsym" : NO

Checking for function "dlsym" with dependency -ldl: YES

Checking for function "explicit_bzero" : NO

Checking for function "getifaddrs" : YES

Checking for function "getopt" : YES

Checking for function "getopt_long" : YES

Checking for function "getpeereid" : NO

Checking for function "getpeerucred" : NO

Checking for function "inet_aton" : YES

Checking for function "inet_pton" : YES

Checking for function "kqueue" : NO

Checking for function "mbstowcs_l" : NO

Checking for function "memset_s" : NO

Checking for function "mkdtemp" : YES

Checking for function "posix_fadvise" : YES

Checking for function "posix_fallocate" : YES

Checking for function "ppoll" : YES

Checking for function "pthread_barrier_wait" : NO

Checking for function "pthread_barrier_wait" with dependency threads: YES

Checking for function "pthread_is_threaded_np" : NO

Checking for function "pthread_is_threaded_np" with dependency threads: NO

Checking for function "sem_init" : NO

Checking for function "sem_init" with dependency -lrt: NO

Checking for function "sem_init" with dependency threads: YES

Checking for function "setproctitle" : NO

Checking for function "setproctitle" with dependency -lutil: NO

Checking for function "setproctitle_fast" : NO

Checking for function "shm_open" : NO

Checking for function "shm_open" with dependency -lrt: YES

Checking for function "shm_unlink" : NO

Checking for function "shm_unlink" with dependency -lrt: YES

Checking for function "shmget" : YES

Checking for function "socket" : YES

Checking for function "strerror_r" : YES

Checking for function "strlcat" : NO

Checking for function "strlcpy" : NO

Checking for function "strnlen" : YES

Checking for function "strsignal" : YES

Checking for function "sync_file_range" : YES

Checking for function "syncfs" : YES

Checking for function "uselocale" : YES

Checking for function "wcstombs_l" : NO

Checking for function "syslog" : YES

Check usable header "syslog.h" : YES

Program msgfmt found: YES

Check usable header "libintl.h" : YES

Checking for function "ngettext" : YES

meson.build:2863: WARNING: Consider using the built-in option for language standard version instead of using "-std=c99".

Configuring pg_config_ext.h using configuration

Configuring pg_config.h using configuration

Compiler for C supports arguments -fPIC: YES

Compiler for C supports link arguments -Wl,--as-needed: YES

Configuring pg_config_paths.h using configuration

Configuring ecpg_config.h using configuration

Program strip found: YES

Compiler for C supports link arguments -Wl,--export-dynamic: YES

Program ar found: YES

Program gawk found: YES

Configuring Makefile.global using configuration

Configuring version.sgml using configuration

Program pandoc found: NO

Program db2x_xsltproc found: NO

Program db2x_texixml found: NO

Program makeinfo found: NO

Message: checking for file conflicts between source and build directory

Program git found: YES

Program bzip2 found: YES

Build targets in project: 531

3、进入上面的创建的build目录

[postgres@pg1 build]$ ls

build.ninja            config   doc         meson-logs     meson-uninstalled

compile_commands.json  contrib  meson-info  meson-private  src

[postgres@pg1 build]$ ninja(执行命令),正常开始安装,类似传统方式的make&&make install.。

[1983/1983] Linking target src/interfaces/ecpg/test/thread/alloc

sudo ninja install

在命令执行过程中,会提示要你录入操作系统用户postgres的密码。同时你先要把操作系统用户postgres加入到/etc/sudoers文件中。

4、初始化PG数据库,[postgres@pg1 soft]$ bin/initdb -D /home/postgres/data

The files belonging to this database system will be owned by user "postgres".

This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".

The default database encoding has accordingly been set to "UTF8".

The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /home/postgres/data ... ok

creating subdirectories ... ok

selecting dynamic shared memory implementation ... posix

selecting default "max_connections" ... 100

selecting default "shared_buffers" ... 128MB

selecting default time zone ... America/New_York

creating configuration files ... ok

running bootstrap script ... ok

performing post-bootstrap initialization ... ok

syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections

initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

   bin/pg_ctl -D /home/postgres/data -l logfile start

   总结:在学习了meson安装方法后,我发现其命令和生成的目录命名很有意思。meson(我的儿),nijia(你家),build.ninja,搭建你的家。


评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

合作电话:010-64087828

社区邮箱:greatsql@greatdb.com

社区公众号
社区小助手
QQ群
GMT+8, 2025-6-29 11:41 , Processed in 0.014728 second(s), 9 queries , Redis On.
返回顶部