PostgreSQL

安装

docker-compose安装

cat <<EOF > docker-compose.yaml
version: '3.8'
services:
  db:
    image: harbor.qihoo.net/finloan-infra-library/postgres:15-alpine
    restart: always
    environment:
      POSTGRES_USER: postgres
      # The password for the default postgres user.
      POSTGRES_PASSWORD: difyai123456
      # The name of the default postgres database.
      POSTGRES_DB: dify
      # postgres data directory
      PGDATA: /var/lib/postgresql/data/pgdata
	shm_size: '16gb'  # shared memory
	command: postgres -c 'max_connections=10000'
    volumes:
      - /data/postgre:/var/lib/postgresql/data
    # uncomment to expose db(postgresql) port to host
    ports:
      - "5432:5432"
    healthcheck:
      test: [ "CMD", "pg_isready" ]
      interval: 1s
      timeout: 3s
      retries: 30
EOF

docker compose up -d

运维

修改最大连接数

pg默认最大连接数是100,如果你的pod已经启动过了,需要去修改配置文件才能生效;

psql
# 查看配置文件所在路径: /var/lib/postgresql/data/pgdata/postgresql.conf
show config_file;
exit

# 修改配置文件中的最大连接数
sed -i 's/^max_connections[ ]*=.*.*/max_connections = 10000/' /var/lib/postgresql/data/pgdata/postgresql.conf
# 重启容器
docker compose restart

常用命令

# 连接当前库
psql
# 连接指定库
psql -h localhost -p 5432 -U postgres -d dify

# 列出所有数据库
\l
# 当前链接的库
select current_database();
# 连接到其他数据库
\c otherdb
# 查看数据库的模式
\dn

# 列出所有的表
\dt
# 查看特定的表结果
\d tablename
\d+ tablename

# 显示当前连接信息
\conninfo
# 显示命令历史
\s
# 重复执行上一条命令
\g
# 保存查询结果到文件
\o filename
select * from mytable;
\o
# 执行文件中的sql
\i filename.sql

相关推荐

  1. PostgreSQL

    2024-07-11 03:34:03       40 阅读
  2. PostgreSQL

    2024-07-11 03:34:03       21 阅读
  3. PostgreSQLPostgreSQL详细介绍

    2024-07-11 03:34:03       57 阅读
  4. PostgreSql 规则

    2024-07-11 03:34:03       39 阅读
  5. PostgreSql 序列

    2024-07-11 03:34:03       43 阅读
  6. Postgresql部署

    2024-07-11 03:34:03       44 阅读
  7. postgresql 序列

    2024-07-11 03:34:03       44 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 03:34:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 03:34:03       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 03:34:03       58 阅读
  4. Python语言-面向对象

    2024-07-11 03:34:03       69 阅读

热门阅读

  1. Perl词法切分器:文本解析的瑞士军刀

    2024-07-11 03:34:03       18 阅读
  2. 解决Spring Boot中的安全漏洞与防护策略

    2024-07-11 03:34:03       21 阅读
  3. 二、Python日志系统之watchDog监控日志

    2024-07-11 03:34:03       22 阅读
  4. 如何预防SQL注入

    2024-07-11 03:34:03       22 阅读
  5. 1、预处理

    2024-07-11 03:34:03       23 阅读
  6. Jmeter进阶-接口自动化

    2024-07-11 03:34:03       17 阅读
  7. 在 Ubuntu 上玩转 WordPress

    2024-07-11 03:34:03       24 阅读
  8. Redis 数据过期及淘汰策略

    2024-07-11 03:34:03       21 阅读