首页 > 解决方案 > 远程 Postgresql 很慢

问题描述

我使用 Django ORM 运行 .py 文件,该文件连接到另一台服务器上的 Postgresql 服务器。两台服务器都在 Ubuntu 20.04 上运行

当我运行相同的文件时,它需要以下时间:

当运行具有更多进程的 .py 文件时,可能需要 20 秒。如果我在 postgresql 服务器上同时运行相同的脚本,无论如何需要 2-3 秒

我试过了:

我检查了服务器上的互联网速度及其正常

这是 postgresql.conf

# Generated by PGConfig 2.0 beta
## http://pgconfig.org

# Memory Configuration
shared_buffers = 2GB
effective_cache_size = 6GB
work_mem = 41MB
maintenance_work_mem = 512MB

# Checkpoint Related Configuration
min_wal_size = 512MB
max_wal_size = 2GB
checkpoint_completion_target = 0.9
wal_buffers = 16MB

# Network Related Configuration
listen_addresses = '*'
max_connections = 1000

# Storage Configuration
random_page_cost = 1.1
effective_io_concurrency = 200

# Worker Processes
max_worker_processes = 8
max_parallel_workers_per_gather = 4
max_parallel_workers = 8

# Logging configuration for pgbadger
logging_collector = on
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
log_temp_files = 0
lc_messages = 'C'

# Adjust the minimum time to collect data
log_min_duration_statement = '10s'
log_autovacuum_min_duration = 0

# 'csvlog' format configuration
log_destination = 'csvlog'

在 pg_hba 我只插入 1 个字符串

#
# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

host    all             all             all                     md5

有这个速度是正常的还是我可以配置?

标签: pythondjangopostgresqlubuntupostgresql-13

解决方案


推荐阅读