From: | aditya desai <admad123(at)gmail(dot)com> |
---|---|
To: | MichaelDBA <MichaelDBA(at)sqlexec(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pgsql Performance <pgsql-performance(at)lists(dot)postgresql(dot)org> |
Subject: | Re: ALTER STATEMENT getting blocked |
Date: | 2023-01-22 11:29:14 |
Message-ID: | CAN0SRDFWZ5Ptnufz=Rw3BK5VgO4uXpXpGKBfsBJacZNgBHx-DQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Thanks All. Let me check this and get back to you.
On Fri, Jan 20, 2023 at 2:36 AM MichaelDBA <MichaelDBA(at)sqlexec(dot)com> wrote:
> Do something like this to get it without being behind other
> transactions...You either get in and get your work done or try again
>
> DO language plpgsql $$
> BEGIN
> FOR get_lock IN 1 .. 100 LOOP
> BEGIN
> ALTER TABLE mytable <do something>;
> EXIT;
> END;
> END LOOP;
> END;
> $$;
>
>
>
> Tom Lane wrote on 1/19/2023 12:45 PM:
>
> aditya desai <admad123(at)gmail(dot)com> <admad123(at)gmail(dot)com> writes:
>
> We have a Postgres 11.16 DB which is continuously connected to informatica
> and data gets read from it continuously.
>
> When we have to ALTER TABLE.. ADD COLUMN.. it gets blocked by the SELECTs
> on the table mentioned by process above.
>
> Is there any way to ALTER the table concurrently without getting blocked?
> Any parameter or option? Can someone give a specific command?
>
> ALTER TABLE requires exclusive lock to do that, so it will queue up
> behind any existing table locks --- but then new lock requests will
> queue up behind its request. So this'd only happen if your existing
> reading transactions don't terminate. Very long-running transactions
> are unfriendly to other transactions for lots of reasons including
> this one; see if you can fix your application to avoid that. Or
> manually cancel the blocking transaction(s) after the ALTER begins
> waiting.
>
> regards, tom lane
>
>
>
>
>
> Regards,
>
> Michael Vitale
>
> Michaeldba(at)sqlexec(dot)com <michaelvitale(at)sqlexec(dot)com>
>
> 703-600-9343
>
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | aditya desai | 2023-01-22 11:33:46 | LIKE CLAUSE on VIEWS |
Previous Message | MichaelDBA | 2023-01-19 21:06:17 | Re: ALTER STATEMENT getting blocked |