繁体   English   中英

pg_dump 和 restore - pg_restore 在 Windows 上挂起

[英]pg_dump and restore - pg_restore hangs on Windows

我的笔记本电脑 (mac) 上的 postgres 数据库中有大约 50GB 的数据,我需要将这些数据传输到我的新电脑 (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 输出任何东西 - 我试过详细模式等,但什么也没有。

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

大卫

所以我会给自己买一顶笨蛋帽。

@a_horse_with_no_name 指出的问题是我误用了 -f 标志。 这指定了输出文件而不是输入文件。

使用

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

解决了这个问题。 谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM