博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PostgreSQL standby in 64bit to 32bit or reverse enviroment
阅读量:7252 次
发布时间:2019-06-29

本文共 6039 字,大约阅读时间需要 20 分钟。

64和32位系统上安装的PostgreSQL能不能做流复制搭建standby.


今天问同事借了一台32位的机器测试一下.
测试环境 : 
CentOS 5.x 32bit 和64bit 各一台.
PostgreSQL 9.1.4源码
32bit 作为primary
64bit 作为standby
结果是可行的, 只是需要在64bit上使用32bit的pgsql程序.
而反过来则不行(64bit primary , 32bit standby).
说白了, 程序要兼容. 在这种环境中建standby, 程序必须都是32bit的. 因为OS 64bit可以跑32bit的程序, 而OS 32bit 不能跑64bit的程序.

1. 配置OS
yum install -y lrzszyum install -y sysstatyum install -y e4fsprogsyum install -y ntpyum install -y readline-develyum install -y zlibyum install -y zlib-develyum install -y opensslyum install -y openssl-develyum install -y pam-develyum install -y libxml2-develyum install -y libxslt-devel/usr/sbin/ntpdate asia.pool.ntp.org && /sbin/hwclock --systohc-- 临时关闭防火墙, 生产中则配置一下, 开放互访监听端口service iptables stopvi /etc/sysctl.confkernel.shmmni = 4096kernel.sem = 50100 64128000 50100 1280fs.file-max = 7672460net.ipv4.ip_local_port_range = 9000 65000net.core.rmem_default = 1048576net.core.rmem_max = 4194304net.core.wmem_default = 262144net.core.wmem_max = 1048576net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_max_syn_backlog = 4096net.core.netdev_max_backlog = 10000vm.overcommit_memory = 0net.ipv4.ip_conntrack_max = 655360fs.aio-max-nr = 1048576net.ipv4.tcp_timestamps = 0sysctl -pvi /etc/security/limits.conf* soft    nofile  131072* hard    nofile  131072* soft    nproc   131072* hard    nproc   131072* soft    core    unlimited* hard    core    unlimited* soft    memlock 50000000* hard    memlock 50000000vi /etc/sysconfig/selinuxSELINUX=disabledcd /data03/soft_baktar -jxvf flex-2.5.35.tar.bz2cd flex-2.5.35./configure && make && make install
32位机器上
useradd platform32vi /home/platform32/.bash_profileexport PGPORT=1616export PGDATA=/home/platform32/pg_rootexport LANG=en_US.utf8export PGHOME=/home/platform32/pgsqlexport LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/libexport DATE=`date +"%Y%m%d%H%M"`export PATH=$PGHOME/bin:$PATH:.export MANPATH=$PGHOME/share/man:$MANPATHalias rm='rm -i'alias ll='ls -lh'
64位机器上
useradd platform64vi /home/platform64/.bash_profile export PGPORT=1616export PGDATA=/home/platform64/pg_rootexport LANG=en_US.utf8export PGHOME=/home/platform64/pgsqlexport LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/libexport DATE=`date +"%Y%m%d%H%M"`export PATH=$PGHOME/bin:$PATH:.export MANPATH=$PGHOME/share/man:$MANPATHalias rm='rm -i'alias ll='ls -lh'
2. 编译安装PostgreSQL 9.1.4
64位机器./configure --prefix=/home/platform64/pgsql --with-pgport=1616 --with-perl --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-thread-safety --with-wal-blocksize=16 && gmake worldsudo gmake install-world32位机器./configure --prefix=/home/platform32/pgsql --with-pgport=1616 --with-perl --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-thread-safety --with-wal-blocksize=16 && gmake worldsudo gmake install-world
3. 在32bit 机器上初始化数据库
initdb -D $PGDATA -E UTF8 --locale=C -U postgres -Wvi pg_hba.confhost    replication     replica        192.168.101.35/32                 md5host all all 0.0.0.0/0 md5vi postgresql.conflisten_addresses = '0.0.0.0'port = 1616max_connections = 100shared_buffers = 1024MBmaintenance_work_mem = 512MBmax_stack_depth = 8MBwal_level = hot_standbycheckpoint_segments = 32max_wal_senders = 32wal_sender_delay = 10mswal_keep_segments = 64hot_standby = onpg_ctl startpsql -h 127.0.0.1 postgres postgrescreate role replica nosuperuser nocreatedb nocreaterole noinherit login replication connection limit 32 encrypted password 'REPLICA';vi /home/platform32/.pgpass192.168.101.66:1616:replication:replica:REPLICA192.168.101.35:1616:replication:replica:REPLICAchmod 400 /home/platform32/.pgpass
4. 配置standby
vi /home/platform64/.pgpass192.168.101.66:1616:replication:replica:REPLICA192.168.101.35:1616:replication:replica:REPLICAchmod 400 /home/platform64/.pgpassvi $PGDATA/recovery.confrecovery_target_timeline = 'latest'standby_mode = onprimary_conninfo = 'host=192.168.101.66 port=1616 user=replica keepalives_idle=60'trigger_file = '/home/platform64/pg_root/.1616.PG.trigger'
5. 初始化standby
pg_basebackup -D $PGDATA -F p -x -l base -P -v -h 192.168.101.66 -p 1616 -U replica
6. 启动standby
pg_ctl start报错FATAL:  incorrect checksum in control file
7. 修改pg_controlfile的checksum源码, 不check.
vi src/backend/access/transam/xlog.c注释checksum部分        /* if (!EQ_CRC32(crc, ControlFile->crc))                ereport(FATAL,                                (errmsg("incorrect checksum in control file")));        */
8. 重新编译standby端的pgsql

9. 重新启动standby, 报另一个错误
FATAL:  database files are incompatible with serverDETAIL:  The database cluster was initialized with MAXALIGN 1093850759, but the server was compiled with MAXALIGN 8.HINT:  It looks like you need to initdb.
在控制文件差别 : 
32 位机器的控制文件信息 : Maximum data alignment:               4Maximum size of a TOAST chunk:        200064 位机器(initdb 后)的控制文件信息 : Maximum data alignment:               8Maximum size of a TOAST chunk:        1996
在src/backend/access/transam/xlog.c这里面有很多的check, 不一一列出.要在64 bit的机器上使用到底应该怎么办呢?其实和程序有关系, 只要把32bit 上编译的pgsql程序拷贝过来就可以了10. 在64bit的机器上使用32bit的pgsql做standby .
scp -r root@32bit:/home/platform32/pgsql /home/platform64/pg_ctl start
在primary上插入测试数据 :
[platform32@192_168_101_66 pg_root]$ psql postgres postgres -h 127.0.0.1 psql (9.1.4) Type "help" for help.  postgres=# \dt         List of relations  Schema | Name | Type  |  Owner    --------+------+-------+----------  public | t    | table | postgres (1 row)  postgres=# create table test (id int); CREATE TABLE postgres=# insert into test select generate_series (1,10000); INSERT 0 10000
在standby上验证 :
[platform64@db-192-168-101-35 ~]$ psql -h 127.0.0.1 postgres postgrespsql (9.1.4)Type "help" for help.postgres=# select count(*) from test; count ------- 10000(1 row)
11. 那么反过来行不行呢? 在32bit的机器上允许64bit的程序?
显然是不行的
[platform32@192_168_101_66 ~]$ pg_ctl --help -bash: /home/platform32/pgsql/bin/pg_ctl: cannot execute binary file[platform32@192_168_101_66 ~]$ postgres --help -bash: /home/platform32/pgsql/bin/postgres: cannot execute binary file

转载地址:http://toebm.baihongyu.com/

你可能感兴趣的文章
node+vue报错合辑
查看>>
Date——js 获取当前日期到之后一个月30天的日期区间
查看>>
RT-SA-2019-003 Cisco RV320 Unauthenticated Configuration Export
查看>>
Java线程练习
查看>>
Algs4-1.5.22Erods-renyi模型的倍率实验
查看>>
计算机硬件的组成、python的开发层面及语法介绍
查看>>
python面试知识点
查看>>
栅格布局
查看>>
Zimber 8.8.12卸载后重新安装报错解决办法
查看>>
Git 自救指南
查看>>
spring boot配置项目访问路径,配置拦截器,配置静态虚拟路径
查看>>
linux运维笔记
查看>>
Lake Counting (DFS)
查看>>
信息安全影响因素
查看>>
hadoop安装
查看>>
delegate事件委托
查看>>
Linux Process VS Thread VS LWP
查看>>
杭电多校第二场 1005 hack it
查看>>
VMM2012应用指南之9-向VMM中添加VMware ESX Server主机
查看>>
Exchange日常管理之二十二:配置保留策略
查看>>