Problem: univention-pkgdb.inst fails with traceback

Problem:

Installing the software-installation-monitor on a dc-backup the joinscript trows a traceback:

Traceback (most recent call last):
  File "/usr/sbin/univention-pkgdb-scan", line 37, in <module>
univention.pkgdb.main()
  File "/usr/lib/python2.7/dist-packages/univention/pkgdb.py", line 577, in main
connection = open_database_connection(config_registry, pkgdbu=True)
  File "/usr/lib/python2.7/dist-packages/univention/pkgdb.py", line 561, in open_database_connection
connection = pgdb.connect(database=connectstring)
  File "/usr/lib/python2.7/dist-packages/pgdb.py", line 1615, in connect
cnx = _connect(dbname, dbhost, dbport, dbopt, dbuser, dbpasswd)
pg.InternalError: FATAL:  database "pkgdb" does not exist

Investigation:

Reading from the master DB

univention-pkgdb-scan --db-server 'master.schein.ig' --debug
Reading package lists... Done
Building dependency tree
Reading state information... Done

Look for existing DB on DC-backup

root@backup:/var/log/univention# su - postgres -c 'psql'
psql (9.6.20)
Type "help" for help.

postgres=# \l
»       »       »       »       »       »       »          List of databases
»       Name     |    Owner    | Encoding | Collate | Ctype |   Access privileges···
-------------+-------------+----------+---------+-------+-----------------------
 postgres    | postgres    | LATIN1   | en_IN   | en_IN |·
 selfservice | selfservice | UTF8     | en_IN   | en_IN |·
 template0   | postgres    | LATIN1   | en_IN   | en_IN | =c/postgres          +
»       »       »        |             |          |         |       | postgres=CTc/postgres
 template1   | postgres    | LATIN1   | en_IN   | en_IN | =c/postgres          +
»       »       »        |             |          |         |       | postgres=CTc/postgres
(4 rows)

ucr search --brief ‘^(pkgdb/|hostname$|domainname$)’

domainname: schein.ig
hostname: backup
pkgdb/overwrite/joincheck: <empty>
pkgdb/requiressl: true
pkgdb/scan: yes

Solution:

To create the missing database use this command
debian/univention-pkgdb.postinst → su - postgres -c 'psql -v ON_ERROR_STOP= -qf /usr/share/univention-pkgdb/sql/create-database.sql'

Addition

I would advise against installing the pkgdb on a master/primary. At least not in environments with a lot of servers that might also do regular updates at the same time.

The Pkgdb should exist only 1× within the domain