我的笔记本电脑(mac)上的postgres数据库中大约有50gb的数据,需要将这些数据传输到新的pc(Windows)上。我已经使用需要传输的模式的pg_dump生成了tar转储,但是pg_restore只是挂起了。
为消除文件大小和源文件为mac的问题,我将其简化为我能找到的最简单的测试用例,即在PC上以新模式创建新表,使用pg dump将其导出,然后尝试将其还原回同一数据库。即使有这么简单的东西,pg_restore仍然挂起。我显然缺少一些东西-可能很明显。有什么想法吗?
D:\Share\dbexport>psql -U postgres
Password for user postgres:
psql (12.1)
WARNING: Console code page (850) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
postgres=# create schema new_schema
postgres-# create table new_schema.new_table(id numeric);
CREATE SCHEMA
postgres=# insert into new_schema.new_table values(1);
INSERT 0 1
postgres=# commit;
WARNING: there is no transaction in progress
COMMIT
postgres=# exit
使用新表和1行创建架构。所以出口
D:\Share\dbexport>pg_dump -U postgres -n new_schema -f new_schema_sql.sql
Password:
D:\Share\dbexport>more new_schema_sql.sql
--
-- PostgreSQL database dump
--
-- Dumped from database version 12.1
-- Dumped by pg_dump version 12.1
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: new_schema; Type: SCHEMA; Schema: -; Owner: postgres
--
CREATE SCHEMA new_schema;
ALTER SCHEMA new_schema OWNER TO postgres;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: new_table; Type: TABLE; Schema: new_schema; Owner: postgres
--
CREATE TABLE new_schema.new_table (
id numeric
);
ALTER TABLE new_schema.new_table OWNER TO postgres;
--
-- Data for Name: new_table; Type: TABLE DATA; Schema: new_schema; Owner: postgres
--
COPY new_schema.new_table (id) FROM stdin;
1
\.
因此,文件已创建并具有预期的内容。在尝试还原之前,我重新连接到数据库并删除新的架构。
--
-- PostgreSQL database dump complete
--
D:\Share\dbexport>psql -U postgres
Password for user postgres:
psql (12.1)
WARNING: Console code page (850) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
postgres=# drop schema new_schema cascade;
NOTICE: drop cascades to table new_schema.new_table
DROP SCHEMA
postgres=# select * from new_schema.new_table;
ERROR: relation "new_schema.new_table" does not exist
LINE 1: select * from new_schema.new_table;
^
postgres=# exit
D:\Share\dbexport>pg_restore -U postgres -f new_schema_sql.sql
它只是挂在最后一行。我有点迷茫-我无法让pg_restore输出任何内容-我已经尝试了详细模式等,但是什么也没有。
有人知道我下一步要去哪里吗?
大卫
答案 0 :(得分:7)
所以我要给自己买一个笨拙的帽子。
@a_horse_with_no_name指出的问题是我误用了-f标志。那将指定输出文件而不是输入文件。
使用
pg_restore -U postgres -d postgres -n new_schema new_schema_custom.sql
解决了该问题。谢谢