我有 Azure Database for PostgreSQL 服务 (PaaS)。当我尝试使用它进行查询时,psql
即使是来自一个表的简单SELECT
查询也需要大约 1.5 秒。当我在 postgres 控制台中时,没有问题,查询在 100 毫秒内执行。什么会导致连接时间延迟?
for I in {1..15} ; do /usr/bin/time -f "%es" psql -U postgres@user -h my-server.postgres.database.azure.com database_name -c "SELECT count(*) FROM table_name" > /dev/null ; done
1.86s
1.95s
1.60s
1.03s
1.59s
1.58s
1.60s
1.68s
1.60s
1.60s
1.62s
1.63s
1.61s
1.83s
1.70s
仅供参考:表中有 11 个条目
更新 下面的测试证明这是连接延迟而不是在 postgres 上执行查询本身
$ psql -t -U postgres@resource-group -h postgresql-project.postgres.database.azure.com stage_table <<EOF
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
SELECT count(*), clock_timestamp() FROM my_table;
EOF
17 | 2019-07-23 13:26:11.475655+00
17 | 2019-07-23 13:26:11.506887+00
17 | 2019-07-23 13:26:11.553769+00
17 | 2019-07-23 13:26:11.585022+00
17 | 2019-07-23 13:26:11.616273+00
17 | 2019-07-23 13:26:11.64752+00
17 | 2019-07-23 13:26:11.678787+00
17 | 2019-07-23 13:26:11.710046+00
17 | 2019-07-23 13:26:11.74129+00
17 | 2019-07-23 13:26:11.772524+00
17 | 2019-07-23 13:26:11.803794+00
17 | 2019-07-23 13:26:11.835042+00
17 | 2019-07-23 13:26:11.86629+00
17 | 2019-07-23 13:26:11.897517+00
17 | 2019-07-23 13:26:11.944397+00
$
我也在 azure 上读到过accelerated networking
,但这看起来只适用于 VM 本身。我可以在 PostgreSQL 服务上启用此加速吗?https://docs.microsoft.com/en-us/azure/virtual-network/create-vm-accelerated-networking-cli