当前位置:网站首页>在docker中快速使用各个版本的PostgreSQL数据库
在docker中快速使用各个版本的PostgreSQL数据库
2022-07-06 16:23:00 【华为云】

1、安装概述

PG安装方法很多,和MySQL类似,给用户提供很大的选择空间。如:RPM包安装(在线、离线)、源码编译安装、二进制等。
https://yum.postgresql.org/rpmchart.php
https://yum.postgresql.org/11/redhat/rhel-6-x86_64/repoview/postgresqldbserver11.group.html
https://www.postgresql.org/ftp/source/
打开 PostgreSQL 官网 https://www.postgresql.org/,点击菜单栏上的Download ,可以看到这里包含了很多平台的安装包,包括 Linux、Windows、Mac OS等 。
各个安装包:https://www.postgresql.org/ftp/source/
Linux 我们可以看到支持 Ubuntu 和 Red Hat 等各个平台,点击具体的平台链接,即可查看安装方法:

点击上图中的 file browser,我们还能下载 PostgreSQL 最新的源码。

2、Docker中下载创建
Docker Hub的官网地址:https://hub.docker.com/_/postgres
GitHub的地址:https://github.com/docker-library/postgres
-- 拉取所有镜像docker pull postgres:9.4.26 docker pull postgres:9.6.24docker pull postgres:10.20docker pull postgres:11.15docker pull postgres:12.10docker pull postgres:13.6docker pull postgres:14.2-- 创建各个版本的Docker容器docker rm -f lhrpg94 lhrpg96 lhrpg10 lhrpg11 lhrpg12 lhrpg13 lhrpg14docker run --name lhrpg94 -h lhrpg94 -d -p 54321:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:9.4.26docker run --name lhrpg96 -h lhrpg96 -d -p 54322:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:9.6.24docker run --name lhrpg10 -h lhrpg10 -d -p 54323:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:10.20docker run --name lhrpg11 -h lhrpg11 -d -p 54324:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:11.15docker run --name lhrpg12 -h lhrpg12 -d -p 54325:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:12.10docker run --name lhrpg13 -h lhrpg13 -d -p 54326:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:13.6docker run --name lhrpg14 -h lhrpg14 -d -p 54327:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:14.23、登陆测试
-- docker直接登陆docker exec -it lhrpg14 psql -U postgres -d postgres-- 本地登陆docker exec -it lhrpg14 bashsu - postgrespsql-- 远程登陆psql -U postgres -h 192.168.66.35 -d postgres -p54327-- 从Postgresql 9.2开始,还可以使用URI格式进行远程连接:psql postgresql://myuser:[email protected]:5432/mydbpsql postgresql://postgres:[email protected]:54327/postgres其中-h参数指定服务器地址,默认为127.0.0.1,默认不指定即可,-d指定连接之后选中的数据库,默认也是postgres,-U指定用户,默认是当前用户,-p 指定端口号,默认是"5432",其它更多的参数选项可以执行: ./bin/psql --help 查看。
C:\Users\lhrxxt>psql -U postgres -h 192.168.66.35 -d postgres -p54327Password for user postgres:psql (13.3)Type "help" for help.postgres=# select version(); version------------------------------------------------------------------------------------------------------------------ PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit(1 row)postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges-----------+----------+----------+-------------------+-------------------+----------------------- postgres | postgres | UTF8 | Chinese_China.936 | Chinese_China.936 | template0 | postgres | UTF8 | Chinese_China.936 | Chinese_China.936 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | Chinese_China.936 | Chinese_China.936 | =c/postgres + | | | | | postgres=CTc/postgres(3 rows)postgres=# CREATE DATABASE lhrdb WITH OWNER=postgres ENCODING='UTF-8';CREATE DATABASEpostgres=# \c lhrdbYou are now connected to database "lhrdb" as user "postgres".lhrdb=#lhrdb=# create table student (lhrdb(# id integer not null,lhrdb(# name character(32),lhrdb(# number char(5),lhrdb(# constraint student_pkey primary key (id)lhrdb(# );CREATE TABLElhrdb=#lhrdb=# \d student Table "public.student" Column | Type | Collation | Nullable | Default--------+---------------+-----------+----------+--------- id | integer | | not null | name | character(32) | | | number | character(5) | | |Indexes: "student_pkey" PRIMARY KEY, btree (id)lhrdb=#lhrdb=# INSERT INTO student (id, name, number) VALUES (1, '张三', '1023');INSERT 0 1lhrdb=# SELECT * FROM student WHERE id=1; id | name | number----+------------------------------------+-------- 1 | 张三 | 1023(1 row)是不是很方便呢。
安装配置完成,若有不懂,可以私聊麦老师。
边栏推荐
- The intranet penetrates the zerotier extranet (mobile phone, computer, etc.) to access intranet devices (raspberry pie, NAS, computer, etc.)
- leetcode:236. 二叉树的最近公共祖先
- [unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code
- Newsletter L Huobi ventures is in-depth contact with genesis public chain
- mysql-cdc 的jar包 ,在flink运行模式下,是不是要放在不同的地方呢?
- 问下各位,有没有flink sql生成作业的文档啊或是案列啊知道flink cli可以建表和指定目
- Eureka Client启动后就关闭 Unregistering application xxx with eureka with status DOWN
- Gpt-3 is a peer review online when it has been submitted for its own research
- Rider离线使用Nuget包的方法
- The important data in the computer was accidentally deleted by mistake, which can be quickly retrieved by this method
猜你喜欢

服务器SMP、NUMA、MPP体系学习笔记。

今日睡眠质量记录78分

After 3 years of testing bytecan software, I was ruthlessly dismissed in February, trying to wake up my brother who was paddling

Do you still have to rely on Simba to shout for a new business that is Kwai?

浅谈现在的弊端与未来的发展

达晨史上最大单笔投资,今天IPO了

快讯 l Huobi Ventures与Genesis公链深入接洽中

Daily question brushing record (XV)
![[unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code](/img/4c/5d867437aac5faa299817e187602e1.png)
[unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code

自动化测试工具Katalon(Web)测试操作说明
随机推荐
公链与私链在数据隐私和吞吐量上的竞争
短链的设计
Today's sleep quality record 78 points
Computer reinstallation system teaching, one click fool operation, 80% of people have learned
零代码高回报,如何用40套模板,能满足工作中95%的报表需求
The same job has two sources, and the same link has different database accounts. Why is the database list found in the second link the first account
Server SMP, NUMA, MPP system learning notes.
flinksql select id ,count(*) from a group by id .
The best sister won the big factory offer of 8 test posts at one go, which made me very proud
Every year, 200 billion yuan is invested in the chip field, and "China chip" venture capital is booming
Without CD, I'll teach you a trick to restore the factory settings of win10 system
MVC and MVVM
Résumé des connaissances de gradle
What should I do if the USB flash disk data is formatted and how can I recover the formatted USB flash disk data?
MATLIB reads data from excel table and draws function image
电脑重装系统u盘文件被隐藏要怎么找出来
(1) Chang'an chain learning notes - start Chang'an chain
Laravel8 uses passport authentication to log in and generate a token
JDBC programming of MySQL database
【212】php发送post请求有哪三种方法