Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sZA8W-00GonS-Bk for pgsql-hackers@arkaria.postgresql.org; Wed, 31 Jul 2024 14:17:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sZA8U-007kUL-Lp for pgsql-hackers@arkaria.postgresql.org; Wed, 31 Jul 2024 14:17:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sZA8T-007kSr-Ux for pgsql-hackers@lists.postgresql.org; Wed, 31 Jul 2024 14:17:02 +0000 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sZA8Q-002OBP-TV for pgsql-hackers@postgresql.org; Wed, 31 Jul 2024 14:17:00 +0000 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-816d9285ebdso237477939f.0 for ; Wed, 31 Jul 2024 07:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilm.com; s=google; t=1722435418; x=1723040218; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=z5NQjG7Ao1tw05KMUGp6MI0V9NR0T6mUMXlIgXgoflE=; b=NkpfDiuyFMTiha5RWQ1PnJ3UifJz+5ILMrGE3wM2dra1l7H0q6lXYPEJd2Yo14R2oD e0YwuZsopRaIfGNCd3DqdJDj7ENDw3xb6VHMunLH94OvwabmLwu1FqbFhEgTSlZG8wxA g3Ni3bDAYlFfq6yv+KgVa8xu+KD5iCP3lXs7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722435418; x=1723040218; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=z5NQjG7Ao1tw05KMUGp6MI0V9NR0T6mUMXlIgXgoflE=; b=h7tEdo/bKfw7SyRoRzscAYPtttRud+XPrkzsnSMNkUG9s8tou3yA95G9uGzig1gZa3 Ne4PzACXkIsaStTaCw10I8df2YIOl+EljbPOFDRhFnbdhcUb0Stj98uk0+c7u66tl+aO RVjaWgRhV5H5BQV+BLvQo50pIzxlKIjMLOG8ySjtOizfu2SK3j5pnwk+5Q6O3Td4zAGb 1VOgRkYcJg7XKEDwsr60rvt+Hub6OvxYPopvTQAWYXTV2fbXBDMMfvMlgmcFyM3UOdZI gecQs5NQp05VaxZlS8Ah3ykqV/uLpGC/YZ7xSwFFgdOudUHq0HrIqdOxl9Kuy1sQY7LM VNQw== X-Gm-Message-State: AOJu0YwMOW28cUO84gzMxrIpOiGuZ8MZZygmFKnpqyC9P0bppdAu/shD O0cA5Czj3XyHD8XXfrStORiZ1xYjRSAKi14FyeUQUdcRnJw+k1FPs+pNOfANpLKea+KnCV7dbPC YSeHTRXvpx2JGHjJUgz9zaEOubyr2q3jfCr/5Id6tGGIPpS93Lpo= X-Google-Smtp-Source: AGHT+IGm8EAA01QYUTDg5F8efG9ts9wA1Cfum3Udc2zds4NTfMdiJh85ngrJ1JwrUWdsq9fTRTdndADVvDLX6GxKhpE= X-Received: by 2002:a05:6602:15c9:b0:807:aebc:3bdd with SMTP id ca18e2360f4ac-81f95a4f653mr1619966939f.5.1722435416845; Wed, 31 Jul 2024 07:16:56 -0700 (PDT) MIME-Version: 1.0 From: Jim Vanns Date: Wed, 31 Jul 2024 15:16:45 +0100 Message-ID: Subject: Suggestions to overcome 'multixact "members" limit exceeded' in temporary tables To: PostgreSQL-development Content-Type: multipart/alternative; boundary="0000000000002b8b35061e8bbf21" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000002b8b35061e8bbf21 Content-Type: text/plain; charset="UTF-8" I've reached the limit of my understanding and attempts at correcting my code/use of temporary tables in the face of multixact members and have come to ask for your help! Here's a brief description of my software; Pool of N connection sessions, persistent for the duration of the program lifetime. Upon each session initialisation, a set of CREATE TEMPORARY TABLE ON COMMIT DELETE ROWS statements are made for bulk ingest. Each session is acquired by a thread for use when ingesting data and therefore each temporary table remains until the session is terminated The thread performs a COPY FROM STDIN in binary format Then an INSERT INTO
SELECT FROM WHERE... This has been working great for a while and with excellent throughput. However, upon scaling up I eventually hit this error; ERROR: multixact "members" limit exceeded DETAIL: This command would create a multixact with 2 members, but the remaining space is only enough for 0 members. HINT: Execute a database-wide VACUUM in database with OID 16467 with reduced vacuum_multixact_freeze_min_age and vacuum_multixact_freeze_table_age settings. And it took me quite a while to identify that it appears to be coming from the temporary table (the other 'main' tables were being autovacuumed OK) - which makes sense because they have a long lifetime, aren't auto vacuumed and shared by transactions (in turn). I first attempted to overcome this by introducing an initial step of always creating the temporary table before the copy (and using on commit drop) but this lead to a terrible performance degradation. Next, I reverted the above and instead I introduced a VACUUM step every 1000000 (configurable) ingest operations Finally, I introduced a TRUNCATE step in addition to the occasional VACUUM since the TRUNCATE allowed the COPY option of FREEZE. The new overhead appears minimal until after several hours and again I've hit a performance degradation seemingly dominated by the TRUNCATE. My questions are; 1) Is the VACUUM necessary if I use TRUNCATE + COPY FREEZE (on the temporary table)? 2) Is there really any benefit to using FREEZE here or is it best to just VACUUM the temporary tables occasionally? 3) Is there a better way of managing all this!? Perhaps re-CREATING the TT every day or something? I understand that I can create a Linux tmpfs partition for a tablespace for the temporary tables and that may speed up the TRUNCATE but that seems like a hack and I'd rather not do it at all if it's avoidable. Thanks for your help, Jim PS. PG version in use is 15.4 if that matters here -- Jim Vanns Principal Production Engineer Industrial Light & Magic, London --0000000000002b8b35061e8bbf21 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I've reached the limit of my understanding and attempt= s at correcting my code/use of temporary tables in the face of=C2=A0multixa= ct members and have come to ask for your help! Here's a brief descripti= on of my software;

