简体   繁体   中英

Calling postgres command like pg_restore or pg_dump form sql file

I need to run postgres command like pg_restore or pg_dump in sql files.

I have few insert statement and after that I would like to run pg_dump after that in same sql file.

Command to run pg_dump is

pg_dump -p5444 -U"username" -Fc -hhost-name  -d Database_name -t TABLENAME > location\abcd5.dump

How can I run the same with in sql file?

The machine I am using is unix.

It is possible to achieve what you want, but it is not possible to do it the way you want.

Use a file you can run in your shell, for example bash (.sh) since you're on a Unix system.

In that file you can run your sql file with psql and pg_dump command afterwards.

The shell file could look something like this:

psql -p <port> -U <username> -h <host-name> -d <database-name> <sql-file>
pg_dump -p5444 -U "username" -Fc -hhost-name  -d Database_name -t TABLENAME > location\abcd5.dump

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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