databend icon indicating copy to clipboard operation
databend copied to clipboard

feat: database level default connection configuration

Open dantengsky opened this issue 1 month ago โ€ข 4 comments

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Two New Database-Level Options

DEFAULT_STORAGE_CONNECTION, DEFAULT_STORAGE_PATH

These options define the default storage connection and path for the database. Any table created in the database without explicit storage settings will inherit these database-level defaults.

You can set the options when creating the database, or adjust them later with ALTER DATABASE.

Example

CREATE CONNECTION IF NOT EXISTS prod_s3
  STORAGE_TYPE = 's3'
  ACCESS_KEY_ID = '***'
  SECRET_ACCESS_KEY = '***';

CREATE DATABASE analytics OPTIONS (
  DEFAULT_STORAGE_CONNECTION = 'prod_s3',
  DEFAULT_STORAGE_PATH = 's3://mybucket/analytics/'
);

SHOW CREATE DATABASE analytics;

+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| Database  | Create Database                                                                                                                                   |
+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| analytics | CREATE DATABASE `analytics` ENGINE=DEFAULT OPTIONS (DEFAULT_STORAGE_CONNECTION='prod_s3', DEFAULT_STORAGE_PATH='s3://mybucket/analytics/') |
+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------+

USE analytics;

CREATE TABLE t AS SELECT 1;

SELECT storage_param
FROM system.tables
WHERE database = 'analytics' AND name = 't';

+-------------------------------------------------------------------------------------------------------+
| storage_param                                                                                         |
+-------------------------------------------------------------------------------------------------------+
| s3 | bucket=mybucket,root=/analytics/,endpoint=https://s3.amazonaws.com,ak=******,iam_role=           |
+-------------------------------------------------------------------------------------------------------+

ALTER DATABASE analytics SET OPTIONS (
  DEFAULT_STORAGE_PATH = 's3://mybucket/analytics_v2/'
);

CREATE TABLE t_v2 AS SELECT 1;

SELECT storage_param
FROM system.tables
WHERE database = 'analytics' AND name = 't_v2';

+----------------------------------------------------------------------------------------------------------+
| storage_param                                                                                            |
+----------------------------------------------------------------------------------------------------------+
| s3 | bucket=mybucket,root=/analytics_v2/,endpoint=https://s3.amazonaws.com,ak=******,iam_role=           |
+----------------------------------------------------------------------------------------------------------+

Notes:

  • When creating a database you cannot supply only one of DEFAULT_STORAGE_CONNECTION or DEFAULT_STORAGE_PATH; they must appear together or both be omitted.

  • When altering an existing database you may change one option at a time as long as the other option already exists; otherwise the command fails.

  • During CREATE DATABASE/ALTER DATABASE, connection reachability and storage path permissions are validated.

  • Updating these database-level options does not change storage parameters of existing tables; only tables created afterwards use the new defaults.

  • fixes: #18825

Tests

  • [x] Unit Test
  • [x] Logic Test
  • [ ] Benchmark Test
  • [ ] No Test - Explain why

Type of change

  • [ ] Bug Fix (non-breaking change which fixes an issue)
  • [x] New Feature (non-breaking change which adds functionality)
  • [ ] Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • [ ] Documentation Update
  • [ ] Refactoring
  • [ ] Performance Improvement
  • [ ] Other (please describe):

This change isโ€‚Reviewable

dantengsky avatar Oct 23 '25 07:10 dantengsky

@codex review

dantengsky avatar Dec 09 '25 04:12 dantengsky

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. Repo admins can enable using credits for code reviews in their settings.

@codex review

dantengsky avatar Dec 10 '25 02:12 dantengsky

Codex Review: Didn't find any major issues. Hooray!

โ„น๏ธ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with ๐Ÿ‘.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".