用户在阿里云购买了RDS PostgreSQL,如何在自己的机房或者ECS上建立备库?关于如何构建逻辑备库,在我以前的文章有详细的讲解,所谓逻辑备库,是可以跨版本,甚至仅仅同步一部分相同步的表的备库。
https://yq.aliyun.com/articles/7240
如果用户需要构建一个和RDS PostgreSQL一模一样的备库,则可以通过流复制或者归档来完成。同时用户可以通过这种方法搭建自己的备库,在RDS没有提供异地容灾服务前,进行异地容灾。
步骤如下
PS:目前阿里RDS PostgreSQL软件还没有下载或开源,如果将来开放下载或开源的话,建议安装阿里云提供的PostgreSQL版本,可以保证兼容性,以及出问题可以找到阿里云的PostgreSQL内核团队修复。
select name,setting from pg_settings;
block_size | 8192
wal_block_size | 8192
rds_available_extensions | plpgsql,pg_stat_statements,btree_gin,btree_gist,chkpass,citext,cube,dblink,dict_int,earthdistance,hstore,intagg,intarray,isn,ltree,pgcrypto,pgrowlocks,pg_prewarm,pg_trgm,postgres_fdw,sslinfo,tablefunc,tsearch2,unaccent,postgis,postgis_topology,fuzzystrmatch,postgis_tiger_geocoder,plperl,pltcl,plv8,plls,plcoffee,"uuid-ossp",zhparser,pgrouting,rdkit,pg_hint_plan,pgstattuple
wget https://ftp.postgresql.org/pub/source/v9.4.6/postgresql-9.4.6.tar.bz2
tar -jxvf postgresql-9.4.6.tar.bz2
cd postgresql-9.4.6
./configure --prefix=/home/postgres/pgsql9.4.6 --with-blocksize=8 --with-wal-blocksize=8
gmake -j 32 world
gmake install-world
# vi ~/env_pg.sh
export PS1="$USER@\`/bin/hostname -s\`-> "
export PGPORT=1921
export PGDATA=/data01/pgdata
export LANG=en_US.utf8
export PGHOME=/home/postgres/pgsql9.4.6
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=\`date +"%Y%m%d%H%M"\`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
export PGHOST=$PGDATA
export PGDATABASE=postgres
export PGUSER=postgres
alias rm='rm -i'
alias ll='ls -lh'
unalias vi
postgres@digoal-> . ./env_pg.sh
-bash: unalias: vi: not found
postgres@digoal-> psql -V
psql (PostgreSQL) 9.4.6
postgis
plv8
plls
plcoffee
zhparser
pgrouting
rdkit
pg_hint_plan
PS:目前RDS PostgreSQL不支持自定义表空间,所以所有的数据都是放在默认表空间的,也即是需要单个目录的空间大于购买规格的空间的原因。将来如果RDS开放了创建表空间的权限,可以重新规划本地的目录。[root@digoal ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 39G 22G 15G 61% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sdb 20G 44M 19G 1% /data01
postgres@digoal-> psql "replication=true" -h xxxx.pg.rds.aliyuncs.com -p 3433 -U digoal
Password for user digoal:
psql (9.4.6, server 9.4.1)
Type "help" for help.
postgres=> IDENTIFY_SYSTEM;
systemid | timeline | xlogpos | dbname
---------------------+----------+------------+--------
6165616856935119759 | 3 | 0/6B3A0180 |
(1 row)
# add by digoal
port=1921
unix_socket_directories='.'
tcp_keepalives_idle = 70
tcp_keepalives_interval = 10
tcp_keepalives_count = 10
log_destination='csvlog'
logging_collector=on
log_truncate_on_rotation=on
log_line_prefix = ''
log_checkpoints = on
log_connections = on
log_disconnections = on
log_error_verbosity = verbose
hot_standby = on
max_standby_archive_delay = 300s
max_standby_streaming_delay = 300s
wal_receiver_status_interval = 1s
hot_standby_feedback = on
log_statement='none'
archive_mode=on
archive_command = '/bin/date'
track_io_timing=off
listen_addresses='0.0.0.0'
standby_mode = 'on'
primary_conninfo = 'host=xxxxxx.pg.rds.aliyuncs.com user=digoal password=xxxx port=3433'
recovery_target_timeline = 'latest'
postgres@digoal-> psql -h xxxx.pg.rds.aliyuncs.com -p 3433 -U digoal postgres
Type "help" for help.
postgres=> create table test(id timestamp);
postgres=> insert into test values (now());
postgres=> update test set id=now() returning *;
postgres=> \watch 1
postgres@digoal-> psql -h 127.0.0.1 -p 1921 -U digoal postgres
Type "help" for help.
postgres=> select * from test;
postgres=> \watch 1
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。