shell脚本
#/bin/sh
# 获取数据库密码,根据实际情况,需要修改
export_pgpasswd()
{
if [ -f /usr/local/svconfig/server/conf/imos.cfg ]
then
dbpasswd=`cat /usr/local/svconfig/server/conf/imos.cfg | grep DBPassword | awk -F "=" '{ print $2}'`
dbpasswd=`/usr/local/bin/unipd 1 ${dbpasswd}`
if [ ""x = "$dbpasswd"x ]
then
echo " `date +"%Y-%m-%d %H:%M:%S"` --> error: do passwd error, DBPassword not in imos.cfg" >> ${LOGFILE} 2>&1
exit 1
fi
export PGPASSWORD=$dbpasswd
else
export PGPASSWORD=passwd
fi
}
export_pgpasswd
WORK_PATH=`pwd`
/home/postgres/pgsql/bin/psql -U postgres -f ${WORK_PATH}/test.sql
被调用的SQL脚本
test.sql
create or replace function fun_test() returns integer as
$BODY$
begin
xxx(具体实现代码)
return 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
select * from fun_test();