我在我的笔记本电脑(Mac)上有大约50GB的Postgres数据库数据,需要将其转移到我的新PC(Windows)上。我已经使用pg_dump生成了需要转移的模式的tar备份文件,但是pg_restore一直卡住。
为了排除文件大小和源系统(Mac)的问题,我将其简化到最简单的测试用例,即在我的PC上创建一个新模式的新表格,在使用pg_dump导出后尝试将其恢复到同一数据库中。即使是这么简单的操作,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输出任何内容 - 已尝试使用详细模式等,但没有效果。
有人知道我接下来应该去哪里找吗?
大卫
psql
运行该脚本,pg_restore
仅适用于自定义和 tar 格式,不适用于 "text" 格式。 - user330315\i
运行它。 - user330315pg_restore
的-f
参数指定了一个输出文件(日志文件),输入文件则不需要任何参数开关来指定。详情请见:https://www.postgresql.org/docs/current/app-pgrestore.html - user330315