• Skip to main content
  • Skip to primary sidebar

学習記録

テーブルのみのdumpとrestore

2022年10月20日 by 河副 太智 Leave a Comment

Postgresql 12.6 から Postgresql 14.5. にtest_eu3という名称のテーブルのみを移行する際にエラーが頻発したので顛末を記録していく。

テーブルのDumpは以下のコード

※(cd..でcドライブの最上位まで移動してから)cd \Program Files\PostgreSQL\12\bin(binフォルダに移動psqlではなく通常のコマンド)

1
pg_dump -Fc -b -U postgres -t test_eu -f C:\Users\...\Desktop\test_eu.sql rulings

まず、以下のエラーが出て文字化けしているので内容がつかめない。

1
2
3
4
5
6
7
8
9
10
11
12
C:\Users\...>pg_restore -v -U app_admin -d pre_rulings -t test_eu3 test_eu3.sql
pg_restore: connecting to database for restore
Password:
pg_restore: implied data-only restore
pg_restore: processing data for table "public.test_eu3"
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 2915; 0 3097390 TABLE DATA test_eu3 postgres
pg_restore: error: could not execute query: ERROR:  ????????????"public.test_eu3"??????????s
Command was: COPY public.test_eu3 (id, "national", item_day, item_hs_all, item_hs2, item_hs4, item_hs6, item_place, image_amount, img_name_all, item_image, other_info, org_discription, org_discription2, eng_discription, eng_discription2, id2) FROM stdin;
pg_restore: warning: errors ignored on restore: 1
 
C:\Users\...>

そこでpsqlで以下を入力し、英語に変換する

1
ALTER ROLE app_admin SET lc_messages = 'C';

すると以下のようなエラーに変わった

1
2
3
4
5
6
7
8
9
10
C:\Users\enosh>pg_restore -v -U app_admin -d pre_rulings -t test_eu3 test_eu3.sql
pg_restore: connecting to database for restore
Password:
pg_restore: implied data-only restore
pg_restore: processing data for table "public.test_eu3"
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 2915; 0 3097390 TABLE DATA test_eu3 postgres
pg_restore: error: could not execute query: ERROR:  relation "public.test_eu3" does not exist
Command was: COPY public.test_eu3 (id, "national", item_day, item_hs_all, item_hs2, item_hs4, item_hs6, item_place, image_amount, img_name_all, item_image, other_info, org_discription, org_discription2, eng_discription, eng_discription2, id2) FROM stdin;
pg_restore: warning: errors ignored on restore: 1

relation “public.test_eu3″がないとの事、
publicとはデータベース作成の際に自動で作成されるスキーマ名の事、
特に気にせず空のtest_eu3のテーブルを作成し、以下を入力

1
pg_restore -v -U app_admin -d pre_rulings -t test_eu test_eu.sql

空のテーブルとdumpにあるテーブルデータのカラムが異なるとエラーになるので注意する。

これで移行が完了。

このエントリーをはてなブックマークに追加

Tweet
[`yahoo` not found]
このエントリーを Google ブックマーク に追加
LinkedIn にシェア
LINEで送る


Filed Under: PosgreSQL

Reader Interactions

コメントを残す コメントをキャンセル

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in