pg_dump 和 restore - 在 Windows 上 pg_restore 卡住了

4
我在我的笔记本电脑(Mac)上有大约50GB的Postgres数据库数据,需要将其转移到我的新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

Schema 是通过创建新表和插入 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
\.

已经创建了.so文件并且具有预期的内容。在尝试还原之前,我重新连接到数据库并删除新模式。

--
-- 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输出任何内容 - 已尝试使用详细模式等,但没有效果。

有人知道我接下来应该去哪里找吗?

大卫


你创建了一个 SQL 脚本,需要使用 psql 运行该脚本,pg_restore 仅适用于自定义和 tar 格式,不适用于 "text" 格式。 - user330315
谢谢您的评论,不过如果我使用自定义或tar格式重新运行上述练习,我会遇到同样的问题。我会在问题中添加更新以展示这种行为。 - user7863288
如果您有 SQL 脚本,请使用 psql 中的 \i 运行它。 - user330315
3
pg_restore-f参数指定了一个输出文件(日志文件),输入文件则不需要任何参数开关来指定。详情请见:https://www.postgresql.org/docs/current/app-pgrestore.html - user330315
然而,正如我在问题中提到的那样,我有大量的数据需要传输,这些数据无法使用简单的SQL脚本处理。我的感觉是pg_restore存在问题,因为如果我使用自定义格式重复此操作,它仍然会卡住。 - user7863288
就是-f参数的问题。谢谢。我以为这应该很简单,就像那样。我会将问题标记为已解决。谢谢。 - user7863288
1个回答

11
所以我会给自己买一个傻瓜帽子。 正如 @a_horse_with_no_name 指出的那样,问题在于我误用了 -f 标志。它指定的是输出文件而不是输入文件。 使用

pg_restore -U postgres -d postgres -n new_schema new_schema_custom.sql

问题已得到解决。谢谢您。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接