当前位置:网站首页>在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.2
3、登陆测试
-- 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)
是不是很方便呢。
安装配置完成,若有不懂,可以私聊麦老师。
边栏推荐
- Why is bat still addicted to 996 when the four-day working system is being tried out in Britain?
- Can online reload system software be used safely? Test use experience to share with you
- 士大夫哈哈哈
- Daily question brushing record (XV)
- Master binary tree in one article
- app通用功能测试用例
- How can Oracle CDC deserialize with jsondebeziumdeserializationschema
- Zero code and high return. How to use 40 sets of templates to meet 95% of the reporting needs in the work
- MATLIB从excel表中读取数据并画出函数图像
- AI金榜题名时,MLPerf榜单的份量究竟有多重?
猜你喜欢
The problem of ASP reading Oracle Database
app通用功能測試用例
英国都在试行4天工作制了,为什么BAT还对996上瘾?
The method of reinstalling win10 system is as simple as that
Entropy information entropy cross entropy
Gradle知識概括
电脑重装系统u盘文件被隐藏要怎么找出来
求帮助xampp做sqlilab是一片黑
Detailed explanation of regular expression (regexp) in MySQL
Matplotlib draws a histogram and adds values to the graph
随机推荐
Please help xampp to do sqlilab is a black
[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code
Local deployment Zeppelin 0.10.1
js对JSON数组的增删改查
After 3 years of testing bytecan software, I was ruthlessly dismissed in February, trying to wake up my brother who was paddling
[system analyst's road] Chapter 7 double disk system design (service-oriented development method)
(1) Chang'an chain learning notes - start Chang'an chain
matplotlib画柱状图并添加数值到图中
Penetration test --- database security: detailed explanation of SQL injection into database principle
Oracle对表进行的常用修改命令
[unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code
The largest single investment in the history of Dachen was IPO today
js导入excel&导出excel
Do you still have to rely on Simba to shout for a new business that is Kwai?
Daily question brushing record (XV)
Talking about the current malpractice and future development
Up to 5million per person per year! Choose people instead of projects, focus on basic scientific research, and scientists dominate the "new cornerstone" funded by Tencent to start the application
Gradle知识概括
leetcode:236. 二叉树的最近公共祖先
Zero code and high return. How to use 40 sets of templates to meet 95% of the reporting needs in the work