Postgres: runs into FATAL: sorry, too many clients already almost every night

Hi all,

I encounter a strange problem here:
openHAB running for about 2 years, with Postgres as DB backend, current version of OH is 4.3.5. For about 10 days or so almost every night OH runs into “too many clients already” when it tries to connect. DB max connections is set to 100.

When I set DB max connections to 250, the same happened, maybe just a bit later. When I set DB max connections to 1000, the Raspi 4 crashed during the night.

When I set idle_in_transaction_session_timeout = 60000 on the DB side (this is in ms), nothing changed.

Yesterday evening I started a little script querying the DB every 5 s for all open connections. I see now, that OH is indeed the culprit (there are a few other services running on the Pi as well):
100 open connections from OH, thereof 75 (!) with query = COMMIT. I don’t know what this really means, but it seems strange, all of them started between 00:11:14 and 00:28:27.

In my persistence config I have strategies like every minute, every 5 minutes, every hour; and: everyDayEnd, but that’s set to 0 59 23 * *.

What can be the reason for this behaviour? And: how can I find out, why this happens (COMMIT is like not enough too see, what queries are really executed)?

Maybe I should just set the idle timeout on the DB to much less than 60000, but that would 1) not solve the root problem, 2) not explain, why this behaviour started some days ago, without any relevant change to my system and setup I would remember.

Thanks for your help and ideas,

Bernd

Maybe a connection pool service like PgBouncer can help.

just a guess but could it be related to this?

If you are hitting this It is possible it may result in your connection pool on postgres getting used up
Also, what do you see when you query pg_stat_actvity?

You can review this article to troubleshoot more but as it explains how to isolate things.

https://www.baeldung.com/sql/psqlexception-fatal-sorry-too-many-clients-already-solution

But if you are hitting this known bug in OH and it is in your version it may explain all of it.
the latest release of OH 4.3.8 addresses this bug.

The above PR wasn’t released until 4.3.8:

Good morning and thanks for your ideas!

The guess / bug mentioned might match, will see…

What I did yesterday was: I re-configured Postgres to log all statements, and I ran my script again over night, which queries pg_stat_activity. The latter one is difficult to post here because it contains so many columns, but as I had stated earlier, it essentially shows a huge amount of columns with query = COMMIT.

Looking at the Postgres logfile with all statements, it gets difficult:
There is a pattern as expected because of the persistence service writing new values either every minute or every 5 minutes. But there is no clear relationship between statements run when everything runs smoothly and when there occur these “too many connection” messages:

Example when running without any problem:

2025-10-17 00:42:59.840 UTC [451766] openhab@openhab LOG:  statement: BEGIN
2025-10-17 00:42:59.841 UTC [451766] openhab@openhab LOG:  statement: select pg_catalog.version()
2025-10-17 00:42:59.842 UTC [451766] openhab@openhab LOG:  statement: select current_schema()
2025-10-17 00:42:59.843 UTC [451766] openhab@openhab LOG:  statement: show transaction isolation level
2025-10-17 00:42:59.844 UTC [451766] openhab@openhab LOG:  statement: show standard_conforming_strings
2025-10-17 00:42:59.845 UTC [451766] openhab@openhab LOG:  statement: ROLLBACK
2025-10-17 00:42:59.846 UTC [451766] openhab@openhab LOG:  statement: BEGIN
2025-10-17 00:42:59.847 UTC [451766] openhab@openhab LOG:  statement: SELECT time, value FROM item0060 WHERE time >= '2025-10-15' and time < '2025-10-17'
2025-10-17 00:42:59.861 UTC [451766] openhab@openhab LOG:  statement: COMMIT
2025-10-17 00:43:00.072 UTC [451765] openhab@openhab LOG:  statement: COMMIT
2025-10-17 00:43:00.878 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0021" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.878 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 00:43:00.884 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0192" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.884 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '19.935789108276367'
2025-10-17 00:43:00.890 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0183" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.890 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '200'
2025-10-17 00:43:00.896 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0184" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.896 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '0.2'
2025-10-17 00:43:00.903 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0185" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.903 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 00:43:00.908 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0027" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.908 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '60.932820320129395'
2025-10-17 00:43:00.914 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0032" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.914 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 00:43:00.919 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0036" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.919 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 00:43:00.924 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0037" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.924 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 00:43:00.930 UTC [450350] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0059" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 00:43:00.930 UTC [450350] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 00:43:05.128 UTC [451811] openhab@openhab LOG:  statement: BEGIN
2025-10-17 00:43:05.128 UTC [451811] openhab@openhab LOG:  statement: SELECT t.oid, typarray
        FROM pg_type t JOIN pg_namespace ns
            ON typnamespace = ns.oid
        WHERE typname = 'hstore';
        
