Bug 1524221

Summary: Unable to install spacewalk-postgresql: template database encoding error
Product: [Community] Spacewalk Reporter: Eric Burgueño <nevermind85>
Component: InstallationAssignee: Jan Dobes <jdobes>
Status: CLOSED CURRENTRELEASE QA Contact: Red Hat Satellite QA List <satqe-list>
Severity: high Docs Contact:
Priority: unspecified    
Version: 2.7CC: chakraborty, ihavethisundercontrol, Toni.Feric, yoram
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: spacewalk-admin-2.8.3-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-20 12:32:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1564160    

Description Eric Burgueño 2017-12-10 21:36:48 UTC
Description of problem:

When running spacewalk-setup using a postgresql backend, the database step fails with the following error:

# cat /var/log/rhn/install_db.log
Note: Forwarding request to 'systemctl enable 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.

Version-Release number of selected component (if applicable):

This is on CentOS 7.4, with spacewalk 2.7 and postgresql 9.2

How reproducible:
Always


Steps to Reproduce:
1. Setup the yum repositories as in https://github.com/spacewalkproject/spacewalk/wiki/HowToInstall and install spacewalk-setup-postgresql and spacewalk-postgresql

2. Create an answers file for spacewalk-setup:
# cat > answers <<EOF
admin-email = admin
hostname = spacewalk.example.com
ssl-set-org = Example Corp.
ssl-set-org-unit = Example Team
ssl-set-city = Auckland
ssl-set-state = Auckland
ssl-set-country = New Zealand
ssl-password = "somepwd"
ssl-set-email = root@localhost
ssl-config-sslvhost = Y
db-backend = postgresql
db-name = rhnschema
db-user = rhnuser
db-password = "someotherpwd"
db-host = localhost
db-port = 5432
enable-tftp=Y
EOF

3. Install spacewalk
# spacewalk-setup --answer-file=$(pwd)/answers

Actual results:

* Loading answer file: /root/spacewalk-answer-file.
* 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.


Expected results:
Spacewalk is installed

Comment 1 Eric Burgueño 2017-12-11 03:14:15 UTC
I did some more digging. I believe this is an bug with the spacewalk-setup-postgresql script.

Specifically, the scripts looks for a /usr/lib/systemd/system/spacewalk.target file to decide whether to use SystemD's "systemctl" or "service" commands.

/usr/lib/systemd/system/spacewalk.target does not exist after installing the spacewalk RPMs, so the script fallsback to using "service" to run PostgreSQL's initdb; which for some reason does not respect the system LANG:

# env|grep LANG
LANG=en_NZ.UTF-8

# cat /etc/locale.conf 
LANG="en_NZ.UTF-8"

# service postgresql initdb
Hint: the preferred way to do this is now "postgresql-setup initdb"
Initializing database ... OK

# head /var/lib/pgsql/initdb.log 
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".

Comment 2 Yoram van de Velde 2017-12-12 09:38:06 UTC
We have the same issue with installs since this weekend.

-Spacewalk 2.7
-Centos 7.4.1708
-PostgreSQL 9.2.23

Exactly the same setup process worked thursday.

Comment 3 Eric Burgueño 2017-12-12 10:29:59 UTC
At the moment, a simple workaround that I found is to manually run "postgresql-setup initdb" before "spacewalk-setup". The DB will be initialized correctly respecting the system LANG, and "spacewalk-setup" will do the rest.

Comment 4 Jan Dobes 2017-12-15 17:27:01 UTC
It stopped working after postgresql packages were updated from 9.2.23-1.el7_4 to 9.2.23-3.el7_4 last week.

Anyway, missing systemd target on RHEL 7 is a bug, I added it (actually, I wanted to do this already month ago for different reason), now the DB initialization seems fine.

spacewalk(master).git:
e47c437cf7377b3e9e712d79f69379a95e8ea270

You can try to install with fixed spacewalk-admin RPM from nightly:

https://copr-be.cloud.fedoraproject.org/results/@spacewalkproject/nightly/epel-7-x86_64/00688037-spacewalk-admin/spacewalk-admin-2.8.3-1.el7.centos.noarch.rpm

Comment 5 Tomáš Kašpárek 2018-01-05 11:55:22 UTC
*** Bug 1526004 has been marked as a duplicate of this bug. ***

Comment 6 soham 2018-01-22 12:43:27 UTC
Hi,

I am still having the same problem. I have tried to install both spacewalk-2.7 and spacewalk-2.6. The issue is present in both. I also tried to use the workaround given by Eric but I can't get to initialize the database. Eric, if you reading this, any suggestion? 

In spacewalk-2.6 I tried with downgraded postgresql packages, but it still has the same problem. 

