Docker安装Postgresql
手动下载镜像(自己服务器无法拉取镜像的情况下)
- # 在一台可以拉取镜像的服务器拉取,然后打包到要加载的服务器
- docker pull postgers:latest
- docker save -o /data/docker/images/postgres.tar postgres:latest
- # 将生成的postgres.tar文件传输到目标服务器(如通过SCP)
- # 在目标服务器上加载镜像:
- sudo docker load -i /data/tools/images/postgres.tar
复制代码 安装pgsql_18.1
- # 查看
- docker search postgres
- # 拉取
- docker pull postgres:18.1
- docker pull postgres:latest
- # 停止并删除临时容器
- docker stop my-postgres && docker rm my-postgres
复制代码
- 启动容器,设置数据日志(CDC准备工作)
- PostgreSQL 18+ 版本的 Docker 镜像期望你将一个单独的卷挂载到容器的 /var/lib/postgresql 目录,而不是像之前那样挂载到其内部的子目录 /var/lib/postgresql/data。这样做是为了兼容pg_ctlcluster和方便未来升级。
- docker run --name my-postgres \
- --restart unless-stopped \
- -e POSTGRES_PASSWORD=123456 \
- -e POSTGRES_DB=source_db \
- -v /data/postgresql:/var/lib/postgresql \
- -p 5432:5432 \
- -d \
- postgres:latest \
- -c wal_level=logical \
- -c max_wal_senders=10 \
- -c max_replication_slots=10
复制代码- # 上面创建容器的时候,可以指定用户(别指定:postgres,这是默认超级用户)
- -e POSTGRES_USER=postgresql \
- # 启动参数中启用逻辑复制 (CDC必需)
- -c wal_level=logical \
- -c max_wal_senders=10 \
- -c max_replication_slots=10
复制代码- docker logs my-postgres --tail 10
- # 验证是否安装好,查询数据库版本
- docker exec my-postgres psql -U postgres -d source_db -c "SELECT version();"
- docker exec my-postgres psql -U postgres -d source_db -c "SHOW wal_level;"
- 账号:postgres
- 密码:123456
- 端口:5432
- 数据库:source_db
复制代码- SELECT version();
- SHOW wal_level;
- SHOW max_wal_senders;
- SHOW max_replication_slots;
复制代码 来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |
|
|
|
|
|
相关推荐
|
|
|