PostgreSQL pg_dump

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9382821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:19:48  来源:igfitidea点击:

PostgreSQL pg_dump

postgresql

提问by user1202766

I am trying to create a database backup using the command

我正在尝试使用该命令创建数据库备份

pg_dump -U vdc(old db) | psql vdc_bak.sql(backup db);

What's wrong with the syntax here?

这里的语法有什么问题?

It tells "syntax error near pg_dump"

它告诉“pg_dump 附近的语法错误”

回答by a_horse_with_no_name

You still don't show us the big picture, but the "syntax error" seems to indicate that you run that from within a SQL client tool (psql, pgAdmin, ...)

您仍然没有向我们展示大图,但“语法错误”似乎表明您是从 SQL 客户端工具(psql、pgAdmin 等)中运行它的

pg_dumpand psqlare commandlineprograms, not SQL statements.

pg_dumppsql命令行程序,而不是 SQL 语句。

You need to run them from the command prompt (aka shell)

您需要从命令提示符(又名 shell)运行它们

Additionally the (old db)parameter is completely wrong. The database is not put into brackets for pg_dump, e.g:

此外(旧数据库)参数是完全错误的。数据库没有放在 pg_dump 的括号中,例如:

pg_dump -U user1 dbname_old_db | psql -U user2 dbname_new_db

Again: you have to run this from the command prompt, not from within a SQL tool

再次:您必须从命令提示符运行它,而不是从 SQL 工具中运行

回答by zgpmax

From the error message syntax error near pg_dumpand the fact that you ended your command line with a semicolon, it looks like you are trying to run pg_dumpfrom withinpsql.

从错误信息syntax error near pg_dump,并且你结束你的命令行用分号事实上,它看起来像你正在尝试运行pg_dumpPSQL。

This won't work. You need to run your command at the shell (e.g. bash) prompt.

这行不通。您需要在 shell(例如bash)提示符下运行您的命令。

(As an aside, providing the text of your error message (syntax error near pg_dump) was pivotal in diagnosing this issue. Your original question did not include it, and no-one was able to help. Once you added the text, you had an answer within a few minutes.)

(顺便说一句,提供错误消息的文本(pg_dump 附近的语法错误)对于诊断此问题至关重要。您的原始问题未包含它,并且没有人能够提供帮助。添加文本后,您就在几分钟内得到答复。)