com.liferay.portal.kernel.job.JobExecutionException:org.postgresql.util.PSQLException:此连接已关闭

时间:2017-08-13 09:03:37

标签: postgresql liferay

我使用了postgresql 9.3和liferay 5.2

系统正常工作但经过一段时间后我在日志文件中遇到连接丢失问题。

    private void connectToServer() {
        client = new TcpClient(SERVER_IP, PORT_NO);
        nwStream = client.GetStream();

        writer = new StreamWriter(client.GetStream());
        writer.AutoFlush = true;
        connected = true;

        getDataFromServer();

        if (getDataTimer == null) {
            getDataTimer = new System.Timers.Timer();
            getDataTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            getDataTimer.Interval = 1000;
            getDataTimer.Enabled = true;
        }
    }

    private void OnTimedEvent(object source, ElapsedEventArgs e) {
        if (connected) {
            getDataFromServer();
        }
    }

    private void getDataFromServer() {
        new Thread(() => {
            Thread.CurrentThread.IsBackground = true;
            byte[] bytesToRead = new byte[client.ReceiveBufferSize];
            int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
            updateOutputWindow(Encoding.Default.GetString(bytesToRead, 0, bytesRead));
        }).Start();
    }

    private void updateOutputWindow(string text) {
        if (InvokeRequired) {
            Invoke(new MethodInvoker(delegate () {
                updateOutputWindow(text);
            }));
        }
        else {
            rtb_outputWindow.AppendText("\n" + text);
        }
    }

这是我在 portal-ext.properties 中的配置:

(org.springframework.scheduling.quartz.SchedulerFactoryBean#6e2243fb_Worker-2) 07:19:09,914 ERROR [JobWrapper:81] com.liferay.portal.kernel.job.JobExecutionException: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
com.liferay.portal.kernel.job.JobExecutionException: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
    at com.liferay.counter.service.persistence.ConnectionHeartbeatJob.execute(ConnectionHeartbeatJob.java:55)
    at com.liferay.portal.job.JobWrapper.execute(JobWrapper.java:69)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
Caused by: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:226)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:321)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:313)
    at com.mchange.v2.c3p0.impl.NewProxyStatement.execute(NewProxyStatement.java:1006)
    at com.liferay.counter.service.persistence.ConnectionHeartbeatJob.sendHeartbeat(ConnectionHeartbeatJob.java:75)
    at com.liferay.counter.service.persistence.ConnectionHeartbeatJob.execute(ConnectionHeartbeatJob.java:52)
    ... 3 more
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:143)
    at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:112)
    at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:70)
    at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:283)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1799)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
    ... 9 more
