Docker ps
Windows 下 Docker 部署 PostgreSQL&pgvector后新建库和表:解决模板冲突与 PowerShell 管道兼容问题
Docker ps 确认现有容器名字postgre-vector

容器里面还没有 health_assistant 数据库
进入容器内部 psql:docker exec -it pg‑vector psql -U postgres

3.执行建库 SQL
CREATE DATABASE health_assistant

4.\q 退出 psql

5.导入 schema 脚本
docker exec -i postgres-vector psql -U postgres -d health_assistant < data/schema.sql 报错了,因为我之间也有一个模版template,起冲突了
5.1 解决问题1 模版冲突

template1模板库排序 collation 版本不匹配,已经变成错误,不能直接新建数据库。
这个是容器镜像升级 / 底层 debian 系统字符集版本变更导致,template1损坏。
解决方法 A:用 template0 模板创建数据库(直接当前 psql 里面执行)
CREATE DATABASE health_assistant TEMPLATE template0;
\q

5.2 windows 里面不能直接创建schema.sql,绕开 powershell 管道问题
docker exec -i postgres-vector psql -U postgres -d health_assistant < data/schema.sql
\dt 还是有问题。
解决方法 Windows系统创建好schema.sql 再复制到Docker
在windows 系统里面,将你 Windows 项目里的 data/schema.sql 拷贝进 docker 容器的 /tmp
docker cp data/schema.sql postgres-vector:/tmp/schema.sql

docker exec -it postgres-vector bash 再进入容器内部
在容器内部执行建表,在容器内部执行
psql -U postgres -d health_assistant -f /tmp/schema.sql
进去查看表
psql -U postgres -d health_assistant
\dt


浙公网安备 33010602011771号