databricks-lakebase
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLakebase Postgres Autoscaling
Lakebase Postgres 自动扩缩容
FIRST: Use the parent skill for CLI basics, authentication, and profile selection.
databricksLakebase is Databricks' serverless Postgres-compatible database (similar to Neon). It provides fully managed OLTP storage with autoscaling, branching, and scale-to-zero.
Manage Lakebase Postgres projects, branches, endpoints, and databases via CLI commands.
databricks postgres第一步:如需了解CLI基础操作、身份验证和配置文件选择,请使用父级技能。
databricksLakebase是Databricks推出的无服务器Postgres兼容数据库(与Neon类似)。它提供全托管的OLTP存储,支持自动扩缩容、分支功能和缩容至零。
可通过 CLI命令管理Lakebase Postgres的项目、分支、端点和数据库。
databricks postgresResource Hierarchy
资源层级
Project (top-level container)
└── Branch (isolated database environment, copy-on-write)
├── Endpoint (read-write or read-only)
├── Database (standard Postgres DB)
└── Role (Postgres role)- Project: Top-level container. Creating one auto-provisions a branch and a
productionread-write endpoint.primary - Branch: Isolated database environment sharing storage with parent (copy-on-write). States: ,
READY.ARCHIVED - Endpoint (called Compute in the Lakebase UI): Compute resource powering a branch. Types: ,
ENDPOINT_TYPE_READ_WRITE(read replica).ENDPOINT_TYPE_READ_ONLY - Database: Standard Postgres database within a branch. Default: .
databricks_postgres - Role: Postgres role within a branch. Manage roles via .
databricks postgres create-role -h
Project (顶级容器)
└── Branch (隔离的数据库环境,写时复制)
├── Endpoint (读写或只读)
├── Database (标准Postgres数据库)
└── Role (Postgres角色)- Project:顶级容器。创建项目时会自动预配置一个分支和一个
production读写端点。primary - Branch:与父级共享存储的隔离数据库环境(写时复制)。状态包括:、
READY。ARCHIVED - Endpoint(Lakebase UI中称为Compute):为分支提供算力的资源。类型包括:、
ENDPOINT_TYPE_READ_WRITE(只读副本)。ENDPOINT_TYPE_READ_ONLY - Database:分支内的标准Postgres数据库。默认数据库为。
databricks_postgres - Role:分支内的Postgres角色。可通过管理角色。
databricks postgres create-role -h
Resource Name Formats
资源命名格式
| Resource | Format |
|---|---|
| Project | |
| Branch | |
| Endpoint | |
| Database | |
All IDs: 1-63 characters, start with lowercase letter, lowercase letters/numbers/hyphens only (RFC 1123).
| 资源 | 格式 |
|---|---|
| Project | |
| Branch | |
| Endpoint | |
| Database | |
所有ID要求:1-63个字符,以小写字母开头,仅包含小写字母、数字和连字符(符合RFC 1123规范)。
CLI Discovery — ALWAYS Do This First
CLI 命令探索 — 请务必先执行此步骤
Note: "Lakebase" is the product name; the CLI command group is. All commands usepostgres.databricks postgres ...
Do NOT guess command syntax. Discover available commands and their usage dynamically:
bash
undefined注意:产品名称为"Lakebase";CLI命令组为。所有命令均使用postgres格式。databricks postgres ...
请勿猜测命令语法。请动态探索可用命令及其用法:
bash
undefinedList all postgres subcommands
列出所有postgres子命令
databricks postgres -h
databricks postgres -h
Get detailed usage for any subcommand (flags, args, JSON fields)
获取任意子命令的详细用法(参数、选项、JSON字段)
databricks postgres <subcommand> -h
Run `databricks postgres -h` before constructing any command. Run `databricks postgres <subcommand> -h` to discover exact flags, positional arguments, and JSON spec fields for that subcommand.databricks postgres <subcommand> -h
在构造任何命令之前,请先运行`databricks postgres -h`。运行`databricks postgres <subcommand> -h`可查看该子命令的确切参数、位置变量和JSON规范字段。Create a Project
创建项目
Do NOT list projects before creating.
bash
databricks postgres create-project <PROJECT_ID> \
--json '{"spec": {"display_name": "<DISPLAY_NAME>"}}' \
--profile <PROFILE>- Auto-creates: branch +
productionread-write endpoint (1 CU min/max, scale-to-zero)primary - Long-running operation; the CLI waits for completion by default. Use to return immediately.
--no-wait - Run for all available spec fields (e.g.
databricks postgres create-project -h).pg_version
After creation, verify the auto-provisioned resources:
bash
databricks postgres list-branches projects/<PROJECT_ID> --profile <PROFILE>
databricks postgres list-endpoints projects/<PROJECT_ID>/branches/<BRANCH_ID> --profile <PROFILE>
databricks postgres list-databases projects/<PROJECT_ID>/branches/<BRANCH_ID> --profile <PROFILE>请勿在创建项目前列出项目。
bash
databricks postgres create-project <PROJECT_ID> \
--json '{"spec": {"display_name": "<DISPLAY_NAME>"}}' \
--profile <PROFILE>- 自动创建:分支 +
production读写端点(最小/最大1 CU,支持缩容至零)primary - 属于长时间运行的操作;默认情况下CLI会等待操作完成。使用参数可立即返回。
--no-wait - 运行查看所有可用的规范字段(例如
databricks postgres create-project -h)。pg_version
创建完成后,验证自动预配置的资源:
bash
databricks postgres list-branches projects/<PROJECT_ID> --profile <PROFILE>
databricks postgres list-endpoints projects/<PROJECT_ID>/branches/<BRANCH_ID> --profile <PROFILE>
databricks postgres list-databases projects/<PROJECT_ID>/branches/<BRANCH_ID> --profile <PROFILE>Autoscaling
自动扩缩容
Endpoints use compute units (CU) for autoscaling. Configure min/max CU via or . Run to see all spec fields.
create-endpointupdate-endpointdatabricks postgres create-endpoint -hScale-to-zero is enabled by default. When idle, compute scales down to zero; it resumes in seconds on next connection.
端点使用**计算单元(CU)**实现自动扩缩容。可通过或配置最小/最大CU值。运行查看所有规范字段。
create-endpointupdate-endpointdatabricks postgres create-endpoint -h默认启用缩容至零功能。当端点处于空闲状态时,计算资源会缩容至零;下次有连接请求时,会在数秒内恢复。
Branches
分支
Branches are copy-on-write snapshots of an existing branch. Use them for experimentation: testing schema migrations, trying queries, or previewing data changes -- without affecting production.
bash
databricks postgres create-branch projects/<PROJECT_ID> <BRANCH_ID> \
--json '{
"spec": {
"source_branch": "projects/<PROJECT_ID>/branches/<SOURCE_BRANCH_ID>",
"no_expiry": true
}
}' --profile <PROFILE>Branches require an expiration policy: use for permanent branches.
"no_expiry": trueWhen done experimenting, delete the branch. Protected branches must be unprotected first -- use to set to , then delete:
update-branchspec.is_protectedfalsebash
undefined分支是现有分支的写时复制快照。可用于实验场景:测试架构迁移、尝试查询或预览数据变更——且不会影响生产环境。
bash
databricks postgres create-branch projects/<PROJECT_ID> <BRANCH_ID> \
--json '{
"spec": {
"source_branch": "projects/<PROJECT_ID>/branches/<SOURCE_BRANCH_ID>",
"no_expiry": true
}
}' --profile <PROFILE>分支需要设置过期策略:如需创建永久分支,请使用。
"no_expiry": true实验完成后,可删除分支。受保护的分支需先取消保护——使用将设置为,然后再删除:
update-branchspec.is_protectedfalsebash
undefinedStep 1 — unprotect
第一步 — 取消保护
databricks postgres update-branch projects/<PROJECT_ID>/branches/<BRANCH_ID>
--json '{"spec": {"is_protected": false}}' --profile <PROFILE>
--json '{"spec": {"is_protected": false}}' --profile <PROFILE>
databricks postgres update-branch projects/<PROJECT_ID>/branches/<BRANCH_ID>
--json '{"spec": {"is_protected": false}}' --profile <PROFILE>
--json '{"spec": {"is_protected": false}}' --profile <PROFILE>
Step 2 — delete (run -h to confirm positional arg format for your CLI version)
第二步 — 删除(运行-h确认你的CLI版本对应的位置参数格式)
databricks postgres delete-branch projects/<PROJECT_ID>/branches/<BRANCH_ID>
--profile <PROFILE>
--profile <PROFILE>
**Never delete the `production` branch** — it is the authoritative branch auto-provisioned at project creation.databricks postgres delete-branch projects/<PROJECT_ID>/branches/<BRANCH_ID>
--profile <PROFILE>
--profile <PROFILE>
**请勿删除`production`分支**——它是项目创建时自动预配置的权威分支。What's Next
后续操作
Build a Databricks App
构建Databricks应用
After creating a Lakebase project, scaffold a Databricks App connected to it.
Step 1 — Discover branch name (use from a branch):
.nameREADYbash
databricks postgres list-branches projects/<PROJECT_ID> --profile <PROFILE>Step 2 — Discover database name (use from the desired database; is the branch ID, not the full resource name):
.name<BRANCH_ID>bash
databricks postgres list-databases projects/<PROJECT_ID>/branches/<BRANCH_ID> --profile <PROFILE>Step 3 — Scaffold the app with the feature:
lakebasebash
databricks apps init --name <APP_NAME> \
--features lakebase \
--set "lakebase.postgres.branch=<BRANCH_NAME>" \
--set "lakebase.postgres.database=<DATABASE_NAME>" \
--run none --profile <PROFILE>Where is the full resource name (e.g. ) and is the full resource name (e.g. ).
<BRANCH_NAME>projects/<PROJECT_ID>/branches/<BRANCH_ID><DATABASE_NAME>projects/<PROJECT_ID>/branches/<BRANCH_ID>/databases/<DB_ID>For the full app development workflow, use the skill.
databricks-apps创建Lakebase项目后,可搭建一个连接到该项目的Databricks应用。
第一步 — 查看分支名称(从状态的分支中获取字段):
READY.namebash
databricks postgres list-branches projects/<PROJECT_ID> --profile <PROFILE>第二步 — 查看数据库名称(从目标数据库中获取字段;为分支ID,而非完整资源名称):
.name<BRANCH_ID>bash
databricks postgres list-databases projects/<PROJECT_ID>/branches/<BRANCH_ID> --profile <PROFILE>第三步 — 使用功能搭建应用:
lakebasebash
databricks apps init --name <APP_NAME> \
--features lakebase \
--set "lakebase.postgres.branch=<BRANCH_NAME>" \
--set "lakebase.postgres.database=<DATABASE_NAME>" \
--run none --profile <PROFILE>其中为完整资源名称(例如),为完整资源名称(例如)。
<BRANCH_NAME>projects/<PROJECT_ID>/branches/<BRANCH_ID><DATABASE_NAME>projects/<PROJECT_ID>/branches/<BRANCH_ID>/databases/<DB_ID>如需了解完整的应用开发流程,请使用****技能。
databricks-appsOther Workflows
其他工作流
Connect a Postgres client
Get the connection string from the endpoint, then connect with psql, DBeaver, or any standard Postgres client.
bash
databricks postgres get-endpoint projects/<PROJECT_ID>/branches/<BRANCH_ID>/endpoints/<ENDPOINT_ID> --profile <PROFILE>Manage roles and permissions
Create Postgres roles and grant access to databases or schemas.
bash
databricks postgres create-role -h # discover role spec fieldsAdd a read-only endpoint
Create a read replica for analytics or reporting workloads to avoid contention on the primary read-write endpoint.
bash
databricks postgres create-endpoint projects/<PROJECT_ID>/branches/<BRANCH_ID> <ENDPOINT_ID> \
--json '{"spec": {"type": "ENDPOINT_TYPE_READ_ONLY"}}' --profile <PROFILE>连接Postgres客户端
从端点获取连接字符串,然后使用psql、DBeaver或任何标准Postgres客户端进行连接。
bash
databricks postgres get-endpoint projects/<PROJECT_ID>/branches/<BRANCH_ID>/endpoints/<ENDPOINT_ID> --profile <PROFILE>管理角色和权限
创建Postgres角色,并授予数据库或模式的访问权限。
bash
databricks postgres create-role -h # 探索角色规范字段添加只读端点
为分析或报表工作负载创建只读副本,避免对主读写端点造成资源竞争。
bash
databricks postgres create-endpoint projects/<PROJECT_ID>/branches/<BRANCH_ID> <ENDPOINT_ID> \
--json '{"spec": {"type": "ENDPOINT_TYPE_READ_ONLY"}}' --profile <PROFILE>Troubleshooting
故障排除
| Error | Solution |
|---|---|
| Use |
| Check workspace permissions |
| Protected branch cannot be deleted | |
| Long-running operation timeout | Use |
| 错误 | 解决方案 |
|---|---|
| 使用 |
| 检查工作区权限 |
| 受保护分支无法删除 | 先使用 |
| 长时间运行的操作超时 | 使用 |