Pool of N connection sessions, persis= tent for the duration of the program lifetime.
Upon each session = initialisation, a set of CREATE TEMPORARY TABLE ON COMMIT DELETE ROWS state= ments are made for bulk ingest.
Each session is acquired by a thr= ead for use when ingesting=C2=A0data and therefore each temporary table rem= ains until the session is terminated
The thread performs a COPY &= lt;temp table> FROM STDIN in binary format
Then an INSERT INTO= <main table> SELECT FROM <temp table> WHERE...

<= /div>
This has been working great for a while and with excellent throug= hput. However, upon scaling up I eventually hit this error;

<= /div>
ERROR: =C2=A0multixact "members" limit exceeded
DETA= IL: =C2=A0This command would create a multixact with 2 members, but the rem= aining space is only enough for 0 members.
HINT: =C2=A0Execute a databas= e-wide VACUUM in database with OID 16467 with reduced vacuum_multixact_free= ze_min_age and vacuum_multixact_freeze_table_age settings.

And it took me quite a while to identify that it appears = to be coming from the temporary table (the other 'main' tables were= being autovacuumed=C2=A0OK) - which makes sense because they have a long l= ifetime, aren't auto vacuumed and shared by transactions (in turn).

I first attempted to overcome this by introducing an = initial step of always creating the temporary table before the copy (and us= ing on commit drop) but this lead to a terrible performance degradation.
Next, I reverted the above and instead I introduced a VACUUM step e= very 1000000 (configurable) ingest operations
Finally, I introduc= ed a TRUNCATE step in addition to the occasional VACUUM since the TRUNCATE = allowed the COPY option of FREEZE.

The new overhea= d appears minimal until after several hours and again I've hit a perfor= mance degradation=C2=A0seemingly dominated=C2=A0by the TRUNCATE.
=
My questions are;

1) Is the VACUUM = necessary if I use TRUNCATE=C2=A0+ COPY FREEZE (on the temporary table)?
2) Is there really any benefit to using FREEZE here or is it best t= o just VACUUM the temporary tables occasionally?
3) Is there a be= tter way of managing all this!? Perhaps re-CREATING the TT every day or som= ething?

I understand that I can create a Linux tmp= fs partition for a tablespace for the temporary tables and that may speed u= p the TRUNCATE but that seems like a hack and I'd rather not do it at a= ll if it's avoidable.

Thanks for your help,

Jim

PS. PG version in use i= s 15.4 if that matters here

--
Jim Vanns
Principal Produc= tion Engineer
Industrial Light & Magic, London
--0000000000002b8b35061e8bbf21--