记忆正在泄漏Docker中的Postgres

发布于 2025-01-29 11:42:47 字数 1668 浏览 2 评论 0原文

我为公司服务进行负载测试。 撰写版本:Docker撰写版本v2.4.1 我对DB的组合:

version: '3.4'
x-check: &default-healthcheck
  healthcheck:
    test: [ "CMD", "/data/.prepare" ]
    interval: 30s
    timeout: 30s

services:
  postgres-api:
    image: postgres:11
    container_name: 'load-POSTGRES-API'
    restart: unless-stopped
    environment:
      - POSTGRES_USER=test
      - POSTGRES_PASSWORD=test
    command: [
      "postgres",
      "-c",
      "log_statement=all",
      "-c",
      "log_destination=stderr",
      "-c",
      "max_connections=50",
      "-c",
      "shared_buffers=1GB",
      "-c",
      "effective_cache_size=4GB",
      "-c",
      "work_mem=16MB",
      "-c",
      "maintenance_work_mem=512MB",
      "-c",
      "random_page_cost=1.1",
      "-c",
      "temp_file_limit=10GB",
      "-c",
      "log_min_duration_statement=200ms",
      "-c",
      "idle_in_transaction_session_timeout=10s",
      "-c",
      "lock_timeout=1s",
      "-c",
      "statement_timeout=60s",
      "-c",
      "shared_preload_libraries=pg_stat_statements",
      "-c",
      "pg_stat_statements.max=10000",
      "-c",
      "pg_stat_statements.track=all"
    ]
    ports:
      - "${EXT_IP}:${POSTGRES_EXPOSE_API}"
    volumes:
      - ./postgres-l3/data:/data:rw
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 4G
        reservations:
          memory: 256M
    <<: *default-healthcheck

分配的内存持续5-10分钟(取决于负载),然后发生溢出,服务不会连接到数据库,我观察到错误:

"message":"the database system is in recovery mode"

连接丢失了,清除了数据库内存和数据库内存开始迅速融化。 所有桌子的大小为〜50MB。

如何解决?它的正常程度如何?

I make loading testing for companies service.
Compose version: Docker Compose version v2.4.1
My compose for DB:

version: '3.4'
x-check: &default-healthcheck
  healthcheck:
    test: [ "CMD", "/data/.prepare" ]
    interval: 30s
    timeout: 30s

services:
  postgres-api:
    image: postgres:11
    container_name: 'load-POSTGRES-API'
    restart: unless-stopped
    environment:
      - POSTGRES_USER=test
      - POSTGRES_PASSWORD=test
    command: [
      "postgres",
      "-c",
      "log_statement=all",
      "-c",
      "log_destination=stderr",
      "-c",
      "max_connections=50",
      "-c",
      "shared_buffers=1GB",
      "-c",
      "effective_cache_size=4GB",
      "-c",
      "work_mem=16MB",
      "-c",
      "maintenance_work_mem=512MB",
      "-c",
      "random_page_cost=1.1",
      "-c",
      "temp_file_limit=10GB",
      "-c",
      "log_min_duration_statement=200ms",
      "-c",
      "idle_in_transaction_session_timeout=10s",
      "-c",
      "lock_timeout=1s",
      "-c",
      "statement_timeout=60s",
      "-c",
      "shared_preload_libraries=pg_stat_statements",
      "-c",
      "pg_stat_statements.max=10000",
      "-c",
      "pg_stat_statements.track=all"
    ]
    ports:
      - "${EXT_IP}:${POSTGRES_EXPOSE_API}"
    volumes:
      - ./postgres-l3/data:/data:rw
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 4G
        reservations:
          memory: 256M
    <<: *default-healthcheck

The allocated memory lasts for 5-10 minutes (depending on the load), then an overflow occurs, the services will not connect to the database and I observe an error:

"message":"the database system is in recovery mode"

Connections are lost, the database memory is cleared and starts to melt quickly again.
The size of all tables is ~50Mb.

How can this be solved? How normal is it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文