Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql pg_仅还原某些表_Postgresql_Hstore_Pg Restore - Fatal编程技术网

Postgresql pg_仅还原某些表

Postgresql pg_仅还原某些表,postgresql,hstore,pg-restore,Postgresql,Hstore,Pg Restore,我正试图编写一个pg_restore命令,只将某些表(及其数据)恢复到我的数据库中 注意:描述的每个命令都以我删除并重新创建数据库开始,并以:-v-x-O-j 8-h localhost-U username-d database file.dump(出于好奇,我不想使用--clean,因为转储所来自的数据库具有不同的名称。) 由于pg_restore对我来说效果很好(使用上述参数),我查看了,并尝试了以下方法: pg\u restore-t table 1-t table 2…(我以这种方式指

我正试图编写一个
pg_restore
命令,只将某些表(及其数据)恢复到我的数据库中

注意:描述的每个命令都以我删除并重新创建数据库开始,并以:
-v-x-O-j 8-h localhost-U username-d database file.dump
(出于好奇,我不想使用
--clean
,因为转储所来自的数据库具有不同的名称。)

由于
pg_restore
对我来说效果很好(使用上述参数),我查看了,并尝试了以下方法:

pg\u restore-t table 1-t table 2…
(我以这种方式指定了121个表)

但是,我会遇到如下错误:

pg_restore: creating TABLE people
pg_restore: [archiver (db)] Error from TOC entry 123; 1234 12345 TABLE people dumped_table_username
pg_restore: [archiver (db)] could not execute query: ERROR:  type "hstore" does not exist
LINE 14:     extra_data hstore,
                        ^
    Command was: CREATE TABLE people (
    id integer NOT NULL,
    name string,
    age integer,
    date_of_birt...
我不明白为什么只有当设置了
-t
标志时,这才是一个问题,但它似乎是

发生什么事了



编辑:看起来这是的一个副本,它最近被询问过,目前还没有被接受的答案。

显然,带有
-t
/
--table
标志集的
pgu restore
不会运行转储文件中的
创建扩展名
命令(因为从技术上讲,它们不是该表的一部分)。我的问题是通过在
pg_restore
命令之前手动运行
psql数据库-c“CREATE EXTENSION hstore;”“
”。

…从我删除并重新创建数据库开始,到…
结束,您的意思是“删除并重新创建表”不,我指的是整个数据库。我使用的是Rails,所以
rake db:drop&&rake db:create
。如果删除数据库,那么
hstore
扩展也会被删除。在重新创建数据库之后(以及恢复转储之前)是否运行
create extension hstore
?我认为恢复会解决这个问题,因为它对整个数据库恢复(即不带
-t
标志的
pg_restore
),并且转储文件包括
CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public;
。显然不是。添加
psql数据库-c“CREATE EXTENSION hstore;”
pg_restore
之前调用修复此问题。如果您定期这样做,您可能希望在template1数据库中创建hstore扩展。这样,每个新数据库都会自动安装hstore扩展。啊,我不知道!如果您回答这个问题,我会接受它。