mkdir /backup chown postgres:postgres /backup su - postgres createdb -U postgres test
# psql -U postgres test
psql (9.6.10)
"help" でヘルプを表示します.
CREATE TABLE member
(id INTEGER NOT NULL,
name TEXT NOT NULL,
age INTEGER,
PRIMARY KEY (id));
\q
psql -U postgres test -c "INSERT INTO member (id, name, age) VALUES ('1', 'hoge', 10)"
psql -U postgres test -c "INSERT INTO member (id, name, age) VALUES ('2', 'foo', 20)"
psql -U postgres test -c "INSERT INTO member (id, name, age) VALUES ('3', 'bar', 30)"
# psql -U postgres test -c "SELECT * from member"
id | name | age
----+------+-----
1 | hoge | 10
2 | foo | 20
3 | bar | 30
(3 行)
pg_rman init -B /backup -D /opt/pg/pgdata/data
psql -U postgres test -c "SELECT * from member"
pg_rman -B /backup backup -b full
pg_rman -B /backup validate
psql -U postgres test -c "DELETE FROM member WHERE id = 1"
psql -U postgres test -c "SELECT * from member"
id | name | age
----+------+-----
2 | foo | 20
3 | bar | 30
(2 行)
psql -U postgres test -c "VACUUM"
pg_rman -B /backup backup -b incremental
pg_rman -B /backup validate
exit
systemctl stop postgresql-9.6.service
rm -rf /opt/pg/pgdata/data
rm -rf /opt/pg/pgxlog/pg_xlog
rm -rf /opt/pg/pgarch/arc1
su - postgres -c "pg_rman -B /backup restore"
systemctl start postgresql-9.6.service
psql -U postgres test -c "SELECT * from member"