2017-08-13 08:19:09,901 INFO  [STDOUT] (org.springframework.scheduling.quartz.SchedulerFactoryBean#6e2243fb_Worker-1) 08:19:09,901 WARN  [NewPooledConnection:486] [c3p0] A PooledConnection that has already signalled a Connection error is still in use!
2017-08-13 08:19:09,903 INFO  [STDOUT] (org.springframework.scheduling.quartz.SchedulerFactoryBean#6e2243fb_Worker-1) 08:19:09,902 WARN  [NewPooledConnection:487] [c3p0] Another error has occurred [ org.postgresql.util.PSQLException: This connection has been closed. ] which will not be reported to listeners!
org.postgresql.util.PSQLException: This connection has been closed.
    at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:786)
    at org.postgresql.jdbc.PgConnection.createStatement(PgConnection.java:1598)
    at org.postgresql.jdbc.PgConnection.createStatement(PgConnection.java:405)
    at com.mchange.v2.c3p0.impl.NewProxyConnection.createStatement(NewProxyConnection.java:96)
    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.jdbc.datasource.LazyConnectionDataSourceProxy$LazyConnectionInvocationHandler.invoke(LazyConnectionDataSourceProxy.java:364)
    at com.sun.proxy.$Proxy261.createStatement(Unknown Source)
    at com.liferay.counter.service.persistence.ConnectionHeartbeatJob.sendHeartbeat(ConnectionHeartbeatJob.java:73)
    at com.liferay.counter.service.persistence.ConnectionHeartbeatJob.execute(ConnectionHeartbeatJob.java:52)
    at com.liferay.portal.job.JobWrapper.execute(JobWrapper.java:69)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
2017-08-13 08:19:09,905 INFO  [STDOUT] (org.springframework.scheduling.quartz.SchedulerFactoryBean#6e2243fb_Worker-1) 08:19:09,903 ERROR [JobWrapper:81] com.liferay.portal.kernel.job.JobExecutionException: org.postgresql.util.PSQLException: This connection has been closed.
com.liferay.portal.kernel.job.JobExecutionException: org.postgresql.util.PSQLException: This connection has been closed.
    at com.liferay.counter.service.persistence.ConnectionHeartbeatJob.execute(ConnectionHeartbeatJob.java:55)
    at com.liferay.portal.job.JobWrapper.execute(JobWrapper.java:69)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
Caused by: org.postgresql.util.PSQLException: This connection has been closed.
    at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:786)
    at org.postgresql.jdbc.PgConnection.createStatement(PgConnection.java:1598)
    at org.postgresql.jdbc.PgConnection.createStatement(PgConnection.java:405)
    at com.mchange.v2.c3p0.impl.NewProxyConnection.createStatement(NewProxyConnection.java:96)
    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.jdbc.datasource.LazyConnectionDataSourceProxy$LazyConnectionInvocationHandler.invoke(LazyConnectionDataSourceProxy.java:364)
    at com.sun.proxy.$Proxy261.createStatement(Unknown Source)
    at com.liferay.counter.service.persistence.ConnectionHeartbeatJob.sendHeartbeat(ConnectionHeartbeatJob.java:73)
    at com.liferay.counter.service.persistence.ConnectionHeartbeatJob.execute(ConnectionHeartbeatJob.java:52)
    ... 3 more

我尝试添加这些行,但错误仍然出现:

#
# PostgreSQL
#
jdbc.default.driverClassName=org.postgresql.Driver
jdbc.default.url=jdbc:postgresql://192.168.2.3:5432/portal
jdbc.default.username=postgres
jdbc.default.password=postgres

我无法理解错误, 在postgresql设置或liferay中的连接池设置中可能有问题

我在 postgresql.conf 中有这一行,可以更改它以解决此问题:

jdbc.default.testConnectionOnCheckout=true
jdbc.default.preferredTestQuery=SELECT 1
jdbc.default.acquireIncrement=1
jdbc.default.maxIdleTime=10800
jdbc.default.maxConnectionAge=14400
jdbc.default.numHelperThreads=20

已更新:

此错误多次显示在日志文件中,但第一次显示是在一分钟后可能需要1小时。

我在docker容器中运行Postgresql。

liferay和数据库容器位于同一物理服务器中。

我不知道为什么数据库连接有时无法访问。

这是泊坞版:

#synchronous_standby_names = '' # standby servers that provide sync rep
                # comma-separated list of application_name
                # from standby(s); '*' = all

1 个答案:

答案 0 :(得分:0)

哇,Liferay 5.2?那已经有一段时间......

第一个问题是:这是经常/每次出现吗?你可以复制它还是只复制一次?发生这种情况的一个常见原因是,当Postgresql更新并重新启动时。如果在事务期间发生这种情况,我希望Postgresql正常关闭,例如在关闭之前完成交易。

另一方面,在它再次启动之前,它将在一段时间内无法访问。即使Liferay(或连接池)确定当前连接无效(请参阅testQuery),它也无法在服务器关闭期间重新连接。如果Postgresql运行在与运行Liferay的服务器不同的服务器上,它不仅可以重新启动数据库本身,而且可能是完全重启操作系统。当然,Liferay会在这段时间内失去联系。

由于您没有提供有关复制步骤的任何其他说明,我说这是一个很好的开始猜测。否则需要更多信息。