0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

repmgrからpgpoolへデータ復元してみた。(pg_dump)

Last updated at Posted at 2026-01-16

はじめに

これまで作成したrepmgr/pgpool postgresqlのバックアップ・リストアをやってみた。

事前に以下の手順でPostgresqlを構築していること。

ここではHive_metastoreをターゲットとしてバックアップ・リストアします。

0. 変数(ここだけ置き換え)

送信元(repmgr):  (repmgr active機がよい。)

送信先(pgpool):  (pgpool active機がよい。)

pgpool VIP:

pgpool ポート: 9999(あなたの構成どおり)

DB: hive_metastore

ロール: hive

dump配置先: /tmp

以降は hive-site.xml の JDBC URL を jdbc:postgresql://:9999/hive_metastore にする想定です。

1. 送信元(repmgr)でバックアップ作成

hivepg1(active):

sudo -u postgres bash -lc '
set -euo pipefail
DB=hive_metastore
OUT=/tmp/${DB}_$(date +%F_%H%M%S).dump
pg_dump -Fc -d "$DB" --no-owner --no-privileges -f "$OUT"
ls -lh "$OUT"
echo "$OUT"
'

送信先へ転送

pg1の/tmpへ前の手順で作成されたdumpファイルをコピーする。

2. 送信先(pgpool)でDB受け入れ準備

pg1(active)で実施すること。

2.1. hive ロール / DB 作り直し(DROP→CREATE)

sudo -u postgres psql -v ON_ERROR_STOP=1 <<'SQL'
-- 接続を切る
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname='hive_metastore' AND pid <> pg_backend_pid();

DROP DATABASE IF EXISTS hive_metastore;
SQL
sudo -u postgres psql -v ON_ERROR_STOP=1 <<'SQL'

DO $$
BEGIN
  IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'hive') THEN
    CREATE ROLE hive LOGIN PASSWORD 'HivePasswordHere';
  END IF;
END $$;

CREATE DATABASE hive_metastore OWNER postgres;

\connect hive_metastore

GRANT CONNECT, TEMP ON DATABASE hive_metastore TO hive;

ALTER SCHEMA public OWNER TO hive;
GRANT USAGE, CREATE ON SCHEMA public TO hive;

GRANT ALL PRIVILEGES ON ALL TABLES    IN SCHEMA public TO hive;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO hive;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO hive;

ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES    TO hive;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO hive;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO hive;

SQL

3. 送信先(pgpool)でリストア

pg1(active)で実施すること。

sudo -u postgres bash -lc '
set -euo pipefail
DB=hive_metastore
DUMP="$(ls -1t /tmp/hive_metastore_*.dump | head -n 1)"

echo "Restore from: $DUMP"
pg_restore -d "$DB" -j 4 "$DUMP"
'

4. Hive 側:hive-site.xml の最小変更(接続先だけ切替)

hive1/hive2:

sudo vi /etc/hive/conf/hive-site.xml

変更すべきキーは以下:

javax.jdo.option.ConnectionURL

例(pgpool VIP + 9999):

URL: jdbc:postgresql://:9999/hive_metastore

5. Hive Metastore 再起動

hive1/hive2:

sudo systemctl restart hive-metastore
sudo systemctl status hive-metastore -l --no-pager

6. 疎通確認

zeppelinなどで確認し、差分反映されていることを確認する。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?