Connection refused during init of XWiki

I installed Tomcat 9 and XWiki on my own VM about a month ago. Things have been working pretty well. My plan was to migrate a Confluence wiki to Xwiki. I did this today, everything worked fine, but after step 5 in the process of migrating I realised I had used an old xml.zip file and tried to redo the migration. Since then nothing has quite worked as usual. I now cannot initialize XWiki and get these error messages:

2023-03-21 02:43:31,118 [XWiki initialization] ERROR c.x.x.s.DBCPConnectionProvider - Could not create a DBCP pool. There is an error in the Hibernate configuration file, please review it.
java.sql.SQLException: Cannot create PoolableConnectionFactory (Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.)

I am confused as to why this error has suddenly appeared, might I have ruined something while trying to redo the migration in the middle of the process?

This does not tell much, the answer is generally in the root cause of this error at the very end of the stack trace you have after those lines.

The rest looks like this, so seems like a connection issue. I’m just struggling to understand how this first came to be as this was not the case a couple days ago, and I have not edited any files on my server

 2023-03-21 13:07:03,104 [XWiki initialization] ERROR c.x.x.s.DBCPConnectionProvider - Could not create a DBCP pool. There is an error in the Hibernate configuration file, please review it.
java.sql.SQLException: Cannot create PoolableConnectionFactory (Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.)
         at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:653)
         at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:531)
         at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:731)
         at com.xpn.xwiki.store.DBCPConnectionProvider.configure(DBCPConnectionProvider.java:225)
         at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:107)
         at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246)
         at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
         at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:146)
         at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
         at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
         at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
         at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
         at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
         at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
         at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:175)
         at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
         at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
         at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
         at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:173)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127)
         at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:86)
         at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:479)
         at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85)
         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:709)
         at com.xpn.xwiki.internal.store.hibernate.HibernateStore.build(HibernateStore.java:331)
         at com.xpn.xwiki.internal.store.hibernate.HibernateStore.initHibernate(HibernateStore.java:250)
         at com.xpn.xwiki.store.XWikiHibernateBaseStore.checkHibernateSynchronized(XWikiHibernateBaseStore.java:481)
         at com.xpn.xwiki.store.XWikiHibernateBaseStore.checkHibernate(XWikiHibernateBaseStore.java:474)
         at com.xpn.xwiki.store.XWikiHibernateStore.loadXWikiDoc(XWikiHibernateStore.java:1008)
         at com.xpn.xwiki.store.XWikiCacheStore.loadXWikiDoc(XWikiCacheStore.java:395)
         at com.xpn.xwiki.XWiki.getDocument(XWiki.java:2184)
         at com.xpn.xwiki.XWiki.getDocument(XWiki.java:2246)
         at com.xpn.xwiki.XWiki.getXClass(XWiki.java:7058)
         at com.xpn.xwiki.internal.filter.output.BaseObjectOutputFilterStream.checkDatabaseClass(BaseObjectOutputFilterStream.java:180)
         at com.xpn.xwiki.internal.filter.output.BaseObjectOutputFilterStream.beginWikiObject(BaseObjectOutputFilterStream.java:164)
         at com.xpn.xwiki.internal.filter.XWikiDocumentFilterCollection.beginWikiObject(XWikiDocumentFilterCollection.java:234)
         at com.xpn.xwiki.internal.filter.XWikiDocumentFilterCollection.beginWikiObject(XWikiDocumentFilterCollection.java:234)
         at com.xpn.xwiki.internal.filter.output.XWikiDocumentOutputFilterStream$1.beginWikiObject(XWikiDocumentOutputFilterStream.java:154)
         at jdk.internal.reflect.GeneratedMethodAccessor57.invoke(Unknown Source)
         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
         at org.xwiki.filter.internal.FilterProxy.invoke(FilterProxy.java:90)
         at org.xwiki.filter.internal.FilterProxy.invoke(FilterProxy.java:63)
         at com.sun.proxy.$Proxy111.beginWikiObject(Unknown Source)
         at org.xwiki.filter.xar.internal.input.WikiObjectReader$WikiObject.send(WikiObjectReader.java:78)
         at org.xwiki.filter.xar.internal.input.DocumentLocaleReader.sendWikiObjects(DocumentLocaleReader.java:588)
         at org.xwiki.filter.xar.internal.input.DocumentLocaleReader.readDocument(DocumentLocaleReader.java:515)
         at org.xwiki.filter.xar.internal.input.DocumentLocaleReader.read(DocumentLocaleReader.java:388)
         at org.xwiki.filter.xar.internal.input.DocumentLocaleReader.read(DocumentLocaleReader.java:335)
         at org.xwiki.filter.xar.internal.input.XARInputFilterStream.readDocument(XARInputFilterStream.java:121)
         at org.xwiki.filter.xar.internal.input.XARInputFilterStream.read(XARInputFilterStream.java:71)
         at org.xwiki.filter.xar.internal.input.XARInputFilterStream.read(XARInputFilterStream.java:47)
         at org.xwiki.filter.input.AbstractBeanInputFilterStream.read(AbstractBeanInputFilterStream.java:79)
         at com.xpn.xwiki.internal.filter.XWikiDocumentFilterUtils.importEntity(XWikiDocumentFilterUtils.java:191)
         at com.xpn.xwiki.internal.filter.XWikiDocumentFilterUtils.importDocument(XWikiDocumentFilterUtils.java:211)
         at org.xwiki.extension.xar.internal.handler.packager.Packager.getXWikiDocument(Packager.java:403)
         at org.xwiki.extension.xar.internal.handler.packager.Packager.getXWikiDocument(Packager.java:314)
         at org.xwiki.extension.xar.internal.handler.packager.Packager.getXWikiDocument(Packager.java:387)
         at org.xwiki.extension.xar.internal.handler.packager.Packager.getXWikiDocument(Packager.java:375)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentCustomizationDetector.getDocumentFromXAR(InstalledExtensionDocumentCustomizationDetector.java:105)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentCustomizationDetector.isCustomized(InstalledExtensionDocumentCustomizationDetector.java:92)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentCustomizationDetector.lambda$isCustomized$0(InstalledExtensionDocumentCustomizationDetector.java:86)
         at java.base/java.util.stream.MatchOps$1MatchSink.accept(MatchOps.java:90)
         at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1632)
         at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
         at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
         at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
         at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
         at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
         at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
         at java.base/java.util.stream.ReferencePipeline.allMatch(ReferencePipeline.java:533)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentCustomizationDetector.isCustomized(InstalledExtensionDocumentCustomizationDetector.java:86)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentListener.updateCustomizedFlag(InstalledExtensionDocumentListener.java:132)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentListener.addExtensionDocument(InstalledExtensionDocumentListener.java:153)
         at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1621)
         at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentListener.forEachExtensionDocument(InstalledExtensionDocumentListener.java:166)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentListener.addExtensionDocuments(InstalledExtensionDocumentListener.java:147)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentListener.lambda$addExtensionDocuments$1(InstalledExtensionDocumentListener.java:140)
         at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
         at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentListener.addExtensionDocuments(InstalledExtensionDocumentListener.java:140)
         at org.xwiki.extension.xar.internal.doc.InstalledExtensionDocumentListener.onEvent(InstalledExtensionDocumentListener.java:115)
         at org.xwiki.observation.internal.DefaultObservationManager.notify(DefaultObservationManager.java:320)
         at org.xwiki.observation.internal.DefaultObservationManager.notify(DefaultObservationManager.java:285)
         at com.xpn.xwiki.internal.XWikiInitializerJob.runInternal(XWikiInitializerJob.java:117)
         at org.xwiki.job.AbstractJob.runInContext(AbstractJob.java:246)
         at org.xwiki.job.AbstractJob.run(AbstractJob.java:223)
         at java.base/java.lang.Thread.run(Thread.java:829)
 Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
         at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:319)
         at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
         at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:247)
         at org.postgresql.Driver.makeConnection(Driver.java:434)
         at org.postgresql.Driver.connect(Driver.java:291)
         at org.apache.commons.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:52)
         at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:374)
         at org.apache.commons.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:106)
         at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:649)
         ... 89 common frames omitted
 Caused by: java.net.ConnectException: Connection refused (Connection refused)
         at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
         at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
         at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
         at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
         at java.base/java.net.Socket.connect(Socket.java:609)
         at org.postgresql.core.PGStream.createSocket(PGStream.java:241)
         at org.postgresql.core.PGStream.<init>(PGStream.java:98)
         at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:109)
         at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235)
         ... 97 common frames omitted

OK, so not much more information except that XWiki expect to find a PostgreSQL server locally listening to port 5432, and it does not seem to be the case.