pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedDropping and creating a trigger
4+ messages / 3 participants
[nested] [flat]
* Dropping and creating a trigger
@ 2019-01-05 09:59 Mitar <mmitar@gmail.com>
2019-01-05 10:16 ` Re: Dropping and creating a trigger Ron <ronljohnsonjr@gmail.com>
2019-01-05 17:35 ` Re: Dropping and creating a trigger Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 2 replies; 4+ messages in thread
From: Mitar @ 2019-01-05 09:59 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hi!
I am seeing such errors in logs:
ERROR: trigger "myapp_assignments" for relation "assignments" already exists
STATEMENT:
BEGIN TRANSACTION;
DROP TRIGGER IF EXISTS "myapp_assignments" ON "assignments";
CREATE TRIGGER "myapp_assignments"
AFTER INSERT OR UPDATE OR DELETE ON "assignments"
FOR EACH ROW EXECUTE PROCEDURE "tblobs_myapp"();
COMMIT;
How is this possible? If I am inside a transaction, this should work, no?
Mitar
--
http://mitar.tnode.com/
https://twitter.com/mitar_m
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Dropping and creating a trigger
2019-01-05 09:59 Dropping and creating a trigger Mitar <mmitar@gmail.com>
@ 2019-01-05 10:16 ` Ron <ronljohnsonjr@gmail.com>
1 sibling, 0 replies; 4+ messages in thread
From: Ron @ 2019-01-05 10:16 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 1/5/19 3:59 AM, Mitar wrote:
> Hi!
>
> I am seeing such errors in logs:
>
> ERROR: trigger "myapp_assignments" for relation "assignments" already exists
> STATEMENT:
> BEGIN TRANSACTION;
> DROP TRIGGER IF EXISTS "myapp_assignments" ON "assignments";
> CREATE TRIGGER "myapp_assignments"
> AFTER INSERT OR UPDATE OR DELETE ON "assignments"
> FOR EACH ROW EXECUTE PROCEDURE "tblobs_myapp"();
> COMMIT;
>
> How is this possible? If I am inside a transaction, this should work, no?
I'd think it should. Have you run the commands manually, one at a time,
from psql, and checking the table after the DROP TRIGGER, to verify that the
trigger actually gets dropped?
--
Angular momentum makes the world go 'round.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Dropping and creating a trigger
2019-01-05 09:59 Dropping and creating a trigger Mitar <mmitar@gmail.com>
@ 2019-01-05 17:35 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-01-05 22:25 ` Re: Dropping and creating a trigger Mitar <mmitar@gmail.com>
1 sibling, 1 reply; 4+ messages in thread
From: Adrian Klaver @ 2019-01-05 17:35 UTC (permalink / raw)
To: Mitar <mmitar@gmail.com>; pgsql-general@lists.postgresql.org
On 1/5/19 1:59 AM, Mitar wrote:
> Hi!
>
> I am seeing such errors in logs:
>
> ERROR: trigger "myapp_assignments" for relation "assignments" already exists
> STATEMENT:
> BEGIN TRANSACTION;
> DROP TRIGGER IF EXISTS "myapp_assignments" ON "assignments";
> CREATE TRIGGER "myapp_assignments"
> AFTER INSERT OR UPDATE OR DELETE ON "assignments"
> FOR EACH ROW EXECUTE PROCEDURE "tblobs_myapp"();
> COMMIT;
>
> How is this possible? If I am inside a transaction, this should work, no?
Works here:
select version();
version
------------------------------------------------------------------------------------
PostgreSQL 10.6 on x86_64-pc-linux-gnu, compiled by gcc (SUSE Linux)
4.8.5, 64-bit
test=# begin;
BEGIN
test=# drop trigger if exists test_trigger on trigger_test;
DROP TRIGGER
test=# create trigger test_trigger BEFORE INSERT ON trigger_test FOR
EACH ROW WHEN (new.id > 10) EXECUTE PROCEDURE trigger_test()
test-# ;
NOTICE: caught CREATE TRIGGER event on 'test_trigger on
public.trigger_test'
CREATE TRIGGER
test=# commit ;
COMMIT
So:
1) Postgres version?
2) Is this one of your 'temporary' trigger/function combos?
>
>
> Mitar
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Dropping and creating a trigger
2019-01-05 09:59 Dropping and creating a trigger Mitar <mmitar@gmail.com>
2019-01-05 17:35 ` Re: Dropping and creating a trigger Adrian Klaver <adrian.klaver@aklaver.com>
@ 2019-01-05 22:25 ` Mitar <mmitar@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Mitar @ 2019-01-05 22:25 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general@lists.postgresql.org
Hi!
On Sat, Jan 5, 2019 at 9:35 AM Adrian Klaver <adrian.klaver@aklaver.com> wrote:
> > How is this possible? If I am inside a transaction, this should work, no?
>
> Works here:
I thought so. This is being run in parallel multiple times by a
benchmarking tool I made. So it is not just done once, but many times
(50x) at almost the same time.
> select version();
> version
PostgreSQL 11.1 (Debian 11.1-1.pgdg90+1) on x86_64-pc-linux-gnu,
compiled by gcc (Debian 6.3.0-
18+deb9u1) 6.3.0 20170516, 64-bit
In fact, using this Docker image [1] with two patches applied (the
ones I currently have in commitfest). I think they are unrelated to
this problem.
> 2) Is this one of your 'temporary' trigger/function combos?
No. I was trying to fix this code of a package I found. [1] Which
currently does not work well because, again, if it runs multiple times
in parallel, then it happens that sometimes the same trigger tries to
be created twice in a row, failing the second time. So I tried to fix
it by wrapping it into a transaction, but then surprisingly didn't
work.
To reproduce this (if people are interested), I think, you could try:
- try using the Docker image [1]
- clone this benchmarking tool [2]
- after installing, modifying
node_modules/pg-table-observer/dist/PgTableObserver.js to try
BEGIN/COMMIT around the block, see attached patch
- maybe modify index.js to provide connection information to connect
to your PostgreSQL instance, CONN_STR variable
- run: node --experimental-worker --expose-gc index.js pg-query-observer
- ignore errors from the app, check PostgreSQL logs
[1] https://github.com/mitar/docker-postgres
[2] https://github.com/Richie765/pg-table-observer/blob/master/src/PgTableObserver.js#L199
[3] https://github.com/mitar/node-pg-reactivity-benchmark
(How can this thread be moved to bugs mailing list?)
Mitar
--
http://mitar.tnode.com/
https://twitter.com/mitar_m
Attachments:
tx.patch (text/x-patch, 1.0K) download
--- node_modules/pg-table-observer/dist/PgTableObserver.js.orig 2019-01-05 14:11:33.303140087 -0800
+++ node_modules/pg-table-observer/dist/PgTableObserver.js 2019-01-05 14:19:24.817530060 -0800
@@ -373,7 +373,7 @@
trigger_name = channel + '_' + table;
_context4.prev = 2;
_context4.next = 5;
- return db.none('\n CREATE TRIGGER $1~\n AFTER INSERT OR UPDATE OR DELETE ON $2~\n FOR EACH ROW EXECUTE PROCEDURE $3~()\n ', [trigger_name, table, _this2.trigger_func]);
+ return db.none('\n BEGIN; DROP TRIGGER IF EXISTS "' + trigger_name + '" ON "' + table + '"; CREATE TRIGGER "' + trigger_name + '"\n AFTER INSERT OR UPDATE OR DELETE ON "' + table + '"\n FOR EACH ROW EXECUTE PROCEDURE "' + _this2.trigger_func + '"(); COMMIT;\n ');
case 5:
_context4.next = 9;
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2019-01-05 22:25 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-01-05 09:59 Dropping and creating a trigger Mitar <mmitar@gmail.com>
2019-01-05 10:16 ` Ron <ronljohnsonjr@gmail.com>
2019-01-05 17:35 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-01-05 22:25 ` Mitar <mmitar@gmail.com>
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