利用Docker安装PostgreSQL 19 dev版

PostgreSQL官方只提供了正式版的镜像,想要试用dev版,又不想自己编译。结果在下面这个网站找到了一个,

https://github.com/ryanbooz/bluebox-docker

它不是纯净的官方版本,自带了一些初始化脚本,正好用来试验。

  1. 拉取镜像

    sudo docker pull ghcr.io/ryanbooz/bluebox-postgres:19-dev
    [sudo] kylin 的密码:
    19-dev: Pulling from ryanbooz/bluebox-postgres
    d3d5d8ab26d2: Pull complete
    c389a2748e7f: Pull complete
    c8129a85d9e1: Pull complete
    7f4f950f4a59: Pull complete
    d1e0edeeb42f: Pull complete
    e58d32278daa: Pull complete
    d5876f284dbc: Pull complete
    f01cc50a7497: Pull complete
    4f4fb700ef54: Pull complete
    Digest: sha256:253d42b69d62692f3aa82a976702e4ff389092025ad9ceb2a58b5f6089d15378
    Status: Downloaded newer image for ghcr.io/ryanbooz/bluebox-postgres:19-dev
    sudo docker image list -a|grep blue
    ghcr.io/ryanbooz/bluebox-postgres 19-dev a37dec750520 6 days ago 595MB

2.运行容器,注意如果宿主机上有postgres服务正在运行, 不要用-p 5432:5432参数,否则报错,下面用--net=host参数。

复制代码
sudo docker run --name pg19dev -e POSTGRES_PASSWORD=password -e POSTGRES_DB=mydb -v /shujv/par:/par --net=host a37dec750520
Initializing PostgreSQL database...
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are enabled.

fixing permissions on existing directory /var/lib/postgresql/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 ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

waiting for server to start....2026-02-13 00:11:15.207 UTC [37] LOG:  starting PostgreSQL 19devel on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit
2026-02-13 00:11:15.219 UTC [37] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2026-02-13 00:11:15.256 UTC [43] LOG:  database system was shut down at 2026-02-13 00:11:14 UTC
2026-02-13 00:11:15.269 UTC [37] LOG:  database system is ready to accept connections
 done
server started
Running /docker-entrypoint-initdb.d/01-create-roles-and-database.sql
....

PostgreSQL initialization complete.
2026-02-13 00:15:17.152 UTC [1] LOG:  starting PostgreSQL 19devel on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit
2026-02-13 00:15:17.152 UTC [1] LOG:  could not bind IPv4 address "0.0.0.0": Address already in use
2026-02-13 00:15:17.152 UTC [1] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2026-02-13 00:15:17.152 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2026-02-13 00:15:17.174 UTC [1] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2026-02-13 00:15:17.202 UTC [104] LOG:  database system was shut down at 2026-02-13 00:15:16 UTC
2026-02-13 00:15:17.216 UTC [1] LOG:  database system is ready to accept connections
2026-02-13 00:15:17.237 UTC [107] LOG:  pg_cron scheduler started

初始化脚本的输出很长,截断了。

3.服务端在前台显示,如果想要切换到后台,可用^C中断,然后重新启动服务。

复制代码
2026-02-13 00:17:08.473 UTC [1] LOG:  received fast shutdown request
2026-02-13 00:17:08.484 UTC [1] LOG:  aborting any active transactions
2026-02-13 00:17:08.484 UTC [107] LOG:  pg_cron scheduler shutting down
2026-02-13 00:17:08.485 UTC [1] LOG:  background worker "logical replication launcher" (PID 108) exited with exit code 1
2026-02-13 00:17:08.485 UTC [1] LOG:  background worker "pg_cron launcher" (PID 107) exited with exit code 1
2026-02-13 00:17:08.486 UTC [102] LOG:  shutting down
2026-02-13 00:17:08.496 UTC [102] LOG:  checkpoint starting: shutdown fast
2026-02-13 00:17:08.688 UTC [102] LOG:  checkpoint complete: wrote 18 buffers (0.1%), wrote 3 SLRU buffers; 0 WAL file(s) added, 6 removed, 0 recycled; write=0.024 s, sync=0.039 s, total=0.203 s; sync files=17, longest=0.011 s, average=0.003 s; distance=106191 kB, estimate=106191 kB; lsn=0/AAA133C8, redo lsn=0/AAA133C8
2026-02-13 00:17:08.747 UTC [1] LOG:  database system is shut down

sudo docker start pg19dev
pg19dev

4.就可以用docker exec -it登录容器执行操作了。

复制代码
sudo docker exec -it pg19dev psql -U bb_admin -d bluebox
psql (19devel)
Type "help" for help.