###### This is from spacewalk-2.7 installation attempt, everything lastest #######

[root@spacewalkcentos7 ~]# spacewalk-setup
* Setting up SELinux..
** Database: Setting up database connection for PostgreSQL backend.
Database "rhnschema" does not exist
** 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.
[root@spacewalkcentos7 ~]# tail -10  /var/log/rhn/install_db.log
/usr/bin/spacewalk-setup-postgresql: line 165: [: 018446744073692774399: integer expression expected
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.
[root@spacewalkcentos7 ~]# service postgresql initdb
Hint: the preferred way to do this is now "postgresql-setup initdb"
Data directory is not empty!

[root@spacewalkcentos7 ~]# 
[root@spacewalkcentos7 ~]# postgresql-setup initdb
Data directory is not empty!


###### This is from spacewalk-2.6 installation attempt #######


[root@spacewalk yum.repos.d]# 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.
[root@spacewalk yum.repos.d]# tailf /var/log/rhn/install_db.log
/usr/bin/spacewalk-setup-postgresql: line 100: isSUSE: command not found
Note: Forwarding request to 'systemctl enable postgresql.service'.
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 154: [: 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.

^C
[root@spacewalk yum.repos.d]# rpm -qa | grep -i spacewalk
spacewalk-backend-iss-export-2.6.78-1.el7.noarch
spacewalk-backend-applet-2.6.78-1.el7.noarch
spacewalk-backend-tools-2.6.78-1.el7.noarch
spacewalk-setup-2.6.2-1.el7.noarch
spacewalk-repo-2.6-0.el7.noarch
spacewalk-backend-server-2.6.78-1.el7.noarch
spacewalk-backend-xmlrpc-2.6.78-1.el7.noarch
spacewalk-backend-config-files-tool-2.6.78-1.el7.noarch
spacewalk-backend-iss-2.6.78-1.el7.noarch
spacewalk-config-2.6.5-1.el7.noarch
spacewalk-base-minimal-config-2.6.6-1.el7.noarch
spacewalk-html-2.6.6-1.el7.noarch
spacewalk-certs-tools-2.5.3-1.el7.noarch
spacewalk-taskomatic-2.6.49-1.el7.noarch
spacewalk-admin-2.6.1-1.el7.noarch
spacewalk-schema-2.6.17-1.el7.noarch
spacewalk-selinux-2.3.2-1.el7.noarch
spacewalk-common-2.6.1-1.el7.noarch
spacewalk-setup-postgresql-2.6.2-1.el7.noarch
spacewalk-backend-usix-2.6.78-1.el7.noarch
spacewalk-backend-libs-2.6.78-1.el7.noarch
spacewalk-java-postgresql-2.6.49-1.el7.noarch
spacewalk-base-minimal-2.6.6-1.el7.noarch
spacewalk-jpp-workaround-2.3.5-1.el7.noarch
spacewalk-java-config-2.6.49-1.el7.noarch
spacewalk-search-2.6.1-1.el7.noarch
spacewalk-java-lib-2.6.49-1.el7.noarch
spacewalk-backend-sql-2.6.78-1.el7.noarch
spacewalk-backend-xml-export-libs-2.6.78-1.el7.noarch
spacewalk-backend-app-2.6.78-1.el7.noarch
spacewalk-backend-config-files-2.6.78-1.el7.noarch
spacewalk-backend-package-push-server-2.6.78-1.el7.noarch
spacewalk-branding-2.5.3-1.el7.noarch
spacewalk-java-2.6.49-1.el7.noarch
spacewalk-base-2.6.6-1.el7.noarch
spacewalk-setup-jabberd-2.3.2-1.el7.noarch
spacewalk-postgresql-2.6.1-1.el7.noarch
spacewalk-backend-sql-postgresql-2.6.78-1.el7.noarch
spacewalk-doc-indexes-2.6.2-1.el7.noarch
spacewalk-backend-2.6.78-1.el7.noarch
spacewalk-backend-config-files-common-2.6.78-1.el7.noarch

[root@spacewalk yum.repos.d]# rpm -qa | grep -i postgresql
postgresql-server-9.2.23-3.el7_4.x86_64
postgresql-contrib-9.2.23-3.el7_4.x86_64
postgresql-9.2.23-3.el7_4.x86_64
postgresql-jdbc-9.2.1002-5.el7.noarch
spacewalk-setup-postgresql-2.6.2-1.el7.noarch
spacewalk-java-postgresql-2.6.49-1.el7.noarch
spacewalk-postgresql-2.6.1-1.el7.noarch
spacewalk-backend-sql-postgresql-2.6.78-1.el7.noarch
postgresql-libs-9.2.23-3.el7_4.x86_64
postgresql-pltcl-9.2.23-3.el7_4.x86_64


###### This is from spacewalk-2.6 installation attempt after downgrading postgresql #######

[root@spacewalk ~]# yum downgrade postgresql-libs postgresql-contrib postgresql-server postgresql postgresql-pltcl 
Loaded plugins: fastestmirror
base                                                                                                                           | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                                           | 6.8 kB  00:00:00     
extras                                                                                                                         | 3.4 kB  00:00:00     
jpackage-generic                                                                                                               | 1.9 kB  00:00:00     
spacewalk                                                                                                                      | 2.1 kB  00:00:00     
updates                                                                                                                        | 3.4 kB  00:00:00     
Loading mirror speeds from cached hostfile

<SNIP> 

Removed:
  postgresql.x86_64 0:9.2.23-3.el7_4               postgresql-contrib.x86_64 0:9.2.23-3.el7_4         postgresql-libs.x86_64 0:9.2.23-3.el7_4        
  postgresql-pltcl.x86_64 0:9.2.23-3.el7_4         postgresql-server.x86_64 0:9.2.23-3.el7_4         

Installed:
  postgresql.x86_64 0:9.2.23-1.el7_4               postgresql-contrib.x86_64 0:9.2.23-1.el7_4         postgresql-libs.x86_64 0:9.2.23-1.el7_4        
  postgresql-pltcl.x86_64 0:9.2.23-1.el7_4         postgresql-server.x86_64 0:9.2.23-1.el7_4         

Complete!
[root@spacewalk ~]# spacewalk-setup
* Setting up SELinux..
** Database: Setting up database connection for PostgreSQL backend.
/usr/bin/spacewalk-setup-postgresql: line 87: isSUSE: command not found
/usr/bin/spacewalk-setup-postgresql: line 100: isSUSE: command not found
Database "rhnschema" does not exist
** 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.
[root@spacewalk ~]# tailf /var/log/rhn/install_db.log
/usr/bin/spacewalk-setup-postgresql: line 87: isSUSE: command not found
/usr/bin/spacewalk-setup-postgresql: line 100: isSUSE: command not found
Note: Forwarding request to 'systemctl enable postgresql.service'.
/usr/bin/spacewalk-setup-postgresql: line 154: [: 018446744073692774399: integer expression expected
Redirecting to /bin/systemctl stop postgresql.service
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.
^C
[root@spacewalk ~]# 

[root@spacewalk ~]# rpm -qa | grep postgresql
postgresql-jdbc-9.2.1002-5.el7.noarch
spacewalk-setup-postgresql-2.6.2-1.el7.noarch
spacewalk-java-postgresql-2.6.49-1.el7.noarch
postgresql-server-9.2.23-1.el7_4.x86_64
spacewalk-postgresql-2.6.1-1.el7.noarch
postgresql-pltcl-9.2.23-1.el7_4.x86_64
spacewalk-backend-sql-postgresql-2.6.78-1.el7.noarch
postgresql-libs-9.2.23-1.el7_4.x86_64
postgresql-contrib-9.2.23-1.el7_4.x86_64
postgresql-9.2.23-1.el7_4.x86_64

Comment 7 Eric Burgueño 2018-01-22 22:54:51 UTC
@soham you need to initialise the database **before** running spacewalk-setup.

Comment 8 Toni Feric 2018-01-27 00:30:19 UTC
Once "spacewalk-setup" has failed to create the database, any successive re-tries of "spacewalk-setup" will fail.

The following steps worked for me to get around the problem:
- Set your correct locales in /etc/environment
- Wipe existing postgresql data using: rm -rf /var/lib/pgsql/data
- Pre-run the postgresql database creation as suggested by Eric Burgueno: postgresql-setup initdb
- Re-run the Spacewalk setup: spacewalk-setup

This is my /etc/environment (use your own locale settings instead of mine):
LANGUAGE="en_US:en"
LC_ALL="de_CH.utf8"
LC_CTYPE="de_CH.utf8"
LANG="de_CH.utf8"

Instead of running "postgresql-setup initdb" (as suggested by Eric), the following also worked for me:
su - postgres
pg_ctl initdb

Comment 9 soham 2018-01-29 08:01:04 UTC
(In reply to Eric Burgueño from comment #7)
> @soham you need to initialise the database **before** running
> spacewalk-setup.

Thanks Eric. It worked.

Comment 10 Jiří Dostál 2018-03-26 12:16:55 UTC
Moving ON_QA

Comment 11 Jiří Dostál 2018-04-20 12:32:08 UTC
Spacewalk 2.8 has been released.
https://github.com/spacewalkproject/spacewalk/wiki/ReleaseNotes28