简体   繁体   English

如何在PostgreSQL中进行功能备份

[英]How to take functions backup in postgresql

I am trying to backup the functions in database using the method described here How to take backup of functions only in Postgres . 我正在尝试使用此处介绍的方法备份数据库中的功能。 如何仅在Postgres中进行功能备份 But it is showing error << was unexpected at this time . 但是它显示错误<< was unexpected at this time

The code I typed in the command prompt is given below. 我在命令提示符下键入的代码如下。

psql.exe -U postgres -At dbname > /path/to/output/file.sql <<"__END__"
SELECT pg_get_functiondef(f.oid)
FROM pg_catalog.pg_proc f
INNER JOIN pg_catalog.pg_namespace n ON (f.pronamespace = n.oid)
WHERE n.nspname = 'public';
__END__

Please help. 请帮忙。

I'm sure there's a way to do it, but the simplest thing is just supply the sql as one line with the -c option: 我敢肯定有一种方法可以做到,但是最简单的方法是使用-c选项将sql作为一行提供:

psql.exe -U postgres -At dbname -c "SELECT pg_get_functiondef(f.oid) FROM pg_catalog.pg_proc f INNER JOIN pg_catalog.pg_namespace n ON (f.pronamespace = n.oid) WHERE n.nspname = 'public'" > /path/to/output/file.sql

This is also more portable and will work with tools that need one line, like cron etc 这也更加便携,可以与需要一行的工具一起使用,例如cron等

This is a shell problem. 这是一个壳问题。

<< is a feature of Unix-like shells, while you seem to be using Windows. <<是类Unix shell的功能,而您似乎正在使用Windows。

Just save the text of the query into a file and run it with the -f flag. 只需将查询文本保存到文件中,然后使用-f标志运行它即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM