示例:
01.打开数据库 --duckdb to run the executable
simply include a path as a command line argument like duckdb path/to/my_database.duckdb
duckdb #这个是 in-memory database
或者
duckdb path/to/my_database.duckdb ##创建或者打开openorcreate a database at that location as needed
02.连接数据库
DuckDB 支持内存型和持久化型两种工作模式
内存型不持久化数据,采用 InMemoryBlockManager 来管理数据,
DuckDB 采用 SingleFileBlockManager 来管理外存上的数据
SingleFile 的数据划分成定长块,包括两大类:header 和 block
.show
DuckDB, bydefault, connects to a transient in-memory database.
In other words, when the process is terminated, the data loaded is flushed
.open
eg:
mytest.db
mytest.db.wal < the write-ahead log file>
Essentially the WAL contains a list ofall the changes that have been committed/written to disk, but have not been checkpointed
https://sqlite.org/wal.html
https://github.com/duckdb/duckdb/issues/301
事务的支持有两种模式:
回滚模式 (Rollback mode)。在事务处理中,SQLite 把原本的页写入到回滚日志中并且把修改的页写入到数据库文件中。
该模式同时支持 DELETE 和 TRUNCATE 两种子模式。
预写式日志模式 (Write-ahead log mode)。
在事务处理中,不修改原本的页而是把修改的页追加写到单独的预写式日志文件中。
预写式日志模式可以支持更高的并发度并且常常有更好的性能。
但是相较于回滚模式,预写式日志模式不能用于网络文件系统并会增加整体文件管理的复杂度。
数据导入
数据导入导出方面,支持CVS/Parquet/S3 Parquet导入导出
reads Parquet, CSV and JSON files from either your local filesystem or HTTP servers
the database parameterto the connectmethod persists all further changes.
Two new files will be created.
Loading the data
中途保存
.backup
退出程序
.quit
mytest.db
DBeaver SQL IDE for DuckDB
https://duckdb.org/docs/guides/sql_editors/dbeaver
https://central.sonatype.com/artifact/org.duckdb/duckdb_jdbc/0.7.1
https://repo1.maven.org/maven2/org/duckdb/duckdb_jdbc/0.7.1/
JDBC URL to: jdbc:duckdb:/home/<LOCAL_PATH>/db.duckdb
Path to: /home/<LOCAL_PATH>/db.duckdb
命令方式
dot commands 点式命令
begin the line with a period (.) immediately followed by the name of the command you wish toexecute
扩展
查看扩展--select * from duckdb_extensions();
JSON Import/Export
When the JSON extension is installed, FORMAT JSON is supported forCOPYFROM, COPYTO, EXPORT DATABASE and IMPORT DATABASE. See Copyand Import/Export.
从S3中下载扩展
从S3中下载扩展
D:\annotation\corner.json
线上命令
https://shell.duckdb.org/
数据库是查询引擎和储存系统的结合,但现在好像单独的查询引擎或储存系统都可以算是数据库了,它们的边界在一点点模糊
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)