Friday, May 13, 2016

Setup a time-lagging Dr PostgreSQL - 9.4



Step-1

[enterprisedb@localhost ~]$ psql -p 5444
psql.bin (9.5.0.5)
Type "help" for help.
edb=# select pg_create_physical_replication_slot('test_95');
pg_create_physical_replication_slot
-------------------------------------
(test_95,)
(1 row)


Step-2


[enterprisedb@localhost ~]$ pg_basebackup -P -R -X stream -c fast -h localhost -U enterprisedb -p 5444 -D /tmp/slave
44257/44257 kB (100%), 1/1 tablespace


edb=# \! more /tmp/slave/recovery.conf
standby_mode = 'on'
primary_conninfo = 'user=enterprisedb host=localhost port=5444'
primary_slot_name = 'test_95'
recovery_min_apply_delay = 1min


[enterprisedb@localhost ~]$ pg_ctl -D /tmp/slave/ start
server starting
[enterprisedb@localhost ~]$ 2016-05-03 23:51:51 PDT LOG: redirecting log output to logging collector process
2016-05-03 23:51:51 PDT HINT: Future log output will appear in directory "pg_log".


[enterprisedb@localhost ~]$ psql -p 5447
psql.bin (9.5.0.5)
Type "help" for help.

edb=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)

Step-3

edb=# select * from pg_replication_slots;
slot_name | plugin | slot_type | datoid | database | active | active_pid | xmin | catalog_xmin | restart_lsn
-----------+--------+-----------+--------+----------+--------+------------+------+--------------+-------------
test_95 | | physical | | | t | 11930 | | | 0/6000220
(1 row)


edb=# create table test_rep(id int primary key, name varchar(10));
CREATE TABLE

edb=# \dt
enterprisedb | test_rep | table | enterprisedb
public | dept | table | enterprisedb
public | emp | table | enterprisedb
public | jobhist | table | enterprisedb

edb=# \timing on
Timing is on.
edb=# insert into test_rep values(200000,'sample');
INSERT 0 1
Time: 3.740 ms

Step-4

edb=# \dt
public | dept | table | enterprisedb
public | emp | table | enterprisedb
public | jobhist | table | enterprisedb

edb=# \dt
public | dept | table | enterprisedb
public | emp | table | enterprisedb
public | jobhist | table | enterprisedb

edb=# \dt
enterprisedb | test_rep | table | enterprisedb
public | dept | table | enterprisedb
public | emp | table | enterprisedb
public | jobhist | table | enterprisedb


edb=# \timing on
Timing is on.

Time: 0.365 ms
edb=# select * from test_rep where id=200000;

Time: 0.365 ms
edb=# select * from test_rep where id=200000;

Time: 0.365 ms
edb=# select * from test_rep where id=200000;

Time: 0.356 ms
edb=# select * from test_rep where id=200000;

Time: 0.357 ms
edb=# select * from test_rep where id=200000;

Time: 0.366 ms
edb=# select * from test_rep where id=200000;

Time: 0.355 ms
edb=# select * from test_rep where id=200000;

Time: 0.284 ms
edb=# select * from test_rep where id=200000;
200000 | sample


No comments:

Post a Comment