PostgreSQL 转储临时表
我使用以下查询在 PostgreSQL 数据库中创建了一个临时表。
SELECT * INTO TEMP TABLE tempdata FROM data WHERE id=2004;
现在我想创建此临时表tempdata
的备份。
因此,我使用以下命令行执行
"C:\Program Files\PostgreSQL\9.0\bin\pg_dump.exe" -F t -a -U my_admin -t tempdata myDB >"e:\mydump.backup"
,收到一条消息:
pg_dump: No matching tables were found
Is it possible to create a dump of temp table
?
我做得正确吗?
PS:我也想恢复相同的内容。我不想使用任何额外的组件。
TIA。
I created a temp table in my PostgreSQL DB using the following query
SELECT * INTO TEMP TABLE tempdata FROM data WHERE id=2004;
Now I want to create a backup of this temp table tempdata
.
So i use the following command line execution
"C:\Program Files\PostgreSQL\9.0\bin\pg_dump.exe" -F t -a -U my_admin -t tempdata myDB >"e:\mydump.backup"
I get a message saying
pg_dump: No matching tables were found
Is it possible to create a dump of temp tables
?
Am I doing it correctly?
P.S. : I would also want to restore the same.I don't want to use any extra components.
TIA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您无法将 pg_dump 用于该临时表。问题是 临时表仅存在于创建它们的会话中:
因此,您可以在一个会话中创建临时表,但
pg_dump
将使用没有临时表的另一会话。但是,
COPY
应该可以工作:但您可以将数据复制到标准输出或数据库服务器上的文件(需要超级用户访问权限):
因此,使用 COPY 将临时表直接转储到文件可能不是一个选择。您可以复制到标准输出,但效果如何取决于您访问数据库的方式。
如果您不使用临时表,您可能会有更好的运气。当然,您必须管理唯一的表名称以避免与其他会话发生冲突,并且您必须小心确保非临时临时表在使用完毕后被删除。
I don't think you'll be able to use
pg_dump
for that temporary table. The problem is that temporary tables only exist within the session where they were created:So you'd create the temporary table in one session but
pg_dump
would be using a different session that doesn't have your temporary table.However,
COPY
should work:but you'll either be copying the data to the standard output or a file on the database server (which requires superuser access):
So using COPY to dump the temporary table straight to a file might not be an option. You can COPY to the standard output though but how well that will work depends on how you're accessing the database.
You might have better luck if you didn't use temporary tables. You would, of course, have to manage unique table names to avoid conflicts with other sessions and you'd have to take care to ensure that your non-temporary temporary tables were dropped when you were done with them.