bluebox=> 
bluebox=> -- Current status
SELECT 
    (SELECT count(*) FROM bluebox.rental WHERE upper(rental_period) IS NULL) as open_rentals,
    (SELECT count(*) FROM bluebox.customer WHERE activebool) as active_customers,
    (SELECT count(*) FROM bluebox.inventory WHERE status_id = 1) as inventory_available;
 open_rentals | active_customers | inventory_available 
--------------+------------------+---------------------
         1843 |           174980 |             1462726
(1 row)

bluebox=> -- Daily rental volume
SELECT 
    lower(rental_period)::date as day,
    count(*) as rentals,
    sum(p.amount) as revenue
FROM bluebox.rental r
JOIN bluebox.payment p USING (rental_id)
WHERE lower(rental_period) > now() - interval '7 days'
GROUP BY 1 ORDER BY 1;
 day | rentals | revenue 
-----+---------+---------
(0 rows)

bluebox=> -- Top rented films
SELECT f.title, count(*) as rentals
FROM bluebox.rental r
JOIN bluebox.inventory i USING (inventory_id)
JOIN bluebox.film f USING (film_id)
WHERE lower(rental_period) > now() - interval '30 days'
GROUP BY f.film_id, f.title
ORDER BY rentals DESC
LIMIT 10;
                     title                     | rentals 
-----------------------------------------------+---------
 Haunted Mansion                               |     164
 Elemental                                     |     162
 Gran Turismo                                  |     153
 Fast X                                        |     149
 Meg 2: The Trench                             |     145
 Blue Beetle                                   |     142
 Sound of Freedom                              |     142
 Megamind vs. the Doom Syndicate               |     140
 Transformers: Rise of the Beasts              |     139
 Mission: Impossible - Dead Reckoning Part One |     138
(10 rows)

bluebox=> -- Customer churn analysis
SELECT 
    date_trunc('month', status_date) as month,
    count(*) FILTER (WHERE reason_code = 'inactivity') as churned,
    count(*) FILTER (WHERE reason_code = 'winback') as reactivated
FROM bluebox.customer_status_log
WHERE reason_code IN ('inactivity', 'winback')
GROUP BY 1 ORDER BY 1;
         month          | churned | reactivated 
------------------------+---------+-------------
 2026-02-01 00:00:00+00 |    3071 |          60
(1 row)

试验了上述网站的几个测试SQL,还测试了一个复现postgres 18.1的bug的SQL,结果显示,bug已被修复。

复制代码
bluebox=> with cte as (select array[g, 2] as a from generate_series(1, 3) g) select a[2], a[(select a[2])] from cte;
 a | a 
---+---
 2 | 2
 2 | 2
 2 | 2
(3 rows)


bluebox=> with cte as (select array[g, 2] as a from generate_series(1, 3) g)select * from cte;
   a   
-------
 {1,2}
 {2,2}
 {3,2}
(3 rows)

以前在同一台机器上拉取官方18.1镜像,docker run不能启动,这个镜像反而能顺利使用,不明所以。

相关推荐
IvorySQL12 小时前
从双解析器到循环工程:IvorySQL 五年技术演进路线的深度观察
大数据·数据库·人工智能·postgresql·开源
donoot15 小时前
一次 Nginx 502 问题的深度排查:从 SELinux 到容器网络
nginx·docker·selinux·反向代理·502 bad gateway
Sagittarius_A*16 小时前
Docker:渗透前置容器化核心基础
运维·安全·docker·容器
名字还没想好☜19 小时前
Docker 多阶段构建:把镜像从 1.2GB 砍到 15MB
运维·docker·容器·多阶段构建·镜像优化
花和满楼20 小时前
K8s 1.36 ImageVolume GA:OCI 镜像不再只能跑容器
java·容器·kubernetes
生活爱好者!20 小时前
NAS还能玩游戏?部署一款 WebGL 3D 赛车小游戏
游戏·docker·容器·玩游戏
曦月合一21 小时前
本地电脑部署docker,及各种组件(nginx、mysql、redis、mongo、minio、java)
docker·windows10 专业版
hj2862511 天前
Docker 核心知识点整理(网络 + Dockerfile + 原理 + 命令)
网络·docker·容器
梦想的颜色1 天前
【Docker原理】Docker 容器一文打尽:生命周期、环境管控、迁移备份、日志进程排查、垃圾清理
运维·docker·容器·容器生命周期·容器日志排查·容器迁移备份·容器进程管理
万里侯1 天前
GitOps 漂移检测:集群里改了配置,Git 还以为一切正常
微服务·容器·k8s