同步主库数据

pg_basebackup -h pg.rds.aliyuncs.com -U backup_user -p 5432  -X s  -v -P -R -D /data/pg5438 -l postgres32

-D:指向数据目录

-l:随意命名

修改postgresql.conf的配置文件

listen_addresses = '*'
port =  5438
log_line_prefix = '%m [%p] '
log_timezone = 'Asia/Shanghai'
timezone = 'Asia/Shanghai'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8' 
lc_numeric = 'en_US.UTF-8'  
lc_time = 'en_US.UTF-8'     
shared_buffers = 1000MB 
max_connections = 2000
superuser_reserved_connections =20
max_wal_senders = 64
max_replication_slots = 20
max_logical_replication_workers = 20
max_worker_processes = 256
max_prepared_transactions = 900

wal_level = 'logical'
min_wal_size=1GB
max_wal_size=2GB
wal_keep_size = 60GB
wal_log_hints=on

hot_standby = on
archive_mode=off
#archive_command='test ! -f /data/pg5438/archive/%f && cp %p /data/pg5438/archive/%f'
full_page_writes = on 
synchronous_commit = on 

log_truncate_on_rotation = on 
log_directory = '/data/pg5438/log'
log_destination = 'csvlog'
logging_collector = on 
log_filename = 'postgresql-%d-%H'
log_rotation_age = 60
log_rotation_size = 100MB
log_statement = 'mod'

deadlock_timeout = 1s
shared_preload_libraries = 'pg_stat_statements'

修改postgresql.auto.conf配置文件

# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
primary_conninfo = 'user=repl password=''*'' channel_binding=disable host=''pg.rds.aliyuncs.com'' port=5432 sslmode=disable sslcompression=0 ssl_min_protocol_version=TLSv1.2 gssencmode=disable krbsrvname=postgres target_session_attrs=any'

修改postmaster.opts文件

/usr/local/pg13/bin/postgres "-D" "/data/pg5438/data"

文件夹授权

chmod 0700 /data/pg5438/data