Hi there! Finally I was able to solve the problem uninstalling psycopg2* and reinstalling psycopg2-binary.
Still, I want to comment what happened, in case it helps others.
A packages update broke the psycopg2 package in the server. Actually, the server ended up with two instances: psycopg2 and psycopg2-binary, and trying to import psycopg2 from python would return an error:
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: /usr/lib64/python2.7/site-packages/psycopg2/_psycopg.so: undefined symbol: PQconninfo
From what I've learned here, web2py comes with several database adapters. Apparently, for postgresql, web2py tries to use psycopg2, and if it can't, it will use pg8000.
And here is the weird stuff: the pg8000 driver works good when the connection is made directly to PostgreSQL server. But if the connection is made through pgBouncer (a connection pooler for PostgreSQL), then for some reason the pgBouncer connections are not reused; instead, they start to pile up very very fast. I'm not sure if this a problem of the pg8000 adapter that comes with web2py or a problem within pgBouncer.
Still, this makes me wonder: should web2py automatically change to pg8000 when psycopg2 fails?
I mean, in this scenario, I would have prefer a 500 error. It would have been much easier to detect the source of the problem.
As web2py switched to pg8000 without making me notice, and also, as this new driver produced a problem with pgBouncer, it took me a while to understand why pgBouncer was failing so spectacularly.
Again, I'm not sure if this is a problem of web2py's pg8000 adapter or a problem with pgBouncer itself (remember pg8000 works ok connecting directly to PostgreSQL).
But still, wouldn't be nice to be able to say to DAL: "hey, use only this adapter, and fail if you can't import it"?
I've not seen an option for that in DAL's constructor.
Could I just remove the folder gluon/contrib/pg8000/ to be sure my application will use only psycopg2 and fail if it can't find it?