sudo apt-get update && sudo apt-get -y install make g++ checkinstall libreadline6-dev zlib1g-dev
wget https://ftp.postgresql.org/pub/source/v9.4rc1/postgresql-9.4rc1.tar.gz tar xzf postgresql-9.4rc1.tar.gz
cd postgresql-9.4rc1/ ./configure make sudo checkinstall
sudo useradd -M postgres
sudo mkdir -p /data/db sudo chown postgres:postgres /data/db sudo chmod 0700 /data/db
sudo -u postgres /usr/local/pgsql/bin/initdb -D /data/db
sudo -u postgres mkdir /data/db/pg_log sudo -u postgres chmod 0700 /data/db/pg_log
host all all 192.168.1.0/24 md5 host replication replica 192.168.1.108/32 md5
sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /data/db start
ps aux | grep postgres postgres 21295 0.0 0.0 23700 604 ? Ss 13:39 0:00 postgres: logger process postgres 21297 0.0 13.6 170880 138408 ? Ss 13:39 0:01 postgres: checkpointer process postgres 21298 0.0 5.0 170784 51076 ? Ss 13:39 0:00 postgres: writer process postgres 21299 0.0 0.5 170648 5148? Ss 13:39 0:00 postgres: wal writer process postgres 21300 0.0 0.1 171052 1836 ? Ss 13:39 0:00 postgres: autovacuum launcher process postgres 21301 0.2 0.1 25924 1060 ? Ss 13:39 0:17 postgres: stats collector process
/usr/local/pgsql/bin/psql -U postgres -c "create user replica with replication encrypted password '123'"
/usr/local/pgsql/bin/createdb -U postgres testdb /usr/local/pgsql/bin/psql -U postgres -d testdb -c "create table testtable (id serial, data text)" /usr/local/pgsql/bin/psql -U postgres -d testdb -c "insert into testtable select nextval('testtable_id_seq'::regclass), md5(generate_series(1,1000000)::text)"
sudo mkdir -p /data/db sudo chmod 0700 /data/db sudo chown postgres:postgres /data/db
sudo -u postgres /usr/local/pgsql/bin/pg_basebackup -h 192.168.1.103 -U replica -D /data/db -X s
standby_mode='on' primary_conninfo='host=192.168.1.103 port=5432 user=replica password=123'
sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /data/db start
postgres 21295 0.0 0.0 23700 604 ? Ss 13:39 0:00 postgres: logger process postgres 21297 0.0 0.2 170756 2312 ? Ss 13:39 0:00 postgres: checkpointer process postgres 21298 0.0 0.2 170784 2252 ? Ss 13:39 0:00 postgres: writer process postgres 21299 0.0 0.5 170648 5148 ? Ss 13:39 0:00 postgres: wal writer process postgres 21300 0.0 0.1 171052 1804 ? Ss 13:39 0:00 postgres: autovacuum launcher process postgres 21301 0.0 0.1 25924 1060 ? Ss 13:39 0:00 postgres: stats collector process postgres 21323 0.0 0.2 171048 2108 ? Ss 13:46 0:00 postgres: wal sender process replica 192.168.1.108(56673) streaming 0/4E000210 postgres 15150 0.0 0.0 23700 612 ? Ss 13:46 0:00 postgres: logger process postgres 15151 0.0 0.1 170788 1496 ? Ss 13:46 0:00 postgres: startup process recovering 00000001000000000000004E postgres 15152 0.0 0.0 170680 944 ? Ss 13:46 0:00 postgres: checkpointer process postgres 15153 0.0 0.1 170680 1204 ? Ss 13:46 0:00 postgres: writer process postgres 15154 0.0 0.0 25792 648 ? Ss 13:46 0:00 postgres: stats collector process postgres 15155 0.6 0.1 174956 1660 ? Ss 13:46 0:00 postgres: wal receiver process streaming 0/4E000138
testdb=# select * from pg_stat_replication; -[ RECORD 1 ]----+------------------------------ pid | 21987 usesysid | 16384 usename | replica application_name | walreceiver client_addr | 192.168.1.108 client_hostname | client_port | 56674 backend_start | 2014-11-25 18:30:09.206434+03 backend_xmin | state | streaming sent_location | 0/5A2D8E60 write_location | 0/5A2D8E60 flush_location | 0/5A2D8E60 replay_location | 0/5A2D8E60 sync_priority | 0 sync_state | async
testdb=# insert into testtable select nextval('testtable_id_seq'::regclass), md5(generate_series(1,1000000)::text); INSERT 0 1000000 testdb=# select * from pg_stat_replication; -[ RECORD 1 ]----+------------------------------ pid | 21987 usesysid | 16384 usename | replica application_name | walreceiver client_addr | 192.168.1.108 client_hostname | client_port | 56674 backend_start | 2014-11-25 18:30:09.206434+03 backend_xmin | state | streaming sent_location | 0/63800000 write_location | 0/63680000 flush_location | 0/63680000 replay_location | 0/6136E160 sync_priority | 0 sync_state | async
sudo iptables -A OUTPUT -m tcp -p tcp —dport 5432 -j DROP
testdb=# insert into testtable select nextval('testtable_id_seq'::regclass), md5(generate_series(1,1000000)::text); INSERT 0 1000000
LOG: started streaming WAL from primary at 0/78000000 on timeline 1 FATAL: could not receive data from WAL stream: ERROR: requested WAL segment 000000010000000000000078 has already been removed
testdb=# SELECT pg_create_physical_replication_slot('standby_slot'); -[ RECORD 1 ]-----------------------+---------------- pg_create_physical_replication_slot | (standby_slot,)
testdb=# select * from pg_replication_slots; -[ RECORD 1 ]+------------- slot_name | standby_slot plugin | slot_type | physical datoid | database | active | f xmin | catalog_xmin | restart_lsn |
testdb=# insert into testtable select nextval('testtable_id_seq'::regclass), md5(generate_series(1,10000000)::text);
testdb=# show checkpoint_segments; -[ RECORD 1 ]-------+-- checkpoint_segments | 3
testdb=# show wal_keep_segments; -[ RECORD 1 ]-----+-- wal_keep_segments | 0
testdb=#\! ls /data/db/pg_xlog | wc -l 50
testdb=#\! tail -f /data/db/pg_log/postgresql-2014-11-27_191036.log Is the server running on host "192.168.1.103" and accepting TCP/IP connections on port 5432? LOG: started streaming WAL from primary at 0/A0000000 on timeline 1
Source: https://habr.com/ru/post/245847/
All Articles