当前位置:网站首页>[cloud native] docker deployment database persistence
[cloud native] docker deployment database persistence
2022-07-22 17:48:00 【Gauss squirrel Club】
Catalog
In the last article, based on docker Installation of , We use enmotech The latest image of has been installed and started . Container deployment is very convenient , Uninstallation is easier . But this feature is like a double-edged sword , Bring convenience at the same time , There will be some shortcomings . Once the container is deleted , All data and configurations in the container will be lost . Even if you re run a new container , What we get is just a new initial state database .
therefore , For data that needs persistence, such as databases , We also need to see how to prevent the loss of data caused by the deletion or damage of containers . stay openGauss In the database , This function is achieved by specifying relevant parameters .
Database persistence starts
Our environment for this persistence test is based on the previous article stay docker Deploy openGauss. Let's delete the container instance we started last time .
[[email protected] docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
573ea1edffb8 enmotech/opengauss:3.0.0 "entrypoint.sh gauss…" 3 days ago Up 3 days 5432/tcp opengauss
[[email protected] docker]# docker stop 573ea1edffb8
573ea1edffb8
[[email protected] docker]# docker rm 573ea1edffb8
573ea1edffb8
The following command uses the original opengauss Mirror starts a container :
docker run --name opengauss --privileged=true -d -e [email protected] -v /enmotech/opengauss:/var/lib/opengauss -p 15432:5432 enmotech/opengauss:3.0.0
For the explanation of other parameters, please refer to the previous installation . Here we mainly focus on -p -v Two parameters .
- -p Parameters :openGauss The default listening of starts in the container 5432 On port , If you want to access the database from outside the container , You need to in docker run When it's time to specify -p Parameters . For example, the above command will allow you to use 15432 The port accesses the database outside the container . After the above command starts the container database normally , It can be done through external gsql Database access .
- -v Parameters : Appoint Docker in openGauss All data files for , It's in the container /var/lib/opengauss Catalog , The host is /enmotech/opengauss Catalog . If the host's /enmotech/opengauss If it doesn't exist ,docker Automatically created , But it must be an absolute path .Docker Have read and write permission to it .
View the database directory inside the container . Here's the picture , Already in the container /var/lib/opengauss Created data Catalog .
[[email protected] docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89747134cd4d enmotech/opengauss:3.0.0 "entrypoint.sh gauss…" About a minute ago Up About a minute 0.0.0.0:15432->5432/tcp, :::15432->5432/tcp opengauss
[[email protected] docker]# docker exec -it 89747134cd4d /bin/bash
[email protected]:/# cd /var/lib/opengauss/data/
[email protected]:/var/lib/opengauss/data# ls
asp_data gs_gazelle.conf pg_audit pg_errorinfo pg_location pg_notify pg_snapshots PG_VERSION postmaster.opts undo
base gs_profile pg_clog pg_hba.conf pg_log pg_perf pg_stat_tmp pg_xlog postmaster.pid
gaussdb.state gswlm_userinfo.cfg pg_csnlog pg_ident.conf pg_logical pg_replslot pg_tblspc postgresql.conf postmaster.pid.lock
global mot.conf pg_ctl.lock pg_llog pg_multixact pg_serial pg_twophase postgresql.conf.lock sql_monitor
Let's check the database directory on the host . Here's the picture , Already on the host /enmotech/opengauss Created data Catalog . You can see that the data in the container has been stored in the operating system .
Data persistence validation
Now let's build a table 、 Insert data to see whether the persistent storage of data can be completed .
1. Into the container , Log in to the database .
[[email protected] docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89747134cd4d enmotech/opengauss:3.0.0 "entrypoint.sh gauss…" About a minute ago Up About a minute 0.0.0.0:15432->5432/tcp, :::15432->5432/tcp opengauss
[[email protected] docker]# docker exec -it 89747134cd4d /bin/bash
[email protected]:/var/lib/opengauss/data# su - omm
[email protected]:~$ gsql
omm=#
Is a new database instance , Look at me During previous installation Test the user created wxx Are you there? . It is as expected , It just doesn't exist . Because there was no persistent startup during the previous operation .
2. Create table test1, And then insert the data .
create table test1(id int,name varchar(20));
INSERT INTO test1 VALUES (1, 'oligei');
3. Close the database .
[email protected]:~$ gs_ctl stop -D /var/lib/opengauss/data/
[2022-07-19 02:46:25.253][423][][gs_ctl]: gs_ctl stopped ,datadir is /var/lib/opengauss/data
waiting for server to shut down....[[email protected] docker]#
4. Start database
[[email protected] docker]# docker start 89747134cd4d
89747134cd4d
[[email protected] docker]# docker exec -it 89747134cd4d /bin/bash
[email protected]:/# su - omm
[email protected]:~$ gsql
5. Verify that after the container restarts , The original data is still .
6. Just restart , It's not surprising that the data was not lost . We pay more attention to container deletion .
[[email protected] docker]# docker stop 89747134cd4d
89747134cd4d
[[email protected] docker]# docker rm 89747134cd4d
89747134cd4d
[[email protected] docker]# docker exec -it 89747134cd4d /bin/bash
Error: No such container: 89747134cd4d
You can see that the original container has been deleted successfully .
7. Now restart , See if persistence is successful . You still need to use the previously specified storage path .
[[email protected] docker]# docker run --name opengauss --privileged=true -d -e [email protected] -v /enmotech/opengauss:/var/lib/opengauss -p 15432:5432 enmotech/opengauss:3.0.0
[[email protected] docker]# docker ps
[[email protected] docker]# docker exec -it 74b94a7bda80 /bin/bash
[email protected]:/# su - omm
[email protected]:~$ gsql
omm=# select * from test1;
Results previous figure .
It can also be seen from the above figure , The original table records still exist , Database persistence succeeded .
If you think the blogger's article is good or helpful , Please pay attention to the blogger , It would be better if the three collections support ! Thank you for your encouragement !
边栏推荐
- [HMS core] [push kit] set of message classification problems
- Android 面试题:你说一下 PendingIntent 和 Intent 的区别?
- [Digital IC] understand Axi protocol in simple terms
- What if the win11 display microphone is not plugged in? Solution of win11 display microphone not plugged in
- postgreSQL数据库部署在linux服务器上,本机查询ms级,用windows上安装的pgadmin查询超级慢20s左右,是网络的问题还是数据库配置问题?
- MySQL constraint_ Primary key constraint primary key
- 有人知道oracle cdc这个问题吗?source没有空值,但是查询定义的cdc表时说有空值,让修
- 深度学习实现交叉验证(图像、信号处理)
- Guys, when Flink SQL job submits a job to yarn, it reports an SQL error that cannot be executed. If it is executed locally, it does not report an error. The server
- Virtual machine performance test scheme
猜你喜欢
Unity postprocess screen post-processing
cpd配准存在的问题
Conference OA project introduction & Conference release
ACM warm-up exercise 3 in 2022 summer vacation (summary of some topics)
What is the difference between win11 beta 22621.436 and 22622.436?
Talking about DOM objects in depth, use four versions of demoplus to break the history.state header (more)
How to make an appointment while watching the panorama? Here comes the VR catering system tutorial
Instruction arrangement problem
Li Hongyi machine learning 2020--p20 & 21 RNN
PlayBook introduction
随机推荐
【HMS core】【FAQ】【Account Kit】典型问题合集1
会议OA项目之项目简介&会议发布
Win11怎么以管理员身份运行?Win11以管理员身份运行的设置方法
How is VR panorama displayed in all walks of life? How to implement the application?
关键路径问题
指令安排问题
How does win11 close the touch pad? Three solutions for closing the touch panel in win11
[HMS core] [FAQ] [account kit] typical problem set 2
【计网】(三)超网、路由、NAT协议
How can VR panoramic display attract users' attention in a new way of online promotion?
MySQL series 3: Function & Index & View & error code number meaning
【如何优化她】教你如何定位不合理的SQL?并优化她~~~
【FPGA教程案例35】通信案例5——基于FPGA的16QAM调制信号产生,通过matlab测试其星座图
DOM operation of JS - event chain (bubble target capture)
DOM operation of JS -- event proxy
MySQL join and index
Can the task of flinksql monitor whether it is interrupted?
Take CRM system as an example to explain data analysis (importance introduction and analysis method)
1312. Minimum number of inserts to make a string a palindrome string
STL map