From 5c866121b1e684f9f99e6f6335989924b1ae5433 Mon Sep 17 00:00:00 2001 From: MemRelay Date: Tue, 3 Nov 2026 12:55:11 +0800 Subject: [PATCH] =?UTF-8?q?create:=20=E6=95=B0=E6=8D=AE=E5=BA=93=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97=E6=94=AF=E6=8C=81=20PostgreSQL=20?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MemRelay-Operation: memory-save:metrix-pg-external-fact-20261103-a7c41e MemRelay-Resource: a3039e84-5a34-4ed7-9b3e-88c3037f26f9 --- .../数据库管理模块支持 PostgreSQL 外部连接.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 projects/d5a7f581-c442-4554-87b9-ee723b8b0258/数据库管理模块支持 PostgreSQL 外部连接.md diff --git a/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/数据库管理模块支持 PostgreSQL 外部连接.md b/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/数据库管理模块支持 PostgreSQL 外部连接.md new file mode 100644 index 0000000..38ecd21 --- /dev/null +++ b/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/数据库管理模块支持 PostgreSQL 外部连接.md @@ -0,0 +1,30 @@ +--- +title: 数据库管理模块支持 PostgreSQL 外部连接 +type: fact +permalink: main/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/数据库管理模块支持-postgre-sql-外部连接 +stable_id: a3039e84-5a34-4ed7-9b3e-88c3037f26f9 +scope: project +memory_type: fact +project_id: d5a7f581-c442-4554-87b9-ee723b8b0258 +usage_profile_id: 0c9feb46-d06e-43cd-9ef0-c5813c84a998 +status: active +revision: 1 +request_id: metrix-pg-external-fact-20261103-a7c41e +created_at: '2026-11-03T04:55:06.004949+00:00' +updated_at: '2026-11-03T04:55:06.004949+00:00' +tags: +- database +- postgresql +- fact +--- + +Metrix 数据库管理模块(server/app/modules/database 与 web/src/modules/database)支持 MySQL/MariaDB 和 PostgreSQL 外部连接;平台自身数据库(安装页)仍只支持 SQLite/MySQL。 + +- 方言集中在 engines.py 的 Dialect/DIALECTS:postgresql 使用 psycopg 3(server/requirements.txt 中 psycopg[binary]),URL 前缀 postgresql+psycopg,默认端口 5432,双引号标识符;字段 schema_in_database、backslash_escapes、autocommit_writes、system_schemas/system_schema_prefixes 描述方言差异。 +- PostgreSQL 连接的 default_database 是必填的数据库名(前端默认 postgres,后端校验码 validation.postgresDatabaseRequired);接口里的 database 参数对 PostgreSQL 表示 schema。库表树第一层是 schema(排除 pg_catalog、information_schema、pg_toast*、pg_temp*),界面文案用“模式”,默认选中 public。 +- 选定 schema 时连接建立后执行 SET search_path TO "schema", public;连接 connect_timeout 30 秒,不设 statement_timeout,使用 TCP keepalive 识别断线。单条写语句在 AUTOCOMMIT 下执行(支持 VACUUM 等)。 +- SQL 拆分/分类:遮蔽引号、注释和 $$ 函数体;PostgreSQL 普通字符串不按反斜杠转义;分页识别 LIMIT/OFFSET/FETCH/FOR/LOCK/INTO;SELECT INTO 与含 INSERT/UPDATE/DELETE/MERGE 的 WITH 视为写语句。 +- DDL:自增用 GENERATED BY DEFAULT AS IDENTITY,改列按差异逐项 ALTER COLUMN(TYPE ... USING、NOT NULL、DEFAULT、IDENTITY 开关并 setval、主键约束重建),注释用 COMMENT ON COLUMN,唯一约束索引以 DROP CONSTRAINT 删除,删除 schema 用 CASCADE;建表/改表在单个事务内执行。 +- 导入:CSV 追加/覆盖优先 COPY ... FROM STDIN(失败回退批量插入,空字段为 NULL),upsert 用 ON CONFLICT;SQL 导入在同一会话执行。暂不支持 pg_dump 默认输出的 COPY FROM stdin 数据块。 +- 前端:SQL 编辑器补全使用 Monaco pgsql 关键字/函数(高亮仍是 Shiki sql 语法);服务器信息对 PostgreSQL 只显示版本(SHOW server_version)。 +- 测试:server/tests/test_database_postgres.py,真实库用例由 METRIX_TEST_PG_URL=postgresql://用户:密码@主机:端口/库 开启,未设置时跳过,测试自建并删除随机 schema。 \ No newline at end of file