I use libnss-pgsql2 in order to have virtual system users stored in a PostgreSQL database. The virtual users in the database work just fine. They can log in. I can see their uid, gid, groups via the 'id' command. Example:
# id backup001 uid=10001(backup001) gid=10001(backup001) groups=10001(backup001)
However, on systems that I use libnss, I frequently get this error:
Could not connect to database
It happens, for instance, often with cron-jobs. I have one cron-job that runs every hour that dumps the postgresql databases to a backup. The contrab is this:
04 * * * * postgres umask 077 && /usr/bin/pg_dumpall | gzip > ~postgres/backup/postgresql-complete-dump-$(date +\%H).sql.gz
This job always produces the error. Thus, flooding me with an e-mail every hour.
My setup is pretty simple: The table layout I use to store the users is available here: http://p.adora.dk/P2486.html
I use Debian Squeeze on the server.
Relevant config files are: nsswitch.conf : http://p.adora.dk/P2489.html
(description: use "normal" system users in /etc/passwd and /etc/shadow, however, if the user is NOT found, then proceed with a lookup via pgsql)
nss-pgsql.conf : http://p.adora.dk/P2487.html
(description: contains the SQL queries that are used to look up various information that normally is found in /etc/passwd and /etc/group)
nss-pgsql-root.conf : http://p.adora.dk/P2488.html
(description: contains the SQL queries that are used to lookup confidential info that is normally found in /etc/shadow)
Things that I have done to debug this:
- Verified that the connection strings in both nss-pgsql.conf and nss-pgsql-root.conf work as intended.
- Verified that the timeout does not occur. I.e. the error is echoed immediately and not after 300 seconds. Also, this happens on a server that does not do anything - so the connection should be established without delay -- I have verified that it does.
I really hope you can help me fix this error.