利用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不能启动,这个镜像反而能顺利使用,不明所以。

相关推荐
冬奇Lab1 天前
一天一个开源项目(第41篇):Workout.cool - 现代化开源健身教练平台,训练计划与进度追踪
docker·开源·资讯
天朝八阿哥1 天前
使用Docker+vscode搭建离线的go开发调试环境
后端·docker·visual studio code
IvorySQL1 天前
PostgreSQL 技术日报 (3月4日)|硬核干货 + 内核暗流一网打尽
数据库·postgresql·开源
IvorySQL2 天前
双星闪耀温哥华:IvorySQL 社区两项议题入选 PGConf.dev 2026
数据库·postgresql·开源
阿虎儿2 天前
Docker安装(非sudo用户可用)
docker
赵渝强老师3 天前
【赵渝强老师】PostgreSQL中表的碎片
数据库·postgresql
fetasty3 天前
rustfs加picgo图床搭建
docker
蝎子莱莱爱打怪4 天前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
小p5 天前
docker学习7:docker 容器的通信方式
docker
小p5 天前
docker学习5:提升Dockerfile水平的5个技巧
docker