我在同一个网络上有两台服务器,一台托管PostgreSQL数据库,另一台托管网络服务器。
通过localhost或IP本地连接到PSQL数据库是即时的
从数据库服务器到网络服务器的Ping是<1ms,
从Web服务器到数据库服务器的Ping是<1ms
通过网络服务器的IP远程连接到PSQL数据库每次需要5秒钟。
但是,连接后,所有交易都很快。
以下是显示本地连接和远程连接之间差异的日志。
LOCAL connection
2017-06-14 16:09:02 UTC [21966-171] DEBUG: forked new backend, pid=22322 socket=12
2017-06-14 16:09:02 UTC [22322-1] postgres@postgres DEBUG: postgres child[22322]: starting with (
2017-06-14 16:09:02 UTC [22322-2] postgres@postgres DEBUG: postgres
2017-06-14 16:09:02 UTC [22322-3] postgres@postgres DEBUG: )
2017-06-14 16:09:02 UTC [22322-4] postgres@postgres DEBUG: InitPostgres
2017-06-14 16:09:02 UTC [22322-5] postgres@postgres DEBUG: my backend ID is 12
2017-06-14 16:09:02 UTC [22322-6] postgres@postgres DEBUG: StartTransaction
2017-06-14 16:09:02 UTC [22322-7] postgres@postgres DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
2017-06-14 16:09:02 UTC [22322-8] postgres@postgres DEBUG: CommitTransaction
2017-06-14 16:09:02 UTC [22322-9] postgres@postgres DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
REMOTE CONNECTION
================= connection attempted on clientside ====================
2017-06-14 16:07:18 UTC [21966-147] DEBUG: forked new backend, pid=22256 socket=12
2017-06-14 16:07:18 UTC [22256-1] [unknown]@[unknown] DEBUG: SSL connection from "(anonymous)"
2017-06-14 16:07:18 UTC [22256-2] webserver@maindb DEBUG: postgres child[22256]: starting with (
2017-06-14 16:07:18 UTC [22256-3] webserver@maindb DEBUG: postgres
2017-06-14 16:07:18 UTC [22256-4] webserver@maindb DEBUG: )
2017-06-14 16:07:18 UTC [22256-5] webserver@maindb DEBUG: InitPostgres
2017-06-14 16:07:18 UTC [22256-6] webserver@maindb DEBUG: my backend ID is 2
2017-06-14 16:07:18 UTC [22256-7] webserver@maindb DEBUG: StartTransaction
2017-06-14 16:07:18 UTC [22256-8] webserver@maindb DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
================== connection established on clientside ======================
2017-06-14 16:07:23 UTC [22015-51] webserver@maindb DEBUG: shmem_exit(0): 1 before_shmem_exit callbacks to make
2017-06-14 16:07:23 UTC [22015-52] webserver@maindb DEBUG: shmem_exit(0): 6 on_shmem_exit callbacks to make
2017-06-14 16:07:23 UTC [22015-53] webserver@maindb DEBUG: proc_exit(0): 3 callbacks to make
2017-06-14 16:07:23 UTC [22015-54] webserver@maindb DEBUG: SSL: write alert (0x0100)
2017-06-14 16:07:23 UTC [22015-55] webserver@maindb DEBUG: exit(0)
2017-06-14 16:07:23 UTC [22015-56] webserver@maindb DEBUG: shmem_exit(-1): 0 before_shmem_exit callbacks to make
2017-06-14 16:07:23 UTC [22015-57] webserver@maindb DEBUG: shmem_exit(-1): 0 on_shmem_exit callbacks to make
2017-06-14 16:07:23 UTC [22015-58] webserver@maindb DEBUG: proc_exit(-1): 0 callbacks to make
2017-06-14 16:07:23 UTC [21966-148] DEBUG: forked new backend, pid=22257 socket=12
2017-06-14 16:07:23 UTC [21966-149] DEBUG: reaping dead processes
2017-06-14 16:07:23 UTC [21966-150] DEBUG: server process (PID 22015) exited with exit code 0
2017-06-14 16:07:23 UTC [22257-1] [unknown]@[unknown] DEBUG: SSL connection from "(anonymous)"
2017-06-14 16:07:23 UTC [22257-2] webserver@maindb DEBUG: postgres child[22257]: starting with (
2017-06-14 16:07:23 UTC [22257-3] webserver@maindb DEBUG: postgres
2017-06-14 16:07:23 UTC [22257-4] webserver@maindb DEBUG: )
2017-06-14 16:07:23 UTC [22257-5] webserver@maindb DEBUG: InitPostgres
2017-06-14 16:07:23 UTC [22257-6] webserver@maindb DEBUG: my backend ID is 7
2017-06-14 16:07:23 UTC [22257-7] webserver@maindb DEBUG: StartTransaction
2017-06-14 16:07:23 UTC [22257-8] webserver@maindb DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
为了清楚起见,SSL模式也会出现问题。