Error Upgrading Confluence 3.5.13 to 4.1.4 with Postgre Database
Asked by Andreas Lohrmeier:

I upgraded from 3.4.6 to 3.5.13 with no problems.

But from 3.5.13 to 4.1.4 upgrade failed.

Does anyone know what to do ?

2012-02-15 16:18:52,609 INFO \[Thread-25\] \[atlassian.plugin.manager.DefaultPluginManager\] shutdown Shutting down the plugin system  
2012-02-15 16:18:55,765 INFO \[Thread-25\] \[com.atlassian.confluence.lifecycle\] contextDestroyed Stopping Confluence  
2012-02-15 16:48:10,406 INFO \[main\] \[com.atlassian.confluence.lifecycle\] contextInitialized Starting Confluence 4.1.4 (build #3142)  
2012-02-15 16:48:14,218 WARN \[main\] \[atlassian.config.xml.AbstractDom4jXmlConfigurationPersister\] saveDocumentAtomically Unable to move C:\\Confluence\\Data\\confluence.cfg.xml325581889398512959tmp to C:\\Confluence\\Data\\confluence.cfg.xml. Falling back to non-atomic overwrite.  
2012-02-15 16:48:14,234 INFO \[main\] \[springframework.web.context.ContextLoader\] initWebApplicationContext Root WebApplicationContext: initialization started  
2012-02-15 16:48:19,468 INFO \[main\] \[com.atlassian.confluence.lifecycle\] \<init\> Loading EhCache cache manager  
2012-02-15 16:48:50,890 INFO \[main\] \[springframework.web.context.ContextLoader\] initWebApplicationContext Root WebApplicationContext: initialization completed in 36656 ms  
2012-02-15 16:48:56,015 INFO \[main\] \[confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask\] doUpgrade Starting AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask  
2012-02-15 16:48:56,015 INFO \[main\] \[confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask\] deleteDuplicateAttachmentData Removing any attachment data entries which have more than one record for the same attachmentid...  
2012-02-15 16:48:56,046 INFO \[main\] \[confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask\] deleteAttachmentDataRecords Searching for attachment data entries to remove  
2012-02-15 16:48:56,078 INFO \[main\] \[confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask\] deleteParentlessAttachmentData Removing any attachment data entries which have no attachmentid specified...  
2012-02-15 16:48:56,093 INFO \[main\] \[confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask\] deleteAttachmentDataRecords Searching for attachment data entries to remove  
**2012-02-15 16:48:56,109 INFO \[main\] \[confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask\] addNotNullAndUniqueConstraint Adding not-null and unique constraints to the ATTACHMENTID column of ATTACHMENTDATA**   
**2012-02-15 16:48:56,109 INFO \[main\] \[confluence.upgrade.ddl.HibernateAlterTableExecutor\] alterTable Executing grouped alter table command on ATTACHMENTDATA**   
**2012-02-15 16:48:56,109 INFO \[main\] \[confluence.upgrade.ddl.HibernateDdlExecutor\] executeDdlStatements Executing DDL: alter table ATTACHMENTDATA alter column ATTACHMENTID set not null, add constraint ad_unique_attachmentid unique (ATTACHMENTID)**   
**2012-02-15 16:48:56,296 ERROR \[main\] \[atlassian.confluence.upgrade.UpgradeLauncherServletContextListener\] contextInitialized Upgrade failed, application will not start: Upgrade task com.atlassian.confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask@55d3df failed during the SCHEMA_UPGRADE phase due to: StatementCallback; bad SQL grammar \[alter table ATTACHMENTDATA alter column ATTACHMENTID set not null, add constraint ad_unique_attachmentid unique (ATTACHMENTID)\]; nested exception is org.postgresql.util.PSQLException: FEHLER: Relation \>\>ad_unique_attachmentid\<\< existiert bereits**   
**com.atlassian.confluence.upgrade.UpgradeException: Upgrade task com.atlassian.confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask@55d3df failed during the SCHEMA_UPGRADE phase due to: StatementCallback; bad SQL grammar \[alter table ATTACHMENTDATA alter column ATTACHMENTID set not null, add constraint ad_unique_attachmentid unique (ATTACHMENTID)\]; nested exception is org.postgresql.util.PSQLException: FEHLER: Relation \>\>ad_unique_attachmentid\<\< existiert bereits**   
**at com.atlassian.confluence.upgrade.AbstractUpgradeManager.executeUpgradeStep(AbstractUpgradeManager.java:212)**   
**at com.atlassian.confluence.upgrade.AbstractUpgradeManager.runSchemaUpgradeTasks(AbstractUpgradeManager.java:137)**   
**at com.atlassian.confluence.upgrade.AbstractUpgradeManager.upgrade(AbstractUpgradeManager.java:92)**   
**at com.atlassian.confluence.upgrade.UpgradeLauncherServletContextListener.contextInitialized(UpgradeLauncherServletContextListener.java:45)**   
**at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)**   
**at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)**   
**at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)**   
**at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)**   
**at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)**   
**at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)**   
**at org.apache.catalina.core.StandardService.start(StandardService.java:525)**   
**at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)**   
**at org.apache.catalina.startup.Catalina.start(Catalina.java:595)**   
**at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)**   
**at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)**   
**at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)**   
**at java.lang.reflect.Method.invoke(Method.java:597)**   
**at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)**   
**at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)**   
**Caused by: org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar \[alter table ATTACHMENTDATA alter column ATTACHMENTID set not null, add constraint ad_unique_attachmentid unique (ATTACHMENTID)\]; nested exception is org.postgresql.util.PSQLException: FEHLER: Relation \>\>ad_unique_attachmentid\<\< existiert bereits**   
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:97)  
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)  
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)  
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)  
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407)  
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:429)  
at com.atlassian.confluence.upgrade.ddl.HibernateDdlExecutor.executeDdlStatements(HibernateDdlExecutor.java:60)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
at java.lang.reflect.Method.invoke(Method.java:597)  
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)  
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)  
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)  
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)  
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)  
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)  
at $Proxy34.executeDdlStatements(Unknown Source)  
at com.atlassian.confluence.upgrade.ddl.HibernateAlterTableExecutor.alterTableGrouped(HibernateAlterTableExecutor.java:85)  
at com.atlassian.confluence.upgrade.ddl.HibernateAlterTableExecutor.alterTable(HibernateAlterTableExecutor.java:65)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
at java.lang.reflect.Method.invoke(Method.java:597)  
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)  
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)  
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)  
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)  
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)  
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)  
at $Proxy35.alterTable(Unknown Source)  
at com.atlassian.confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask.addNotNullAndUniqueConstraint(AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask.java:142)  
at com.atlassian.confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask.doUpgrade(AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask.java:93)  
at com.atlassian.confluence.upgrade.AbstractUpgradeManager$UpgradeStep$3.execute(AbstractUpgradeManager.java:479)  
at com.atlassian.confluence.upgrade.AbstractUpgradeManager.executeUpgradeStep(AbstractUpgradeManager.java:188)  
... 18 more  
Caused by: org.postgresql.util.PSQLException: FEHLER: Relation \>\>ad_unique_attachmentid\<\< existiert bereits  
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)  
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)  
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)  
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)  
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)  
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:366)  
at com.mchange.v2.c3p0.impl.NewProxyStatement.execute(NewProxyStatement.java:1006)  
at org.springframework.jdbc.core.JdbcTemplate$1ExecuteStatementCallback.doInStatement(JdbcTemplate.java:422)  
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396)  
... 48 more  
2012-02-15 16:48:56,312 ERROR \[main\] \[atlassian.confluence.upgrade.UpgradeLauncherServletContextListener\] contextInitialized 1 errors were encountered during upgrade:  
2012-02-15 16:48:56,312 ERROR \[main\] \[atlassian.confluence.upgrade.UpgradeLauncherServletContextListener\] contextInitialized 1: StatementCallback; bad SQL grammar \[alter table ATTACHMENTDATA alter column ATTACHMENTID set not null, add constraint ad_unique_attachmentid unique (ATTACHMENTID)\]; nested exception is org.postgresql.util.PSQLException: FEHLER: Relation \>\>ad_unique_attachmentid\<\< existiert bereits  
2012-02-15 16:48:56,312 WARN \[main\] \[atlassian.confluence.plugin.PluginFrameworkContextListener\] contextInitialized Not starting full plugin system due to upgrade or licensing errors  
2012-02-15 16:48:58,843 INFO \[main\] \[com.atlassian.confluence.lifecycle\] init Confluence is ready to serve  
2012-02-15 16:57:31,500 INFO \[Thread-15\] \[com.atlassian.confluence.lifecycle\] destroy Shutting down long running task service  
2012-02-15 16:57:31,812 INFO \[Thread-15\] \[com.atlassian.confluence.lifecycle\] contextDestroyed Stopping Confluence  


Answers:
author: Holger Brade
body: I drop manually the follwing two constaints:

alter table ATTACHMENTDATA constraint ad_unique_attachmentid;

alter table BANDANA drop constraint bandana_unique_key;

After first restart I got some strange GUI errors, but after second restart everthing looks fine.


author: JamieA
body: With the stack trace you might get some sensible replies.


author: JamieA
body: Oh, upgrade failed is it? Of course, that's an easy one to fix.