...
rem Target directory for exports
set MyDir=D:\Trezors_export\
rem Set PGPASSWORD to password assigned to D2000 user
set PGPASSWORD=%D2000_DBPASS%
set PGUSER=%D2000_DBUSER%
rem Set PATH to PostgreSQL installation (version-dependent)
set PATH=%PATH%;c:\Program Files\PostgreSQL\13\bin
rem export of table trezors from the archive database
pg_dump -Fc -U %D2000_DBUSER% -f "%MyDir%\MyApp_arc_trezors.dmp" --table \"trezors\" MyApp.Archiv >> %MyDir%\%1.log
rem permit write access to depository database and cluster the data table
echo alter database "%1" set default_transaction_read_only=false | psql -S -U %D2000_DBUSER% MyApp.Archiv >> %MyDir%\%1.log
echo alter table data cluster on ix_data_rc | psql -S -U postgres %1 >> %MyDir%\%1.log
echo cluster data | psql -S -U %D2000_DBUSER% %1 >> %MyDir%\%1.log
rem set access to depository database back to read only
echo alter database "%1" set default_transaction_read_only=true | psql -S -U %D2000_DBUSER% MyApp.Archiv >> %MyDir%\%1.log
pg_dump -Fc -U %D2000_DBUSER% -f "%MyDir%\%1.dmp" %1 >> %MyDir%\%1.log
...
#!/usr/bin/env bash
MyDir=/trezorbackup
MyArc=mes_tpd_archive_self
MyLog=$MyDir/$1.log
#path to pg_dump, psql etc
PATH=/usr/pgsql-11/bin:$PATH
#password for dba user
export PGPASSWORD=$D2000_DBPASS
export PGUSER=$D2000_DBUSER
#export of table trezors from the archive database
pg_dump -Fc -U $D2000_DBUSER -f "$MyDir/arc_trezors.dmp" --table \"trezors\" $MyArc >> $MyLog
#permit write access to depository database and cluster the data table
echo alter database \"$1\" set default_transaction_read_only=false | psql -S -U $D2000_DBUSER $MyArc >> $MyLog
echo alter table data cluster on ix_data_rc | psql -S -U $D2000_DBUSER "$1" >> $MyLog
echo cluster data | psql -S -U $D2000_DBUSER "$1" >> $MyLog
#set access to depository database back to read only
echo alter database \"$1\" set default_transaction_read_only=true | psql -S -U $D2000_DBUSER $MyArc >> $MyLog
#execute dump of depository database
pg_dump -Fc -U $D2000_DBUSER -f "$MyDir/$1.dmp" "$1" >> $MyLog