#set variables export PATH=$HOME/bin:$PATH #main dbhost=192.168.0.214database=haierdbport=5432 schema=publicdbschema=~/tbctemp/dbschema.txtfiltered=~/tbctemp/dbschema_filtered.txt sql=~/tbctemp/rebuild_indexes.sql rm "$dbschema"; rm "$filtered"; rm "$sql" pg_dump -U postgres -s -h "$dbhost" -p $dbport -n $schema "$database" > "$dbschema" grep -e CREATE\ INDEX -e SET\ search_path "$dbschema" | sed 's/CREATE\ INDEX/CREATE\ INDEX\ CONCURRENTLY/g' > "$filtered"#parallel tmp_fifofile="/tmp/$.fifo"mkfifo $tmp_fifofile exec 6<>$tmp_fifofile rm $tmp_fifofilethread=2 for ((i=0;i<$thread;i++));do echodone >&6 # while read p doread -u6 #if [[ "$p" == SET* ]]; then # echo $p >> "$sql" #else { name=$(cut -d\ -f4 <<<"${p}") drop="DROP INDEX $name;" echo $drop >> "$sql" echo $p >> "$sql" psql -U postgres -h "$dbhost" -p $dbport -d "$database" -c "$drop" psql -U postgres -h "$dbhost" -p $dbport -d "$database" -c "$p" #fi echo >&6 } & done < "$filtered"wait exec 6>&-#psql -U postgres -h "$dbhost" -p $dbport -d "$database" -f "$sql" #rm "$dbschema"#rm "$filtered"#rm "$sql" #end
#set variables
export PATH=$HOME/bin:$PATH
#main
dbhost=192.168.0.214
database=haier
dbport=5432
schema=public
dbschema=~/tbctemp/dbschema.txt
filtered=~/tbctemp/dbschema_filtered.txt
sql=~/tbctemp/rebuild_indexes.sql
rm "$dbschema"; rm "$filtered"; rm "$sql"
pg_dump -U postgres -s -h "$dbhost" -p $dbport -n $schema "$database" > "$dbschema"
grep -e CREATE\ INDEX -e SET\ search_path "$dbschema" | sed 's/CREATE\ INDEX/CREATE\ INDEX\ CONCURRENTLY/g' > "$filtered"
#parallel
tmp_fifofile="/tmp/$.fifo"
mkfifo $tmp_fifofile
exec 6<>$tmp_fifofile
rm $tmp_fifofile
thread=2
for ((i=0;i<$thread;i++));do
echo
done >&6 #
while read p
do
read -u6
#if [[ "$p" == SET* ]]; then
# echo $p >> "$sql"
#else
{
name=$(cut -d\ -f4 <<<"${p}")
drop="DROP INDEX $name;"
echo $drop >> "$sql"
echo $p >> "$sql"
psql -U postgres -h "$dbhost" -p $dbport -d "$database" -c "$drop"
psql -U postgres -h "$dbhost" -p $dbport -d "$database" -c "$p"
#fi
echo >&6
} &
done < "$filtered"
wait
exec 6>&-
#psql -U postgres -h "$dbhost" -p $dbport -d "$database" -f "$sql"
#rm "$dbschema"
#rm "$filtered"
#rm "$sql"
#end
On Wed, Dec 18, 2013 at 4:24 AM, Campbell, Lance <lance@illinois.edu> wrote:Below is a Linux script I wrote that will drop and create all of the indexes for your database with the “concurrently” parameter. #!/bin/sh dbhost=localhostdatabase=somedatabasenamedbschema=/tempfile/dbschema.txtfiltered=/tempfile/dbschema_filtered.txtsql=/tempfile/rebuild_indexes.sql rm "$dbschema"rm "$filtered"rm "$sql" pg_dump -s -h "$dbhost" "$database" > "$dbschema" Great script ! i think you can add parallel perform each couple (drop & create index). ^^
Below is a Linux script I wrote that will drop and create all of the indexes for your database with the “concurrently” parameter. #!/bin/sh dbhost=localhostdatabase=somedatabasenamedbschema=/tempfile/dbschema.txtfiltered=/tempfile/dbschema_filtered.txtsql=/tempfile/rebuild_indexes.sql rm "$dbschema"rm "$filtered"rm "$sql" pg_dump -s -h "$dbhost" "$database" > "$dbschema"
Below is a Linux script I wrote that will drop and create all of the indexes for your database with the “concurrently” parameter.
#!/bin/sh
dbhost=localhost
database=somedatabasename
dbschema=/tempfile/dbschema.txt
filtered=/tempfile/dbschema_filtered.txt
sql=/tempfile/rebuild_indexes.sql
rm "$dbschema"
rm "$filtered"
rm "$sql"
pg_dump -s -h "$dbhost" "$database" > "$dbschema"
pgsql-admin by date:
Соглашаюсь с условиями обработки персональных данных