Postgres database upgrade fails in InstallerDb.databaseSetUser on Windows

Description

Running the EnterpriseDB windows package for PostgreSQL 8.3. The installer fails when attempting to upgrade from OpenNMS 1.8.0 to 1.8.1 (but also appears to happen with upgrading from older upgrades to 1.7+).

The problem appears to be the same as that identified by Daniel Greske in June on the -install mailing list:

When I run the installer ($OPENNMS_HOME/bin/install -l /usr/local/lib
-dis) to complete the upgrade, everything goes well until this line:
[...]

  • using 'opennms' as the PostgreSQL database name for OpenNMS

  • checking if database "opennms" is unicode... ALREADY UNICODE

  • Checking for old import files in /opt/opennms/etc... DONE
    Exception in thread "main" org.postgresql.util.PSQLException: ERROR:
    syntax error at or near "$1"
    **Position: 13

    • * * *at
      org.postgresql.core.v3.QueryExecutorImpl.receiveEr rorResponse(QueryExecutorImpl.java:2062)

    • * * *at
      org.postgresql.core.v3.QueryExecutorImpl.processRe sults(QueryExecutorImpl.java:1795)

    • * * *at
      org.postgresql.core.v3.QueryExecutorImpl.execute(Q ueryExecutorImpl.java:257)

    • * * *at
      org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:479)

    • * * *at
      org.postgresql.jdbc2.AbstractJdbc2Statement.execut eWithFlags(AbstractJdbc2Statement.java:367)

    • * * *at
      org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:360)

    • * * *at
      org.opennms.netmgt.dao.db.InstallerDb.databaseSetU ser(InstallerDb.java:1940)

    • * * *at
      org.opennms.install.Installer.install(Installer.ja va:278)

    • * * *at
      org.opennms.install.Installer.main(Installer.java: 859)

I did a little more digging and it looks like the PostgreSQL driver on Windows is sometimes returning tables, indices, and sequences during the statement

ResultSet rs = getAdminConnection().getMetaData().getTables(null, "public", "%", null);

The subsequent ALTER TABLE statement then fails on the first non-table object encountered in the HashSet built from that ResultSet.

One way to ensure that only tables are being acted upon would be to add some filtering to the databaseSetUser() method. Something like the following might work as a workaround for the PostgreSQL behaviour without affecting the results other drivers.

public void databaseSetUser() throws SQLException {
ResultSet rs = getAdminConnection().getMetaData().getTables(null, "public", "%", null);
HashSet<String> objects = new HashSet<String>();
while (rs.next()) {
if (rs.getString("TABLE_TYPE").equals("TABLE"))
objects.add(rs.getString("TABLE_NAME"));
}
PreparedStatement st = getAdminConnection().prepareStatement("ALTER TABLE ? OWNER TO ?");
for (String objName : objects) {
st.setString(1, objName);
st.setString(2, m_user);
st.execute();
}
st.close();
}

I am currently running into this on Windows with the PG 8.4-701 JDBC3 driver. I have had success doing a db upgrade to 1.8 under CentOS 5 with the same PG 8.4-701 driver against a Linux RPM Postgres db, so maybe it's a difference between the Windows and Linux PostgreSQL implementations.

Environment

Operating System: Windows XP/2003 (NT 5.1) Platform: PC

Acceptance / Success Criteria

None

Attachments

1
  • 21 Apr 2014, 02:39 PM

Lucidchart Diagrams

Activity

Jeff Gehlbach October 28, 2014 at 1:59 PM

Merged, cherry-picked, should auto-merge to reach 14.0 branch.

Jeff Gehlbach October 28, 2014 at 1:59 PM

I merged David's pull request and cherry-picked it to 1.12. Ben informs me that it will be auto-merged from 1.12 to rc/stable/1.14.0.

Seth Leger October 28, 2014 at 12:46 PM

The pull request that David submitted looks good, I recommend merging to 1.12 and 14.

David Schlenk April 21, 2014 at 2:39 PM

This patch works for me and passes the InstallerDbTest unit test.

David Schlenk April 21, 2014 at 11:17 AM

I ran into this today as I was attempting to install 1.12.5 on a postgresql 9.3 system that has the pg_buffercache and pg_stat_statements contrib extenstions installed in the database template. The simplest fix should be to specify "TABLE" for the 4th argument to getTables rather than null. I'll test that and submit a patch if that takes care of it.

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

PagerDuty

Created July 30, 2010 at 4:44 PM
Updated June 1, 2015 at 12:45 PM
Resolved October 28, 2014 at 1:59 PM

Flag notifications