Postgres 数据库的安装

Postgres 数据库的安装 

使用docker安装 

 建议使用 17版本,18版本的目前不支持martin。

建议使用 postgis镜像,如果直接使用 postgres 镜像不支持 postgis。

docker pull postgis/postgis:17-3.6-alpine

 

 

docker-compose.yml

version: '3.8'

services:
  postgres:
    image: postgis/postgis:17-3.6-alpine  # 替换为 PostGIS 镜像
    container_name: postgres
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: 123456
      POSTGRES_DB: postdb
      TZ: Asia/Shanghai
      # 允许外部连接的关键设置
      POSTGRES_HOST_AUTH_METHOD: "md5"  # 或 "scram-sha-256"
      POSTGRES_MULTIPLE_EXTENSIONS: "postgis,postgis_topology,postgis_raster"
    ports:
      - "5432:5432"
    volumes:
      - D:\DockerMapping\pgsql\data:/var/lib/postgresql/data
      - D:\DockerMapping\pgsql\conf\postgresql.conf:/var/lib/postgresql/data/postgresql.conf
      - D:\DockerMapping\pgsql\conf\pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf
    command: >
      postgres 
      -c config_file=/var/lib/postgresql/data/postgresql.conf
      -c hba_file=/var/lib/postgresql/data/pg_hba.conf
      -c data_directory=/var/lib/postgresql/data
    restart: unless-stopped
    

 

 

 

配置文件
D:\DockerMapping\pgsql\conf\pg_hba.conf

 

# PostgreSQL Client Authentication Configuration File
# ===================================================
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5

# IPv4 external connections - 允许所有IP连接
host    all             all             0.0.0.0/0               md5

# IPv6 local connections:
host    all             all             ::1/128                 md5

# IPv6 external connections:
host    all             all             ::/0                    md5

# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

 

 


D:\DockerMapping\pgsql\conf\postgresql.conf

# 连接设置 - 关键!
listen_addresses = '*'          # 允许所有IP连接,默认是'localhost'
port = 5432
max_connections = 100

# 认证设置
password_encryption = md5      # 或 scram-sha-256

# 内存设置
shared_buffers = 128MB
work_mem = 4MB

# 日志设置
logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'

# 时区
timezone = 'Asia/Shanghai'

# WAL设置
wal_level = replica
max_wal_size = 1GB
min_wal_size = 80MB

# 其他
datestyle = 'iso, mdy'
lc_messages = 'en_US.utf8'
lc_monetary = 'en_US.utf8'
lc_numeric = 'en_US.utf8'
lc_time = 'en_US.utf8'
default_text_search_config = 'pg_catalog.english'

 

 

 

 

启动

docker-compose up -d postgres

 

 

 使用 DBeaver 工具连接。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

end.

 

posted @ 2026-01-21 09:35  无心々菜  阅读(0)  评论(0)    收藏  举报