Re: On login trigger: take three

From: Alexander Lakhin <exclusion(at)gmail(dot)com>
To: Alexander Korotkov <aekorotkov(at)gmail(dot)com>, Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Mikhail Gribkov <youzhick(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Greg Nancarrow <gregn4422(at)gmail(dot)com>, Ivan Panchenko <wao(at)mail(dot)ru>, Teodor Sigaev <teodor(at)sigaev(dot)ru>, Ibrar Ahmed <ibrar(dot)ahmad(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Subject: Re: On login trigger: take three
Date: 2024-01-23 18:00:01
Message-ID: e2a0248e-5f32-af0c-9832-a90d303c2c61@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello Alexander and Daniel,

Please look at the following query, which triggers an assertion failure on
updating the field dathasloginevt for an entry in pg_database:
SELECT format('CREATE DATABASE db1 LOCALE_PROVIDER icu ICU_LOCALE en ENCODING utf8
ICU_RULES ''' || repeat(' ', 200000) || ''' TEMPLATE template0;')
\gexec
\c db1 -

CREATE FUNCTION on_login_proc() RETURNS event_trigger AS $$
BEGIN
  RAISE NOTICE 'You are welcome!';
END;
$$ LANGUAGE plpgsql;

CREATE EVENT TRIGGER on_login_trigger ON login EXECUTE PROCEDURE on_login_proc();
DROP EVENT TRIGGER on_login_trigger;

\c

\connect: connection to server on socket "/tmp/.s.PGSQL.5432" failed: server closed the connection unexpectedly

The stack trace of the assertion failure is:
...
#5  0x000055c8699b9b8d in ExceptionalCondition (
    conditionName=conditionName(at)entry=0x55c869a1f7c0 "HaveRegisteredOrActiveSnapshot()",
    fileName=fileName(at)entry=0x55c869a1f4c6 "toast_internals.c", lineNumber=lineNumber(at)entry=669) at assert.c:66
#6  0x000055c86945df0a in init_toast_snapshot (...) at toast_internals.c:669
#7  0x000055c86945dfbe in toast_delete_datum (...) at toast_internals.c:429
#8  0x000055c8694fd1da in toast_tuple_cleanup (...) at toast_helper.c:309
#9  0x000055c8694b55a1 in heap_toast_insert_or_update (...) at heaptoast.c:333
#10 0x000055c8694a8c6c in heap_update (... at heapam.c:3604
#11 0x000055c8694a96cb in simple_heap_update (...) at heapam.c:4062
#12 0x000055c869555b7b in CatalogTupleUpdate (...) at indexing.c:322
#13 0x000055c8695f0725 in EventTriggerOnLogin () at event_trigger.c:957
...

Funnily enough, when Tom Lane was wondering, whether pg_database's toast
table could pose a risk [1], I came to the conclusion that it's impossible,
but that was before the login triggers introduction...

[1] https://www.postgresql.org/message-id/1284094.1695479962%40sss.pgh.pa.us

Best regards,
Alexander

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2024-01-23 18:10:27 Re: FEATURE REQUEST: Role vCPU limit/priority
Previous Message Tomas Vondra 2024-01-23 17:43:25 Re: index prefetching