Skip to content

Instantly share code, notes, and snippets.

@hidepin
Last active October 27, 2018 04:25
Show Gist options
  • Save hidepin/934af62fb7dc965d5be8892800fa9872 to your computer and use it in GitHub Desktop.
Save hidepin/934af62fb7dc965d5be8892800fa9872 to your computer and use it in GitHub Desktop.

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment