Problem:univention-pkgdb-scan - pg.InternalError: FATAL: Password authentication for user failed

Problem

When executing the command univention-pkgdb-scan you get the following Traceback:

root@ucsdc0:/home/univention-support#
univention-pkgdb-scan

Traceback (most recent call last):
  File "/usr/sbin/univention-pkgdb-scan", line 41, in <module>
    univention.pkgdb.main()
  File "/usr/lib/python3/dist-packages/univention/pkgdb.py", line 589, in main
    connection = open_database_connection(config_registry, pkgdbu=False)
  File "/usr/lib/python3/dist-packages/univention/pkgdb.py", line 571, in open_database_connection
    connection = pgdb.connect(database=connectstring)
  File "/usr/lib/python3/dist-packages/pgdb.py", line 1619, in connect
    cnx = _connect(dbname, dbhost, dbport, dbopt, dbuser, dbpasswd)
pg.InternalError: FATAL:  Password authentication for user »ucsdc0$« failed

Hint

In this scenario it is important to mention that the package for univention-pkdg, i.e. the pkgdb server itself, is not located on the primary node / DC master (ucsdc0).
This plays an important role later in the solution, because the host name and domain name must match the pkgdb server so that the pkgdb can also be accessed.

Environment

root@ucs-pkgdb:/home/univention-support# univention-app info
UCS: 5.0-8 errataXXX
Installed: pkgdb=11.0

root@ucs-pkgdb:/home/univention-support# dpkg -l | grep pkgdb
ii  python3-univention-pkgdb                            13.0.5-2                                          all          UCS - Software monitoring database Python 3 library
ii  univention-management-console-module-pkgdb          13.0.5-2                                          all          UMC module for software monitoring database
ii  univention-pkgdb                                    13.0.5-2                                          all          UCS - Software monitoring database
ii  univention-pkgdb-tools                              13.0.5-2                                          all          UCS - Software monitoring database tools

root@ucsdc0:/home/univention-support# dpkg -l | grep pkgdb
ii  python3-univention-pkgdb                            13.0.5-2                                          all          UCS - Software monitoring database Python 3 library
ii  univention-pkgdb-tools                              13.0.5-2                                          all          UCS - Software monitoring database tools

Solution

You have to add the User to the DATABASE pkgdb on the system, where univention-pkgdb is installed so, which system is your pkgdb Server.

univention-pkgdb-scan --db-server "$(hostname -f)" --add "ucsdc0$"

SQL: CREATE USER "ucsdc0$" IN GROUP pkgdbg

SQL: ALTER GROUP pkgdbg ADD USER "ucsdc0$"

Hint

This comes from the join script you will find under/usr/lib/univention-install/50univention-pkgdb.inst

univention-pkgdb-scan --db-server "$hostname.$domainname" --add "$hostname$"

Fixed output:
root@ucsdc0:/home/univention-support#
univention-pkgdb-scan

Reading package lists... Done
Building dependency tree       
Reading state information... Done

For missing hosts in the pg_hba.conf, check the following article.

To recreate the DATABASE pkgdb, check the following article.

See also:

PostgreSQL Cheat Sheet

Mastodon