源码编译安装PostgreSQL(pg12)
摘要:源码安装PostgreSQL
系统环境: Centos 7.7 PostgreSQL12.2
1. 安装依赖包
# yum -y install readline readline-devel zlib zlib-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel tcl-devel uuid-devel gcc gcc-c++ make flex bison perl-ExtUtils*
此步骤可选,可根据需要选择,本人是先直接编译安装postgres,然后根据提示再回头安装所需的依赖包,也推荐根据报错信息来安装依赖包,加深pg所需依赖包的作用。2. 内核参数调整
根据需要指定,可跳过,采用默认值
# vi /etc/sysctl.conf
查看已完成配置
# sysctl -p
3. 用户limits设置
建议设置一下
# vi /etc/security/limits.confpostgres soft nofile 1048576postgres hard nofile 1048576postgres soft nproc 131072postgres hard nproc 131072postgres soft stack 10240postgres hard stack 32768postgres soft core 6291456postgres hard core 6291456
4. 创建用户和组
# groupadd dba -g 2000# useradd postgres -g 2000 -u 2000# id postgresuid=2000(postgres) gid=2000(dba) groups=2000(dba)
建议固化uid与gid,特别是后期配置流复制或集群。5. 目录规划
源文件目录# mkdir /soft 安装文件目录# mkdir -p /soft/opt/pg12 数据目录# mkdir -p /opt/data5555 WAL目录# mkdir -p /opt/wal5555 归档目录# mkdir -p /opt/archive5555 chmod -R 0770 /optchmod -R 0770 /softchown -R postgres:dba /soft
数据目录等带上端口号也是比较推荐的,尤其当存在多个实例时。6. 编译安装
下载文件并解压# su - postgres$ cd /soft$ wget https://ftp.postgresql.org/pub/source/v12.1/postgresql-12.2.tar.gz$ tar -zxvf postgresql-12.2.tar.gz
编译$ cd postgresql-12.2/$ ./configure --prefix=/soft/opt/pg12 --with-pgport=5555
建议修改一下端口,不采用默认5432端口
安装使用gmake 或者gmake world$ gmake world当看到最后一行显示为:PostgreSQL, contrib, and documentation successfully made. Ready to install.说明已经编译成功 使用gmake install或者gmake install-world 进行安装$ gmake install-world //包含扩展包和文档当看到最后一行显示为:PostgreSQL, contrib, and documentation installation complete.说明已经安装成功
查看版本$ /soft/opt/pg12/bin/postgres --versionpostgres (PostgreSQL) 12.2
7. 设置软链接
$ cd /soft/opt$ ln -s /soft/opt/pg12 /opt/pgsql
创建一个软链接指向当前版本,当进行版本变更后,不需要调整调用脚本,只需要修改这个软链接即可,后面都会使用这个软链接。8. 初始化数据目录
$ /opt/pgsql/bin/initdb -D /opt/data5555 -X /opt/wal5555 -E UTF8 -U postgres -W
下面的例子使用简体中文编码$ /opt/pgsql/bin/initdb -D/opt/data5555 -E EUC_CN --locale=zh_CN -W
9. 修改数据库参数
下面是一个参考配置$ vi /opt/data5555/postgresql.conflisten_addresses=‘192.168.220.150‘port=5555max_connections=1000unix_socket_directories=‘/opt/data5555‘wal_level=logicalarchive_mode=onarchive_command=‘cp %p /opt/archive5555/%f‘max_wal_size=1GBmax_wal_senders=10wal_keep_segments=512hot_standby=onlogging_collector=onlog_destination=csvloglog_directory=‘/opt/data5555/pg_log‘log_filename=‘pg_log_%Y-%m-%d_%H%M%S.log‘log_file_mode=0600log_truncate_on_rotation=onlog_rotation_age=1dlog_rotation_size=10MBlog_min_messages=warninglog_min_duration_statement=30slog_checkpoints=onlog_connections=onlog_disconnections=onlog_duration=onlog_lock_waits=onlog_statement=DDL
10.配置环境变量
$ vi ~/.bash_profileexport PGPORT=5555export PGUSER=postgresexport PGHOME=/opt/pgsqlexport PGDATA=/opt/data5555export PATH=$PGHOME/bin:$PATH
11.手工启停数据库
查看数据库运行状态$ pg_ctl -D /opt/data5555 status启动数据库$ pg_ctl -D /opt/data5555 start &停止数据库$ pg_ctl -D /opt/data5555 stop
12.查看实例进程
$ ps f -u postgres PID TTY STAT TIME COMMAND 1323 pts/0 S 0:00 -bash 1456 pts/0 R+ 0:00 \_ ps f -u postgres 1058 ? Ss 0:00 /opt/pg12/bin/postgres -D /opt/data5555 1068 ? Ss 0:00 \_ postgres: logger 1070 ? Ss 0:00 \_ postgres: checkpointer 1071 ? Ss 0:00 \_ postgres: background writer 1072 ? Ss 0:00 \_ postgres: walwriter 1073 ? Ss 0:00 \_ postgres: autovacuum launcher 1074 ? Ss 0:00 \_ postgres: archiver last was 000000010000000000000008 1075 ? Ss 0:00 \_ postgres: stats collector 1076 ? Ss 0:00 \_ postgres: logical replication launcher
13.开机自启动
root用户配置
# cp /soft/postgresql-12.2/contrib/start-scripts/linux /etc/init.d/postgres-12# chmod +x /etc/init.d/postgres-12# chkconfig postgres-12 on# vi /etc/init.d/postgres-12prefix=/opt/pgsql PGDATA="/opt/data5555" PGUSER=postgres PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin PGCTL="$prefix/bin/pg_ctl" set -e # Only start if we can find the postmaster.test -x $DAEMON ||{ echo "$DAEMON not found" if [ "$1" = "stop" ] then exit 0 else exit 5 fi} # Parse command line parameters.case $1 in start) echo -n "Starting PostgreSQL: " su - $PGUSER -c "$PGCTL -D ‘$PGDATA‘ start >>/dev/null &" echo "ok" ;; stop) echo -n "Stopping PostgreSQL: " su - $PGUSER -c "$PGCTL stop -D ‘$PGDATA‘ -s" echo "ok" ;; restart) echo -n "Restarting PostgreSQL: " su - $PGUSER -c "$PGCTL stop -D ‘$PGDATA‘ -s" su - $PGUSER -c "$PGCTL -D ‘$PGDATA‘ start >>/dev/null &" echo "ok" ;; reload) echo -n "Reload PostgreSQL: " su - $PGUSER -c "$PGCTL reload -D ‘$PGDATA‘ -s" echo "ok" ;; status) su - $PGUSER -c "$PGCTL status -D ‘$PGDATA‘" ;; *) # Print help echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2 exit 1 ;;Esac exit 0
来自为知笔记(Wiz)
源码编译安装PostgreSQL(pg12)
标签:xsl 脚本 mode tle figure euc ica ova its