2025-10-17 00:43:05.133 UTC [451811] openhab@openhab LOG:  statement: ROLLBACK

and when running into a problem:

2025-10-17 00:43:47.230 UTC [451973] openhab@openhab LOG:  statement: BEGIN
2025-10-17 00:43:47.231 UTC [451973] openhab@openhab LOG:  statement: select pg_catalog.version()
2025-10-17 00:43:47.233 UTC [451973] openhab@openhab LOG:  statement: select current_schema()
2025-10-17 00:43:47.234 UTC [451973] openhab@openhab LOG:  statement: show transaction isolation level
2025-10-17 00:43:47.235 UTC [451973] openhab@openhab LOG:  statement: show standard_conforming_strings
2025-10-17 00:43:47.236 UTC [451973] openhab@openhab LOG:  statement: ROLLBACK
2025-10-17 00:43:47.238 UTC [451973] openhab@openhab LOG:  statement: BEGIN
2025-10-17 00:43:47.239 UTC [451973] openhab@openhab LOG:  statement: SELECT time, value FROM item0060 WHERE time >= '2025-10-15' and time < '2025-10-17'
2025-10-17 00:43:47.264 UTC [451973] openhab@openhab LOG:  statement: COMMIT
2025-10-17 00:43:48.409 UTC [451977] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 00:43:48.417 UTC [451978] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 00:43:59.584 UTC [452025] openhab@openhab LOG:  statement: BEGIN
2025-10-17 00:43:59.584 UTC [452025] openhab@openhab LOG:  statement: SELECT t.oid, typarray
        FROM pg_type t JOIN pg_namespace ns
            ON typnamespace = ns.oid
        WHERE typname = 'hstore';
        
2025-10-17 00:43:59.588 UTC [452025] openhab@openhab LOG:  statement: ROLLBACK

and also:

