How to exclude PL/pgSQL functions in export?

后端 未结 3 955
感情败类
感情败类 2021-01-16 13:00

I use following command to dump some structures from server\' database to be able to create sample of data on my local hard drive.

pg_dump -h myserver.com -U         


        
相关标签:
3条回答
  • 2021-01-16 13:51

    There is a way to do it. Say your backup is named backup.dump. What you need to do is:

    $ pg_restore -l -f out.txt backup.dump
    

    That will create a file out.txt that contains a list of objects that are in the dump. You need to edit the file and delete the items you don't want restored. Then you do this:

    $ pg_restore -L out.txt -h your.host.name -U username ....  backup.dump
    

    This will use a file out.txt (that you edited) to select the things that will be restored. Pretty handy especially in case the dump is large and you cannot re-dump the database.

    0 讨论(0)
  • 2021-01-16 14:00

    In addition to the answer from Bartosz above, you can use the following sed command to remove e.g. a certain FUNCTION from the list before restoring:

    sed -r -i -e '/FUNCTION public plpgsql_call_handler\(\) postgres/d' /var/backup/${DBNAME}.list 
    
    0 讨论(0)
  • 2021-01-16 14:03

    I need to exclude some schemas

    pg_dump has a switch to exclude schemas:

    pg_dump -N schema ...
    

    I quote the manual about pg_dump:

    -N schema
    --exclude-schema=schema

    Do not dump any schemas matching the schema pattern. The pattern is interpreted according to the same rules as for -n. -N can be given more than once to exclude schemas matching any of several patterns.
    ...


    With PostgreSQL 9.1 or later you have new options to move extensions into a separate schema - even pre-installed old-style modules. You can register old object with your (new-style) extension and then use the new tools. With fulltext and similarity you probably mean fuzzystrmatch and tsearch2. Example:

    Register existing old-style objects for the extension fuzzystrmatch:

    CREATE EXTENSION fuzzystrmatch SCHEMA public FROM unpackaged;
    

    Drop the extension:

    DROP EXTENSION fuzzystrmatch;
    

    Install it to another schema:

    CREATE EXTENSION fuzzystrmatch SCHEMA my_schema;
    

    Of course, you cannot drop the extension, if objects from it are in use.
    Also, if you install to another schema, you need to schema-qualify its functions in use or add the schema to the search_path.

    0 讨论(0)
提交回复
热议问题