Short tip: CentOS 7.4, PostgreSQL 9.2.23 and Spacewalk 2.7: Could not install database

When installing Spacewalk 2.7 under CentOS 7.4 along with PostgreSQL 9.2.23, I recently stumbled upon the following error:

# spacewalk-setup
* Setting up SELinux..
** Database: Setting up database connection for PostgreSQL backend.
** Database: Installing the database:
** Database: This is a long process that is logged in:
** Database:   /var/log/rhn/install_db.log
*** Progress: ####
Could not install database.

The mentioned log file contained the following errors:

# less /var/log/rhn/install_db.log
...
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql.service to /usr/lib/systemd/system/postgresql.service.
Hint: the preferred way to do this is now "postgresql-setup initdb"
Initializing database ... OK

/usr/bin/spacewalk-setup-postgresql: Line 165: [: 018446744073692774399: integer expression expected.
Redirecting to /bin/systemctl start postgresql.service
createdb: database creation failed: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT:  Use the same encoding as in the template database, or use template0 as template.

The hint regarding the postgresql-setup command is particularly noticeable. Luckily, I’ve created a snapshot of the system enabling me to “rewind” in order to check the hint.

Even though the system’s localisation configuration was correct, I had to run the following command to successfully initialise the PostgreSQL database:

# LANG=en_US.utf8 postgresql-setup initdb

Afterwards, installation Spacewalk was possible – even tough a blank terminal was opened during the process. After stopping the process, the installation proceeded:

# spacewalk-setup
* Setting up SELinux..
** Database: Setting up database connection for PostgreSQL backend.
** Database: Installing the database:
** Database: This is a long process that is logged in:
** Database:   /var/log/rhn/install_db.log
*** Progress: #
** Database: Installation complete.
** Database: Populating database.
...

It seems like this behaviour is a bug that effects Red Hat Enterprise Linux 7 and other Linux distributions based on it – such as CentOS 7.

1 comment Write a comment

  1. I found that I also needed to set
    LC_CTYPE=en_US.UTF-8

    However this may be due to my specific use-case, which was installing spacewalk with saltstack

Leave a Reply