HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to restore function using PG_RESTORE

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
restorefunctionusinghowpg_restore

Problem

I did the backup of my database:

-bash-4.2$ pg_dump -d mydb --format=custom -f /tmp/dump 
-bash-4.2$


Below checked and I saw my functions there:

-bash-4.2$ pg_restore -l /tmp/dump | grep -i addconf
233; 1255 39949 FUNCTION public addconfiguration(text) mydb
247; 1255 39950 FUNCTION public addconfiguration2(text) mydb
273; 1255 39951 FUNCTION public addconfiguration3(text) mydb


Then I tried to restore one function using the Postgres pg_restore instructions:

-bash-4.2$ pg_restore -d postgres --function=addconfiguration2(text) -v /tmp/dump 
-bash: syntax error near unexpected token `('


I also tried without the parentheses and the arg, but it didn't work:

-bash-4.2$ pg_restore -d postgres --function=addconfiguration2 -v /tmp/dump 
pg_restore: connecting to database for restore
pg_restore: implied data-only restore


After the attempts I verified if the function was created using \df inside psql, but without success.

How could I restore functions using pg_restore?

Solution

The parenthesis is special to the shell. You don't have to remove it, you have to quote/escape it to get it to pass through the shell.

pg_restore -d postgres --function='addconfiguration2(text)' -v /tmp/dump

Code Snippets

pg_restore -d postgres --function='addconfiguration2(text)' -v /tmp/dump

Context

StackExchange Database Administrators Q#207656, answer score: 2

Revisions (0)

No revisions yet.