How to take backup of functions only in Postgres

后端 未结 2 1337
孤街浪徒
孤街浪徒 2020-12-13 10:21

I want to take backup of all functions in my postgres database.How to take backup of functions only in Postgres?

2条回答
  •  没有蜡笔的小新
    2020-12-13 10:54

    You can't tell pg_dump to dump only functions. However, you can make a dump without data (-s) and filter it on restoring. Note the -Fc part: this will produce a file suitable for pg_restore.

    First take the dump:

    pg_dump -U username -Fc -s -f dump_test your_database
    

    Then create a list of the functions:

    pg_restore -l dump_test | grep FUNCTION > function_list
    

    And finally restore them (-L specifies the list file created above):

    pg_restore -U username -d your_other_database -L function_list dump_test
    

提交回复
热议问题