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

相关推荐
梦想不只是梦与想3 小时前
docker-compose.yml
docker·docker-compose·docker run
更深兼春远12 小时前
第2篇:Dify 部署保姆级教程:用 Docker跑起来
docker·容器·dify
小白的码BUG之路16 小时前
Docker -- No space left on device
运维·docker·容器
wzq11_66617 小时前
Kubernetes集群——Service篇(详细讲解!!!)
云原生·容器·kubernetes
程序员老陆17 小时前
Docker 命令全景指南:从镜像构建到生产运维
运维·docker·容器
灯澜忆梦1 天前
【minio】#1 | 简介与安装
docker·对象存储·minio
IvorySQL1 天前
PostgreSQL 日报 |PostgreSQL 19 Beta 4 发布(9 月 25 日)
数据库·postgresql
IvorySQL1 天前
PostgreSQL 日报 | 可见性映射数据损坏修复(9 月 26 日)
数据库·postgresql
一直在努力学习的菜鸟1 天前
PostgreSQL PITR实现时间点误删除恢复
postgresql
IvorySQL1 天前
PostgreSQL 日报| relchecks 溢出导致表无法删除(9 月 28 日)
数据库·人工智能·ai·postgresql·区块链