postgreSQL
Windows版のpostgresでのリストア方法
DBは、以下で事前に作成している
CREATE DATABASE testdb WITH ENCODING='EUC_JP' OWNER=postgres TEMPLATE=template0 LC_COLLATE='C' LC_CTYPE='C' CONNECTION LIMIT=-1;
pgAdminなどを利用しplain-textでバックアップしたファイルのリストアで「pg_restore」は使えない。
以下の方法は、使えない。
pg_restore.exe --host localhost --port 5432 --username "postgres" --dbname "testdb" --verbose "C:\tmp\testdb.sql"
以下のようにエラーになる
C:\Users\test>pg_restore.exe --host localhost --port 5432 --username "postgres" --dbname "testdb" --verbose "C:\tmp\testdb.sql"
pg_restore: [アーカイバ] 入力ファイルがテキスト形式のダンプのようです。psqlを使用してください
psqlを使うそうです。↓参考。
http://www.cyber-funnel.com/postgres/index947.html
バックアップした C:\Backup.sql をデータベース db1 にリストアする
psql.exe -h localhost -p 5432 -U postgres -d db1 -f C:\Backup.sql
実際の例の一部を抜粋
set Path=%Path%;C:\PostgreSQL\9.3\bin
C:\Users\test>psql.exe -h localhost -p 5432 -U postgres -d testdb -f "C:\tmp\testdb.sql"
ユーザ postgres のパスワード:
SET
SET
SET
SET
SET
SET
CREATE FUNCTION
ALTER FUNCTION
psql:C:\tmp\testdb.sql:34: ERROR: language "plpgsql" already exists
psql:C:\tmp\testdb.sql:37: ERROR: role "Administrator" does not exist
SET