Postgresql pg_转储和还原-pg_还原挂起在Windows上
我的笔记本电脑(mac)上的postgres数据库中有大约50gb的数据,需要传输到我的新电脑(windows)。我已经使用需要传输的模式的pg_转储生成了tar转储,但pg_restore只是挂起 为了消除文件大小和源文件是mac的问题,我将其归结为我能找到的最简单的测试用例,即在我的PC上以新模式创建一个新表,使用pg dump导出它,然后尝试将其恢复到同一数据库中。即使有这么简单的东西,pg_恢复也只是挂起。很明显,我遗漏了一些东西——可能很明显。有什么想法吗Postgresql pg_转储和还原-pg_还原挂起在Windows上,postgresql,Postgresql,我的笔记本电脑(mac)上的postgres数据库中有大约50gb的数据,需要传输到我的新电脑(windows)。我已经使用需要传输的模式的pg_转储生成了tar转储,但pg_restore只是挂起 为了消除文件大小和源文件是mac的问题,我将其归结为我能找到的最简单的测试用例,即在我的PC上以新模式创建一个新表,使用pg dump导出它,然后尝试将其恢复到同一数据库中。即使有这么简单的东西,pg_恢复也只是挂起。很明显,我遗漏了一些东西——可能很明显。有什么想法吗 D:\Share\dbexp
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_还原输出任何东西-我尝试过使用详细模式等,但什么都没有
有人知道我下一步该去哪里吗
大卫所以我要给自己买顶傻瓜帽 正如@a_horse_和_no_name所指出的问题,我误用了-f标志。指定输出文件而不是输入文件的 使用
pg_restore -U postgres -d postgres -n new_schema new_schema_custom.sql
修正了这个问题。谢谢您创建了一个SQL脚本,您需要使用
psql
运行该脚本,pg_restore
仅适用于自定义和tar格式,而不适用于“text”格式。谢谢您的评论,不幸的是,如果我使用自定义或tar格式重新运行上述练习,我会遇到同样的问题。我将向问题添加一个更新,以显示行为,如果您让SQL脚本使用PSQL的\I
运行它-f
参数pg\u restore
指定了一个输出文件(日志文件),则指定输入文件时没有任何参数切换:尽管如此,正如我在问题中提到的,我有大量的数据要传输,而这些数据不能用简单的sql脚本进行传输。我觉得pg_restore有问题,因为如果我用自定义格式重复这个练习,它仍然挂起。