本文共 2355 字,大约阅读时间需要 7 分钟。
# yum install postgresql -y# yum install postgresql-server -y
# mkdir /data/pg_data# chown postgres:postgres /data/pg_data
# vi /etc/profileexport PGDATA=/data/pg_data# source /etc/profile
# initdb -D /data/pg_data
# su postgresbash-4.2$ pg_ctl -D /data/pg_data startbash-4.2$ exit
# vi /etc/rc.d/rc.local/usr/bin/postgres -D /data/pg_data
# su postgresbash-4.2$ psqlpostgres=# create role repuser login replication encrypted password 'password123';postgres=# \q
pg_hba.conf# vi /data/pg_data/pg_hba.confhost replication repuser 192.168.11.0/8 md5host all all 192.168.11.0/8 trust
postgresql.conf# vi /data/pg_data/postgresql.conflisten_addresses = '192.168.11.131'wal_level = hot_standbymax_wal_senders= 6wal_keep_segments = 10240max_connections = 512archive_mode = onarchive_command = 'cp %p /data/pg_data/pg_archive/%f'
# mkdir /data/pg_data/pg_archive
# pg_ctl -D /data/pg_data reload
recovery.conf# cp /usr/share/pgsql/recovery.conf.sample /data/pg_data/recovery.conf# vi /data/pg_data/recovery.confstandby_mode = onprimary_conninfo = 'host=192.168.11.131 port=5432 user=repuser password=password123 keepalives_idle=60'
postgresql.conf# vi /data/pg_data/postgresql.conflisten_addresses = '192.168.11.132'wal_level = hot_standbymax_connections = 1000hot_standby = onmax_standby_streaming_delay = 30swal_receiver_status_interval = 10shot_standby_feedback = on
# chmod 700 /data/pg_data# vi /etc/rc.d/rc.localsu postgres -c '/usr/bin/postgres -D /data/pg_data'
# su postgresbash-4.2$ psqlpostgres=# select client_addr,sync_state from pg_stat_replication;client_addr | sync_state--------------+------------192.168.11.132 | async
# su postgresbash-4.2$ psqlpostgres=# \l
postgres=# create database pgdata owner pgone;
postgres=# grant all privileges on database pgdata to pgone;
# su postgresbash-4.2$ psqlpostgres=# alter user postgres with password 'password321';
pg_hba.conf# vi /data/pg_data/pg_hba.conflocal all all all all 127.0.0.1/32 trusthost all all 192.168.11.0/24 md5
# pg_ctl -D /data/pg_data reload
/data/pg_data目录权限正确转载地址:http://wixfk.baihongyu.com/