Skip to content

Conversation

@dantengsky
Copy link
Member

@dantengsky dantengsky commented Oct 23, 2025

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: Feature Request: Database level default connection configuration #18825

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • 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

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Oct 23, 2025
@dantengsky dantengsky force-pushed the feat/db-level-connection branch from e649fb2 to f778e9b Compare October 28, 2025 12:59
@dantengsky dantengsky marked this pull request as ready for review November 4, 2025 06:10
@dantengsky dantengsky force-pushed the feat/db-level-connection branch from fe1a632 to 1d719d7 Compare December 9, 2025 01:58
@dantengsky
Copy link
Member Author

@codex review

@chatgpt-codex-connector
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature this PR introduces a new feature to the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Database level default connection configuration

1 participant