How can I take only PostgreSQL functions & procedure backup
You can’t take PostgreSQL functions backup like wise as tables in postgresql.
You can use the below query to get all the function definitions from following script.
# Config:
DB="LC"
U=enterprisedb
export PGPASSWORD="tcs@345"
export PGPORT="5544"
export PGHOST="10.0.4.101"
nijam="/home/Admin/"
logfile="nijam33".sql
/opt/edb/as9.6/bin/psql -d $DB -U $U -t -c "SELECT FORMAT(
'\COPY (SELECT regexp_split_to_table(regexp_replace(pg_get_functiondef(%s), ''\t'', '' '', ''g''), ''\n'')) TO /home/Admin/2ndquadrant.in/LC/schemas/amb/functions_procedures/amb.%s',
pp.oid,
pp.proname
)
from pg_proc pp
inner join pg_namespace pn on (pp.pronamespace = pn.oid)
inner join pg_language pl on (pp.prolang = pl.oid)
WHERE PN.NSPNAME = 'amb'" >>$nijam/$logfile 2>&1
/opt/edb/as9.6/bin/psql -d $DB -U $U -t -c "\i /home/Admin/nijam33.sql"
# Successfully completed the procedure & function backup
You can also take functions backup through Linux command line.
# First, make a dump of the database without data (-s)
pg_dump -h localhost -u username -fc -s -f db_dump dbname
# Create a list of the functions
pg_restore -l db_dump | grep FUNCTION > function_list
# Restore the functions in an other database
pg_restore -h localhost -u username -d other-dbname -l function_list db_dump
FOR IT SUPPORT