欢迎光临
我们一直在努力

wsl docker安装试用金仓数据库kingbase v9

安装说明详细版 安装说明简略版

下载安装镜像

我选择了X64_Linux 730M 25-08-04这个版本,下载需要填写手机号,随便输入即可,不需要接收验证码。实际地址是 https://kingbase.oss-cn-beijing.aliyuncs.com/upload/KESV9-baseline/allmode/V009R001C010/docker/KingbaseES_V009R001C010B0004_x86_64_Docker.tar

将它保存到c:\\d目录。

下载授权文件 https://www.kingbase.com.cn/download.html#authorization?authorcurrV=V9R1C10 (这步对docker 不需要)

安装步骤如下, 1.装载下载的tar文件

Microsoft Windows [版本 10.0.26100.7462]
(c) Microsoft Corporation。保留所有权利。

C:\\Users\\lt>wsl
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker image list -a |grep king
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker load -i /par/KingbaseES_V009R001C010B0004_x86_64_Docker.tar
Error: stat /par/KingbaseES_V009R001C010B0004_x86_64_Docker.tar: no such file or directory
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker load -i /mnt/c/d/KingbaseES_V009R001C010B0004_x86_64_Docker.tar
Getting image source signatures
Copying blob ab160c240055 done
Copying blob 3bf7b9f505f0 done
Copying blob 4f4afaf05775 done
Copying blob a57365b3e1c7 done
Copying blob ffef0f11c393 done
Copying blob 96723fcc60ed done
Copying blob e8f0faf49018 done
Copying blob 3bf7b9f505f0 skipped: already exists
Copying blob 0503f5558886 done
Copying blob 561e0a6710a3 done
Copying config 10ba6f33e2 done
Writing manifest to image destination
Storing signatures
Loaded image(s): localhost/kingbase_v009r001c010b0004_single_x86:v1

2.运行容器 这里有个坑,我从官方 https://docs.kingbase.com.cn/cn/KES-V9R1C10/quick_start/install/docker-install 页面复制的命令行有个字符是错误的,就是-v的减号,页面上是另一个字符,后面会显示它的ascii码,费了不少功夫排错。 还有个坑是镜像名,不叫kingbase:v1,而是很长的一串,用docker image list可以查询,为了简略,用hash值前几位代替。

root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker run -tid –privileged -p 54321:54321 –name kingbase –v /mnt/c/d:/par kingbase:v1 /usr/sbin/init
Error: invalid reference format
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker image list -a |grep king
localhost/kingbase_v009r001c010b0004_single_x86 v1 10ba6f33e228 6 months ago 766 MB
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker run -tid –privileged -p 54321:54321 –name kingbase –v /mnt/c/d:/par 10ba6f33e228 /usr/sbin/init
Error: invalid reference format
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker run -tid –privileged -p 54321:54321 –name kingbase –v /mnt/c/d:/par localhost/kingbase_v009r001c010b0004_single_x86:v1 /usr/sbi
n/init
Error: invalid reference format
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker run -tid –privileged -p 54321:54321 –name kingbase -v /mnt/c/d:/par 10ba6f33e228 /usr/sbin/init
e12ce54039f3171a0fa3f8f67f80e8249818bce3735dbc213b70aa3438d8b8ca

3.查看容器运行日志。确实成功启动了数据库服务。

root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker logs kingbase
export KINGBASE_USER=system
export KINGBASE_DATABASE=kingbase
[Sun 25 Jan 2026 12:28:45 PM UTC]start initdb…
The database cluster will be initialized with locale "en_US.UTF-8".
The files belonging to this database system will be owned by user "kingbase".
This user must also own the server process.

The default text search configuration will be set to "english".

The comparision of strings is case-sensitive.
Data page checksums are disabled.

fixing permissions on existing directory /home/kingbase/userdata/data … ok
creating subdirectories … ok
selecting dynamic shared memory implementation … posix
selecting default max_connections … 100
selecting default shared_buffers … 128MB
selecting default time zone … UTC
creating configuration files … ok
Begin setup encrypt device
initializing the encrypt device … ok
running bootstrap script … ok
performing post-bootstrap initialization … ok
create security database … ok
load security database … ok
syncing data to disk … ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing sys_hba.conf or using the option -A, or
–auth-local and –auth-host, the next time you run initdb.

Success. You can now start the database server using:

/home/kingbase/install/kingbase/bin/sys_ctl -D /home/kingbase/userdata/data -l logfile start

[Sun 25 Jan 2026 12:28:49 PM UTC]start initdb…ok
waiting for server to start…. done
server started
* * * * * kingbase /home/kingbase/docker-entrypoint.sh check_and_run /home/kingbase/userdata/data >> /home/kingbase/cronlog

