Actually, someone has pointed out another issue here - OSM Carto is in the process of switching over to using flex rather than pgsql output from osm2pgsql. To get to what was released on osm.org (tag 5.9.0) you need to do something like this:

git clone https://github.com/gravitystorm/openstreetmap-carto
cd openstreetmap-carto
git pull --all
git switch --detach v5.9.0

That worked for me on a new Debian 12 system, and if no-one suggests a better way either here or at github I’ll change the other “up to date” guides too.