2025-10-17 01:27:14.079 UTC [462252] openhab@openhab LOG:  statement: BEGIN
2025-10-17 01:27:14.079 UTC [462252] openhab@openhab LOG:  statement: select pg_catalog.version()
2025-10-17 01:27:14.081 UTC [462252] openhab@openhab LOG:  statement: select current_schema()
2025-10-17 01:27:14.083 UTC [462252] openhab@openhab LOG:  statement: show transaction isolation level
2025-10-17 01:27:14.083 UTC [462252] openhab@openhab LOG:  statement: show standard_conforming_strings
2025-10-17 01:27:14.084 UTC [462252] openhab@openhab LOG:  statement: ROLLBACK
2025-10-17 01:27:14.086 UTC [462252] openhab@openhab LOG:  statement: BEGIN
2025-10-17 01:27:14.087 UTC [462252] openhab@openhab LOG:  statement: SELECT time, value FROM item0060 WHERE time >= '2025-10-15' and time < '2025-10-17'
2025-10-17 01:27:14.115 UTC [462252] openhab@openhab LOG:  statement: COMMIT
2025-10-17 01:27:25.354 UTC [462300] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:25.359 UTC [462301] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:30.170 UTC [462311] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:30.179 UTC [462312] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:35.717 UTC [462322] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:35.722 UTC [462323] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:40.715 UTC [462328] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:40.722 UTC [462329] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:46.164 UTC [462337] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:46.169 UTC [462338] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:50.896 UTC [462346] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:50.901 UTC [462347] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:55.661 UTC [462359] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:27:55.669 UTC [462360] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:00.878 UTC [457556] openhab@openhab LOG:  execute S_122: INSERT INTO "item0021" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.878 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:28:00.884 UTC [457556] openhab@openhab LOG:  execute S_123: INSERT INTO "item0192" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.884 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '20.223981857299805'
2025-10-17 01:28:00.891 UTC [457556] openhab@openhab LOG:  execute S_124: INSERT INTO "item0183" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.891 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '192'
2025-10-17 01:28:00.898 UTC [457556] openhab@openhab LOG:  execute S_125: INSERT INTO "item0184" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.898 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0.192'
2025-10-17 01:28:00.903 UTC [457556] openhab@openhab LOG:  execute S_126: INSERT INTO "item0185" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.903 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:28:00.909 UTC [457556] openhab@openhab LOG:  execute S_127: INSERT INTO "item0027" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.909 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '70.01018905639648'
2025-10-17 01:28:00.914 UTC [457556] openhab@openhab LOG:  execute S_128: INSERT INTO "item0032" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.914 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:28:00.919 UTC [457556] openhab@openhab LOG:  execute S_129: INSERT INTO "item0036" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.919 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:28:00.925 UTC [457556] openhab@openhab LOG:  execute S_130: INSERT INTO "item0037" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.925 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:28:00.930 UTC [457556] openhab@openhab LOG:  execute S_131: INSERT INTO "item0059" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:28:00.930 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:28:01.126 UTC [462370] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:01.131 UTC [462371] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:11.145 UTC [462389] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:11.149 UTC [462390] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:15.862 UTC [462394] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:15.867 UTC [462395] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:20.644 UTC [462401] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:20.652 UTC [462402] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:26.182 UTC [462425] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:26.194 UTC [462426] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:31.307 UTC [462434] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:31.314 UTC [462435] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:37.340 UTC [462443] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:37.347 UTC [462444] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:42.984 UTC [462451] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:42.989 UTC [462452] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:47.715 UTC [462460] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:47.721 UTC [462461] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:52.794 UTC [462473] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:52.802 UTC [462474] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:58.250 UTC [462477] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:28:58.255 UTC [462478] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:00.878 UTC [457556] openhab@openhab LOG:  execute S_132: INSERT INTO "item0021" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.878 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:29:00.883 UTC [457556] openhab@openhab LOG:  execute S_133: INSERT INTO "item0192" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.883 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '20.45480728149414'
2025-10-17 01:29:00.887 UTC [457556] openhab@openhab LOG:  execute S_134: INSERT INTO "item0183" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.887 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '184'
2025-10-17 01:29:00.893 UTC [457556] openhab@openhab LOG:  execute S_135: INSERT INTO "item0184" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.893 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0.184'
2025-10-17 01:29:00.898 UTC [457556] openhab@openhab LOG:  execute S_136: INSERT INTO "item0185" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.898 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:29:00.902 UTC [457556] openhab@openhab LOG:  execute S_137: INSERT INTO "item0027" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.902 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '61.450472831726074'
025-10-17 01:29:00.907 UTC [457556] openhab@openhab LOG:  execute S_138: INSERT INTO "item0032" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.907 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:29:00.912 UTC [457556] openhab@openhab LOG:  execute S_139: INSERT INTO "item0036" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.912 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:29:00.917 UTC [457556] openhab@openhab LOG:  execute S_140: INSERT INTO "item0037" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.917 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:29:00.923 UTC [457556] openhab@openhab LOG:  execute S_141: INSERT INTO "item0059" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:29:00.923 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:29:02.984 UTC [462485] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:02.990 UTC [462486] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:10.661 UTC [462495] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:10.674 UTC [462496] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:16.157 UTC [462505] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:16.165 UTC [462506] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:21.075 UTC [462513] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:21.079 UTC [462514] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:25.824 UTC [462528] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:25.832 UTC [462529] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:31.283 UTC [462538] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:31.287 UTC [462539] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:36.036 UTC [462547] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:36.047 UTC [462548] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:41.631 UTC [462558] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:41.639 UTC [462560] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:46.930 UTC [462564] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:46.936 UTC [462565] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:51.992 UTC [462579] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:51.999 UTC [462580] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:57.437 UTC [462585] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:29:57.441 UTC [462586] openhab@openhab FATAL:  sorry, too many clients already
2025-10-17 01:30:00.878 UTC [457556] openhab@openhab LOG:  execute S_142: INSERT INTO "item0021" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.878 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:30:00.882 UTC [457556] openhab@openhab LOG:  execute S_143: INSERT INTO "item0192" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.882 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '19.728181838989258'
2025-10-17 01:30:00.887 UTC [457556] openhab@openhab LOG:  execute S_144: INSERT INTO "item0183" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.887 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '181'
2025-10-17 01:30:00.892 UTC [457556] openhab@openhab LOG:  execute S_145: INSERT INTO "item0184" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.892 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0.181'
2025-10-17 01:30:00.898 UTC [457556] openhab@openhab LOG:  execute S_146: INSERT INTO "item0185" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.898 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:30:00.903 UTC [457556] openhab@openhab LOG:  execute S_147: INSERT INTO "item0027" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.903 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '65.06857919692993'
2025-10-17 01:30:00.908 UTC [457556] openhab@openhab LOG:  execute S_148: INSERT INTO "item0032" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.908 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:30:00.913 UTC [457556] openhab@openhab LOG:  execute S_149: INSERT INTO "item0036" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.913 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:30:00.918 UTC [457556] openhab@openhab LOG:  execute S_150: INSERT INTO "item0037" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.918 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:30:00.923 UTC [457556] openhab@openhab LOG:  execute S_151: INSERT INTO "item0059" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.923 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:30:00.927 UTC [457556] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0060" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.927 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:30:00.933 UTC [457556] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0051" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.933 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:30:00.938 UTC [457556] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0008" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.938 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '8.6'
2025-10-17 01:30:00.944 UTC [457556] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0010" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.944 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '56.1'
2025-10-17 01:30:00.952 UTC [457556] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0011" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.952 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '0'
2025-10-17 01:30:00.958 UTC [457556] openhab@openhab LOG:  execute <unnamed>: INSERT INTO "item0013" (TIME, VALUE) VALUES( NOW(), CAST( $1 as DOUBLE PRECISION) ) ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE
2025-10-17 01:30:00.958 UTC [457556] openhab@openhab DETAIL:  Parameters: $1 = '8.08'
[...]