4.登录镜像服务器命令行,连接数据库,这里犯了一个经验主义错误,金仓的命令行工具叫ksql, 不是psql。

root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker exec -it kingbase bash

Welcome to 5.15.167.4-microsoft-standard-WSL2

System information as of time: Sun 25 Jan 2026 12:33:27 PM UTC

System load: 0.07
Processes: 19
Memory used: 4.8%
Swap used: 0.0%
Usage On: 48%
Users online: 0

[kingbase@e12ce54039f3 ~]$ \\timing on
bash: timing: command not found
[kingbase@e12ce54039f3 ~]$ psql
bash: psql: command not found
[kingbase@e12ce54039f3 ~]$ ksql
License Type: 企业版.
Type "help" for help.

用它运行数独求解SQL,报错了,原因是它的除法运算符和postgresql不同,整除相除结果是小数。

kingbase=# \\timing on
Timing is on.

kingbase=# \\i /par/1230/ltpg0104fcda.txt
ksql:/par/1230/ltpg0104fcda.txt:77: ERROR: operator does not exist: bigint << double precision
LINE 29: ,case when(grid.r*9+n-1)>42 then 1::bigint << (grid.r*…
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Time: 3.049 ms
kingbase=# select 1/3;
?column?
——————–
0.3333333333333333
(1 row)

Time: 2.689 ms
kingbase=# select 1//3;
ERROR: operator does not exist: integer // integer
LINE 1: select 1//3;
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Time: 1.192 ms

把相应代码中的强制转成整数,

grid AS (
SELECT lp AS pos
,((lp1)/9)::int AS r
,((lp1)%9)::int AS c
,((lp1)/9/3*3 + (lp1)%9/3)::int AS g
FROM d
)

能执行,结果还是不对。

kingbase=# \\i /par/1230/ltpg0104fcdakb.txt
id | puzzle | result
—-+———–+——–
| ????????3+|
| ??1??56??+|
| ?9??4??7?+|
| ?????9?5?+|
| 7???????8+|
| ?5?4?2???+|
| ?8??2??9?+|
| ??35??1??+|
| 6???????? |
(1 row)

Time: 5026.349 ms (00:05.026)

用select * from grid limit 10;打印出grid的内容, 看出来问题了,是我忘记向下取整floor,结果转整数时四舍五入了。

kingbase=# \\i /par/1230/ltpg0104fcdakb.txt
pos | r | c | g
—–+—+—+—
1 | 0 | 0 | 0
2 | 0 | 1 | 0
3 | 0 | 2 | 1
4 | 0 | 3 | 1
5 | 0 | 4 | 2
6 | 1 | 5 | 2
7 | 1 | 6 | 3
8 | 1 | 7 | 3
9 | 1 | 8 | 4
10 | 1 | 0 | 1
(10 rows)

Time: 0.553 ms

再改为

grid AS (
SELECT lp AS pos
,floor((lp1)/9)::int AS r
,floor((lp1)%9)::int AS c
,(floor((lp1)/27)*3)::int + floor((lp1)%9/3)::int AS g
FROM d
)

再打印就对了

kingbase=# \\i /par/1230/ltpg0104fcdakb.txt
pos | r | c | g
—–+—+—+—
1 | 0 | 0 | 0
2 | 0 | 1 | 0
3 | 0 | 2 | 0
4 | 0 | 3 | 1
5 | 0 | 4 | 1
6 | 0 | 5 | 1
7 | 0 | 6 | 2
8 | 0 | 7 | 2
9 | 0 | 8 | 2
10 | 1 | 0 | 0
11 | 1 | 1 | 0
12 | 1 | 2 | 0
13 | 1 | 3 | 1
14 | 1 | 4 | 1
15 | 1 | 5 | 1
16 | 1 | 6 | 2

再让它递归求解,终于算对了,真不容易。

kingbase=# \\i /par/1230/ltpg0104fcdakb.txt
id | puzzle | result
—-+———–+———–
3 | 8????????+| 812753649+
| ??36?????+| 943682175+
| ?7??9?2??+| 675491283+
| ?5???7???+| 154237896+
| ????457??+| 369845721+
| ???1???3?+| 287169534+
| ??1????68+| 521974368+
| ??85???1?+| 438526917+
| ?9????4?? | 796318452
(1 row)

Time: 4162.093 ms (00:04.162)

再来看一开始的错误字符’–',它是一个全角字符,ascii码8211, 而半角减号的ascii码45。

kingbase=# select ascii('–');
ascii
——-
8211
(1 row)

Time: 1.924 ms
kingbase=# select ascii('-');
ascii
——-
45
(1 row)

Time: 0.328 ms

赞(0)
未经允许不得转载:171主机测评 » wsl docker安装试用金仓数据库kingbase v9
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址