pg的编译安装
编译可重定位版本的postgresql:
LDFLAGS='-Wl,-rpath='"'"'$$ORIGIN/../lib'"'"',--disable-new-dtags' ./configure '--prefix=/root/pgsql' '--with-systemd' '--with-extra-version=iadm' '--with-system-tzdata=/usr/share/zoneinfo' '--disable-rpath'
其中,编译用的CFLAGS如下:
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
可重定位编译常见的排查问题的手段:
- ldd,可以打印二进制文件所依赖的共享库。
- 注意:在不受信任的二进制文件上执行ldd是危险的,因为它会执行所探测的程序
readelf --dynamic binary_file_path,检查二进制文件是否已设置RUNPATH的值。- 可重定位编译的关键是,为RUNPATH设置相对路径。
问题及解决方法
问题1:
configure: error: Package requirements (icu-uc icu-i18n) were not met:No package 'icu-uc' found
No package 'icu-i18n' found
解决办法:
[root@ecs-cs01-0001 postgresql-10.9]# yum install libicu-devel.aarch64
问题2:
configure: error: could not determine flags for linking embedded Perl.
This probably means that ExtUtils::Embed or ExtUtils::MakeMaker is notinstalled.
解决办法:
[root@ecs-cs01-0001 postgresql-10.9]# yum install perl-ExtUtils-Embed -y
问题3:
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.
解决办法:
[root@ecs-cs01-0001 postgresql-10.9]# yum install -y readline readline-devel
问题4:
configure: error: library 'pam' is required for PAM
解决办法:
[root@ecs-cs01-0001 postgresql-10.9]# yum install -y pam pam-devel
问题5:
configure: error: library 'xml2' (version >= 2.6.23) is required for XML support
解决办法:
[root@ecs-cs01-0001 postgresql-10.9]# yum install -y libxml2 libxml2-devel
问题6:
configure: error: library 'xslt' is required for XSLT support
解决办法:
[root@ecs-cs01-0001 postgresql-10.9]# yum install -y libxslt-devel.aarch64
问题7:
configure: error: library 'ldap' is required for LDAP
解决办法:
[root@ecs-cs01-0001 postgresql-10.9]# yum install -y openldap-devel.aarch64
问题8:
configure: error: header file is required for systemd support
解决办法:
[root@ecs-cs01-0001 postgresql-10.9]# yum install -y systemd-devel.aarch64
golang中初始化pgsql
|
|
pg的常用配置
postgresql.conf.tpl:
listen_addresses = '{{.pg_listen_host}}'
port = {{.pg_listen_port}}
unix_socket_directories = '../../data/PGData'
fsync = on{{if eq .os "windows"}}
shared_memory_type = windows
dynamic_shared_memory_type = windows{{end}}
shared_buffers = {{index_dynamic .pg_shared_buffers .env_deploy_resource_mode}}
temp_buffers = 8MB
work_mem = {{index_dynamic .pg_work_mem .env_deploy_resource_mode}}
huge_pages = off
effective_cache_size = 4GB
maintenance_work_mem = {{index_dynamic .pg_maintenance_work_mem .env_deploy_resource_mode}}
max_connections = {{index_dynamic .pg_max_connections .env_deploy_resource_mode}}
max_prepared_transactions = {{index_dynamic .pg_max_connections .env_deploy_resource_mode}}
superuser_reserved_connections = 2
#tcp_keepalived_idle = 120
#tcp_keepalived_interval = 10
#tcp_keepalived_count = 10
authentication_timeout = 10s
#wal_level = replica
wal_level = minimal
max_wal_senders = 0
wal_buffers = {{index_dynamic .pg_wal_buffers .env_deploy_resource_mode}}
checkpoint_completion_target = 0.9
commit_delay = {{index_dynamic .pg_commit_delay .env_deploy_resource_mode}}
commit_siblings = 4
wal_log_hints = on
max_wal_size = 1GB
min_wal_size = 80MB
#wal_keep_segments = 640
logging_collector = on
log_destination = 'csvlog'
log_directory = '../../logs/infra/pgsql'
log_filename = 'postgresql-%a.log'
log_rotation_age = 1d
log_duration = off
log_truncate_on_rotation = on
log_min_duration_statement = 60000
log_checkpoints = off
#log_conenctions = off
log_disconnections = off
log_lock_waits = off
log_statement = none
log_line_prefix = '%t [%p]: user=%u,db=%d,client=%h '
log_timezone = '{{.tz}}'
timezone = '{{.tz}}'
log_min_messages = 'error'
log_min_error_statement = 'error'
#clilent_min_messages = 'error'
#shared_preload_libraries = 'pg_stat_statements'
#pg_stat_statements.max = 10000
#pg_stat_statements.track = all
#pg_stat_statements.track_utility = off
#pg_stat_statements.save = off
ipostgres.service:
[Unit]
Description=PostgreSQL 12 database server
Documentation=https://www.postgresql.org/docs/12/static
After=syslog.target
After=network.target
[Service]
Environment="PGDATA={{.root_dir}}/data/PGData"
Environment="LD_LIBRARY_PATH={{.root_dir}}/infra/pgsql/lib"
Environment="PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj"
Environment="PG_OOM_ADJUST_VALUE=0"
ExecStop={{.root_dir}}/infra/pgsql/bin/pg_ctl stop -D ${PGDATA}
ExecStart={{.root_dir}}/infra/pgsql/bin/pg_ctl start -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
OOMScoreAdjust=-1000
Restart=on-failure
RestartSec=5s
Type=forking
User={{.install_user}}