I’m upgrading my instance to 5.0.2, let’s see it this solves the problem…

The reason there are too many clients is that the existing clients are somehow “stuck”, that part should be clear. The question is why they are stuck, what they are waiting for.

I must say that I’m surprised by the amount of rollbacks shown in the log. Rollback is usually a rare thing. When you want to do a “transaction” (multiple changes that are related/depend on each other), you start with BEGIN, do the related/dependent changes and then COMMIT them all together. If you, during the transaction, discovers something that makes it “impossible” to fulfil the transactions, like a bank account becoming negative, you abort the transaction as a whole using ROLLBACK. This undoes everything that has happened since BEGIN.

While the transaction is “ongoing”, locks are in place in the database either or table or record level (or sometimes parts of tables, I think). Other clients, that want to modify whatever is locked, must wait. This could potentially make clients “stuck”, if they wait for a transaction to complete that never does.

I don’t know the code that does make transactions, and I don’t know whether the BEGIN/COMMIT/ROLLBACK commands are explicit or not. There is something called auto-commit, and also database libraries sometimes partly manage transactions implicitly. So, what we see above might make perfect sense because I don’t know the details, but I do think that it looks a bit strange, and that applies both before and after “the error” occurs.

It can also seem like some of these ROLLBACKs appear after a read operation. Maybe I read the log wrong, but doing that makes no sense whatsoever. You don’t use “transactions” at all unless you intend to write something. You could do a number of reads first, to gather information needed to make a decision before you write and commit the transaction, and if the data you read aren’t as you expect, you might abort the transaction before writing, but I would think that this was a relatively rare occurrence. So, I find it a bit peculiar.

You need to look at blocking and row level locks and what event is triggering them.

If you have a insert or update statement that is creating a table lock in lue of a row level lock then all transactions will be in a blocked state until that table level lock is released.

The bug I referenced was present in all version of 4.3 as I understood the github conversation but has been solutioned in version 4.3.8 that was released in the past day or so.

If it was me and I was facing this type of issue I would upgrade to the latest version of OH 4.3.8 and see if it brings any relief or behavior changes before burning lots of effort on everything since there is a known bug for persistence that has been addressed.

Based on OP original statements around no changes and suddenly this starts occurring it would at the surface at least align to the conditions that the bug refers to regarding

if an item has no values persisted, the lastUpdate, lastChange and previousState persistence extensions could get into an infinite loop. This could also happen when the query to the persistence service fails when called from these extension methods, e.g. because the database is offline.

I misunderstood you. I thought you meant that it could have been introduced by the linked PR, which would be impossible since it’s not present in the version he’s using. When it comes to being fixed by the linked PR, that might be, although I had the impression that this problem had been around for a long time, so it wouldn’t quite explain why this suddenly started happening. But, yes, it’s well worth upgrading to 4.3.8 to see if that helps.