pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Payal Singh <payal@omniti.com>
To: Doom.zhou <zzepaigh@gmail.com>
Cc: Campbell, Lance <lance@illinois.edu>
Cc: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: script to drop and create all indexes in a database with parameter concurrently
Date: Wed, 18 Dec 2013 10:04:13 -0500
Message-ID: <20131218150413.GA19712@payal-ThinkPad-T520> (raw )
In-Reply-To: <CAK=muZvbJDD_GNfrWt0ZRFko0DEC6PmOXKcpA8muT54cT3pchQ@mail.gmail.com >
References: <B75CD08C73BD3543B97E4EF3964B7D701F65D459@CITESMBX1.ad.uillinois.edu >
<CAK=muZv5yG3t=Gr1sBNiXvXNyoboVvUW_n1b9Xfg4axniobS2g@mail.gmail.com >
<CAK=muZvbJDD_GNfrWt0ZRFko0DEC6PmOXKcpA8muT54cT3pchQ@mail.gmail.com >
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>
Why don't you simply use a bash script that:
1. gets list of all indexes in a file with prefix 'DROP INDEX...<index_name'
2. Since now each line is a command, input this file to psql.
On Wed, Dec 18, 2013 at 03:43:01PM +0800, Doom.zhou wrote:
> oh my fault !!it's horrible
> *ERROR: deadlock detected*
> *DETAIL: Process 10504 waits for ShareUpdateExclusiveLock on relation
> 23298 of database 16407; blocked by process 10502.*
> * Process 10502 waits for ShareLock on virtual transaction 2/6981;
> blocked by process 10504.*
> * Process 10504: CREATE INDEX CONCURRENTLY t_ems_log_opt_time_idx ON
> t_ems_log USING btree (opt_time);*
> * Process 10502: CREATE INDEX CONCURRENTLY t_ems_log_create_by_idx
> ON t_ems_log USING btree (create_by);*
> *HINT: See server log for query details.*
> *STATEMENT: CREATE INDEX CONCURRENTLY t_ems_log_opt_time_idx ON t_ems_log
> USING btree (opt_time);*
>
> *parallel feature script *
>
>
> >>
> >>
> >>
> >>
> >>
> > *#set variablesexport
> > PATH=$HOME/bin:$PATH#main dbhost=192.168.0.214database=haierdbport=5432schema=publicdbschema=~/tbctemp/dbschema.txtfiltered=~/tbctemp/dbschema_filtered.txtsql=~/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=2for
> > ((i=0;i<$thread;i++));do echodone >&6 # while read pdoread -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"waitexec 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 2:19 PM, Doom.zhou <zzepaigh@gmail.com> wrote:
>
> >
> >
> >
> > 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=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"
> >>
> >>
> >>
> > Great script !
> > i think you can add parallel perform each couple (drop & create index). ^^
> >
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
view thread (7+ messages) latest in thread
Message-ID: <20131218150413.GA19712@payal-ThinkPad-T520>
Permalink: ../20131218150413.GA19712@payal-ThinkPad-T520/
Also on: postgresql.org/message-id/20131218150413.GA19712@payal-ThinkPad-T520
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: payal@omniti.com, zzepaigh@gmail.com, lance@illinois.edu
Subject: Re: script to drop and create all indexes in a database with parameter concurrently
In-Reply-To: <20131218150413.GA19712@payal-ThinkPad-T520>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox