CN112732279A - PostgressSQL-based automatic database installation and deployment method - Google Patents

PostgressSQL-based automatic database installation and deployment method Download PDF

Info

Publication number
CN112732279A
CN112732279A CN202110028355.1A CN202110028355A CN112732279A CN 112732279 A CN112732279 A CN 112732279A CN 202110028355 A CN202110028355 A CN 202110028355A CN 112732279 A CN112732279 A CN 112732279A
Authority
CN
China
Prior art keywords
database
disk
postgresssql
directory
calling
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110028355.1A
Other languages
Chinese (zh)
Inventor
张敏
李永波
刘双妹
孙文本
乔岩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
707th Research Institute of CSIC
Original Assignee
707th Research Institute of CSIC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 707th Research Institute of CSIC filed Critical 707th Research Institute of CSIC
Priority to CN202110028355.1A priority Critical patent/CN112732279A/en
Publication of CN112732279A publication Critical patent/CN112732279A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/211Schema design and management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/4401Bootstrapping
    • G06F9/4411Configuring for operating with peripheral devices; Loading of device drivers

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Data Mining & Analysis (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to a database automatic installation and deployment method based on PostgressSQL, which is technically characterized by comprising the following steps: performing partition management on the disk through the Shell script, wherein the partition management comprises disk partitioning; formatting the disk; mounting a magnetic disk; managing a database directory based on PostgressSQL; initializing and starting a database; and a database is deployed, so that the automatic installation and deployment of the full life cycle of the disk are realized. The invention can meet the automation requirement of firmware database installation, simultaneously relieves the requirement pressure of software technicians because of not depending on software personnel to implement, saves labor cost, reduces the time for installing and deploying the conventional database, greatly improves the efficiency of installing and deploying the database, and has important significance for batch production work of equipment of the same type.

Description

PostgressSQL-based automatic database installation and deployment method
Technical Field
The invention belongs to the technical field of software foundation, and particularly relates to a postgressSQL-based database automatic installation and deployment method.
Background
The database technology is a core technology of an information system, and the basic theories and implementation methods of the structure, storage, design, management and application of the database are researched and utilized to process, analyze and understand the data in the database. The database technology is an important component of modern information science and technology, and is the core of a computer data processing and information management system. The database technology researches and solves the problem of effectively organizing and storing a large amount of data in the computer information processing process, reduces data storage redundancy in a database system, realizes data sharing, guarantees data safety, and efficiently retrieves and processes data. The fundamental goal of database technology is to solve the problem of sharing of data.
With the improvement of the importance of equipment data, the application of database technology in equipment software is more and more extensive. But is more complicated for software-equipped firmware database installation. The increase of the number of equipment also can greatly increase the workload of installing the firmware database, and the installation of the database needs software personnel familiar with the operation of the database to implement, thereby bringing pressure on the requirements of software technicians.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides a database automatic installation and deployment method based on PostgressSQL, which can realize the full-life-cycle automatic installation and deployment of a disk.
The technical problem to be solved by the invention is realized by adopting the following technical scheme:
a PostgressSQL-based database automatic installation and deployment method comprises the following steps:
step 1, disk partition management;
step 2, formatting a magnetic disk;
step 3, mounting a disk;
step 4, managing a database catalog;
step 5, initializing and starting a database;
and 6, deploying the database.
Moreover, the specific implementation method of the step 1 is as follows:
step 1.1, determining a preinstalled disk drive symbol according to user input;
and step 1.2, judging whether the preinstalled disk drive is in the system identification range, if so, executing the step 1.3, otherwise, returning the Shell script to 1, and indicating that the execution fails due to the input of illegal disk drives.
Step 1.3, judging whether a mounting condition exists in a pre-installed disk of a database, if so, unloading a mounting point, and performing step 1.4, otherwise, directly performing step 1.4;
step 1.3, judging whether the pre-installed disk of the database has a partition condition, if so, deleting the pre-installed disk, writing the pre-installed disk into a partition table, and performing step 1.5, otherwise, directly performing step 1.5;
and step 1.4, creating a unique database, installing and deploying the main partition, and synchronously writing in a partition table.
Moreover, the specific implementation method of the step 2 is as follows: ext4 command formats the disk into ext4 file system by calling mkfs, disk test setup is done by calling tune2fs command, which is set to power on without self test.
Moreover, the specific implementation method of step 3 is as follows: and (3) mounting the disk partition generated in the step (1) to a system fixed directory through a mount command.
Moreover, the specific implementation method of the step 4 is as follows: judging whether a data directory and a log pglog directory exist in the disk, if so, deleting the data directory and the log pglog directory, otherwise, not processing the data directory and the log pglog directory; and newly creating a data directory and a log pglog directory in the disk, and modifying the access rights of the data directory and the log pglog directory to be owned by postgres users.
Moreover, the specific implementation method of step 5 is as follows: switching to a postgres super user, adding a dependent library path of a postgresql database into a system environment, initializing a data directory by calling a command initdb of the postgresql database, starting the data directory database by calling a command pg _ ctl of the postgresql database, outputting a starting result to a log pglog directory at the same time, judging whether the postgresql database is started successfully, outputting ' the database is started successfully ' if the postgresql database is started successfully ', and executing step 6; otherwise, continuing to judge for 6 times, if the database is successfully started, outputting 'database starting success', and executing the step 6; if the data fails for 6 times, outputting 'the database cannot be started', unloading the mounting point of the disk partition, and returning the Shell script to 2, which indicates that the execution fails because the database cannot be started.
Moreover, the specific implementation method of step 6 is as follows:
6.1, executing a psql command of the PostgressSQL database, and logging in the database by a super user;
step 6.2, creating a database common user and a password by calling the create user name and password of PostgressSQL;
step 6.3, creating a database by calling the statement create database name owner of PostgressSQL;
step 6.4, quitting the super user login by calling '\ q' of PostgressSQL;
6.5, executing a psql command of the PostgressSQL database, logging in the database by a common user, and creating a script file by executing a database table structure by calling the psql-d database name-U user name-f script file name command of the PostgressSQL;
6.6, quitting the login of the common user by calling '\ q' of PostgressSQL;
6.7, stopping the data directory database by calling a command pg _ ctl of the PostgressSQL database, and outputting a stopping result to a log pglog directory;
and 6.8, finishing the installation of the output database, and returning the Shell script to 0 to show that the execution is successful.
The invention has the advantages and positive effects that:
the method comprises the steps of carrying out partition management on a disk through a Shell script, wherein the partition management comprises disk partitions; formatting the disk; mounting a magnetic disk; managing a database directory based on PostgressSQL; initializing and starting a database; and a database is deployed, so that the automatic installation and deployment of the full life cycle of the disk are realized. The invention can meet the automation requirement of firmware database installation, simultaneously relieves the requirement pressure of software technicians because of not depending on software personnel to implement, saves labor cost, reduces the time for installing and deploying the conventional database, greatly improves the efficiency of installing and deploying the database, and has important significance for batch production work of equipment of the same type.
Drawings
FIG. 1 is a flow diagram of a disk partition management design of the present invention;
FIG. 2 is a database catalog management design flow diagram of the present invention;
FIG. 3 is a database initialization and start-up design flow diagram of the present invention;
FIG. 4 is a database deployment flow diagram of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings.
A PostgressSQL-based database automatic installation and deployment method comprises the following steps:
step 1, disk partition management. And the disk partition management is used for detecting the mounting and partition conditions of the disk identifier of the preinstalled disk of the database. Firstly, determining a preinstalled disk drive symbol according to user input, judging whether the preinstalled disk drive symbol is in a system identification range, if so, checking the mounting condition, otherwise, returning a Shell script to 1, indicating that the execution fails due to the input of an illegal disk drive symbol, checking the mounting condition in a preinstalled disk of a database, and if a mounting point exists, unloading the preinstalled disk drive symbol; then checking the partition condition of a pre-installed disk of the database, if the partition exists, deleting the partition, and writing the partition into a partition table; and finally, creating a unique database, installing and deploying the main partition, and synchronously writing the main partition into the partition table.
As shown in fig. 1, the specific implementation method of this step is:
step 1.1, prompting to input a preinstalled disk drive symbol through an interface;
step 1.2, judging whether user input is received, if so, performing step 1.3, otherwise, re-reading step 1.1;
step 1.3, judging whether the disk drive symbol is in the system identification range, if so, performing step 1.4, otherwise, returning to step 1;
step 1.4, acquiring all mounting names under the disk drive symbol;
step 1.5, acquiring all mount quantities under the disk drive symbol;
step 1.6, judging whether the mounting quantity of the disk drive symbols is larger than 0, if so, performing step 1.7, otherwise, performing step 1.15;
step 1.7, storing all mounting names into an array;
step 1.8, initializing an array index to be 0;
step 1.9, taking out the mounting points from the array according to the indexes;
step 1.10, unloading the mounting points;
step 1.11, array index + 1;
step 1.12, judging whether the array traversal is completed, if the array traversal is completed, performing step 1.13, otherwise, repeating the step 1.9 to the step 1.12;
step 1.13, acquiring all mounting names under the disk drive symbol;
step 1.14, acquiring all mount quantities under the disk drive symbol, and performing step 1.6;
step 1.15, acquiring the number of partitions under the disk drive symbol;
step 1.16, judging whether the number of the sub-areas under the disk drive letter is larger than 0, if so, performing step 1.17, otherwise, performing step 1.22;
step 1.17, initializing a partition number to be 0;
step 1.18, deleting the partition where the partition number is located;
step 1.19, writing into a partition table;
step 1.20, partition number + 1;
step 1.21, judging whether the partition is traversed or not, if so, performing step 1.22, otherwise, repeating the steps 1.18 to 1.21;
step 1.22, creating a unique main partition;
and step 1.23, writing the partition table and finishing.
Returning to 1 in step 1.3 is that when the disk identifier input by the user is checked not to be in the system identification range, the Shell script of the design returns to 1, which indicates that the disk partition management fails, the subsequent steps are not executed, otherwise, the subsequent steps are continuously executed.
And 2, formatting the magnetic disk. The disk formatting comprises two steps of formatting and disk detection setting. The disk format is an ext4 file system and is realized by calling an mkfs. The disk test is set by calling tune2fs command, and to ensure the disk loading speed, it is set to boot-up non-self test.
And step 3, mounting the disk. And (3) mounting the disk partition generated in the step (1) to a fixed directory of the system, and realizing through mount command.
And 4, managing the database catalog. Firstly, judging whether a data directory and a log pglog directory exist or not, if so, recursively deleting the directory, otherwise, not processing; then, the access rights of the data directory and the log pglog directory are created again, and the access rights of the modified data directory and the log pglog directory are owned by postgres users.
As shown in fig. 2, the specific implementation method of this step is:
step 2.1, judging whether a data directory exists in the disk, if so, recursively deleting the data directory, and performing step 2.2, otherwise, directly performing step 2.2;
step 2.2, judging whether a log pglog directory exists in the disk, if so, recursively deleting the pglog directory, and performing step 2.3, otherwise, directly performing step 2.3;
step 2.3, creating a data directory and a log pglog directory;
and 2.4, the access rights of the modified data directory and the log pglog directory are owned by postgres users.
And 5, initializing and starting the database. Firstly, switching to a postgres super user, and adding a dependent library path of a postgressSQL database into a system environment; then, initializing the data directory by calling a command initdb of the PostgressSQL database; starting a data directory database by calling a command pg _ ctl of the PostgressSQL database, and outputting a starting result to a log pglog directory; finally, judging whether the PostgressSQL database is successfully started or not, if so, outputting 'the database is successfully started', and continuing to execute the subsequent steps; otherwise, continuing to judge for 6 times, if the database is successfully started, outputting 'database starting success', and executing the subsequent steps; if the data fails for 6 times, outputting ' the database cannot be started ', unloading the mounting point of the disk partition, and returning the Shell script to 2, which indicates that the execution fails because the database cannot be started '.
As shown in fig. 3, the specific implementation method of this step is:
step 3.1, switching to postgres super users;
step 3.2, adding a dependent library path of the PostgressSQL database into the system environment;
step 3.3, executing the initdb command of the PostgressSQL database, and initializing a data directory;
step 3.4, executing a pg _ ctl command of the PostgressSQL database, starting a data directory, and writing a starting result into a log pglog directory;
step 3.5, initializing waiting time wait _ time of starting database to 0
Step 3.6, initializing a process id identifier pid of the PostgressSQL database to be 0;
step 3.7, judging whether the waiting time for starting the database is less than 6, if so, performing step 3.8, otherwise, performing step 3.13;
step 3.8, acquiring a process id with the name of postgres, and assigning the process id to pid;
step 3.9, judging whether pid is 0, if pid is 0, performing step 3.10, otherwise, performing step 1.12;
step 3.10, waiting time wait _ time + 1;
step 3.11, waiting for 1 second and performing step 3.7;
step 3.12, outputting 'database starting success' and ending;
step 3.13, outputting 'the database cannot be started';
and 3.14, unloading the mounting point of the disk partition and setting the Shell script 2.
In step 3.14 return 2 to the database not bootable.
And 6, deploying the database. As shown in fig. 4, the specific implementation method of this step is:
6.1, executing a psql command of the PostgressSQL database, and logging in the database by a super user;
step 6.2, creating a database common user and a password, and calling a create user XXX (user name) password 'XXX' (password) statement of PostgressSQL;
step 6.3, creating a database, wherein the creation is realized by calling the create database XXX (database name) owner XXX (common user name) of PostgressSQL, and the database belongs to a common user;
step 6.4, quitting the login of the common user, and realizing the login by calling 'q' of PostgressSQL;
step 6.5, executing a psql command of the PostgressSQL database, logging in the database by a common user, simultaneously executing a database table structure to create a script file, and realizing by calling the psql-d XXX (database name) -U XXX (user name) -f XXX (script file name) command of the PostgressSQL;
step 6.6, quitting the login of the common user, and realizing the login by calling 'q' of PostgressSQL;
6.7, stopping the data directory database by calling a command pg _ ctl of the PostgressSQL database, and outputting a stopping result to a log pglog directory;
and 6.8, outputting 'database installation is completed' and returning to 0 after the steps are successfully executed.
In this step 6.8, return 0 is the completion of the database installation.
According to the PostgressSQL-based automatic database installation and deployment method, in a certain equipment system provided with CentOS, the Shell script is executed and the installed hard disk drive is designated, so that the PostgressSQL-based automatic database installation and deployment method is successfully realized.
It should be emphasized that the embodiments described herein are illustrative rather than restrictive, and thus the present invention is not limited to the embodiments described in the detailed description, but also includes other embodiments that can be derived from the technical solutions of the present invention by those skilled in the art.

Claims (7)

1. A PostgressSQL-based database automatic installation and deployment method is characterized by comprising the following steps: the method comprises the following steps:
step 1, disk partition management;
step 2, formatting a magnetic disk;
step 3, mounting a disk;
step 4, managing a database catalog;
step 5, initializing and starting a database;
and 6, deploying the database.
2. The automated postgresql-based database installation and deployment method according to claim 1, characterized in that: the specific implementation method of the step 1 comprises the following steps:
step 1.1, determining a preinstalled disk drive symbol according to user input;
and step 1.2, judging whether the preinstalled disk drive is in the system identification range, if so, executing the step 1.3, otherwise, returning the Shell script to 1, and indicating that the execution fails due to the input of illegal disk drives.
Step 1.3, judging whether a mounting condition exists in a pre-installed disk of a database, if so, unloading a mounting point, and performing step 1.4, otherwise, directly performing step 1.4;
step 1.3, judging whether the pre-installed disk of the database has a partition condition, if so, deleting the pre-installed disk, writing the pre-installed disk into a partition table, and performing step 1.5, otherwise, directly performing step 1.5;
and step 1.4, creating a unique database, installing and deploying the main partition, and synchronously writing in a partition table.
3. The automated postgresql-based database installation and deployment method according to claim 1, characterized in that: the specific implementation method of the step 2 comprises the following steps: ext4 command formats the disk into ext4 file system by calling mkfs, disk test setup is done by calling tune2fs command, which is set to power on without self test.
4. The automated postgresql-based database installation and deployment method according to claim 1, characterized in that: the specific implementation method of the step 3 is as follows: and (3) mounting the disk partition generated in the step (1) to a system fixed directory through a mount command.
5. The automated postgresql-based database installation and deployment method according to claim 1, characterized in that: the specific implementation method of the step 4 comprises the following steps: judging whether a data directory and a log pglog directory exist in the disk, if so, deleting the data directory and the log pglog directory, otherwise, not processing the data directory and the log pglog directory; and newly creating a data directory and a log pglog directory in the disk, and modifying the access rights of the data directory and the log pglog directory to be owned by postgres users.
6. The automated postgresql-based database installation and deployment method according to claim 1, characterized in that: the specific implementation method of the step 5 is as follows: switching to a postgres super user, adding a dependent library path of a postgresql database into a system environment, initializing a data directory by calling a command initdb of the postgresql database, starting the data directory database by calling a command pg _ ctl of the postgresql database, outputting a starting result to a log pglog directory at the same time, judging whether the postgresql database is started successfully, outputting ' the database is started successfully ' if the postgresql database is started successfully ', and executing step 6; otherwise, continuing to judge for 6 times, if the database is successfully started, outputting 'database starting success', and executing the step 6; if the data fails for 6 times, outputting 'the database cannot be started', unloading the mounting point of the disk partition, and returning the Shell script to 2, which indicates that the execution fails because the database cannot be started.
7. The automated postgresql-based database installation and deployment method according to claim 1, characterized in that: the specific implementation method of the step 6 comprises the following steps:
6.1, executing a psql command of the PostgressSQL database, and logging in the database by a super user;
step 6.2, creating a database common user and a password by calling the create user name and password of PostgressSQL;
step 6.3, creating a database by calling the statement create database name owner of PostgressSQL;
step 6.4, quitting the super user login by calling '\ q' of PostgressSQL;
6.5, executing a psql command of the PostgressSQL database, logging in the database by a common user, and creating a script file by executing a database table structure by calling the psql-d database name-U user name-f script file name command of the PostgressSQL;
6.6, quitting the login of the common user by calling '\ q' of PostgressSQL;
6.7, stopping the data directory database by calling a command pg _ ctl of the PostgressSQL database, and outputting a stopping result to a log pglog directory;
and 6.8, finishing the installation of the output database, and returning the Shell script to 0 to show that the execution is successful.
CN202110028355.1A 2021-01-11 2021-01-11 PostgressSQL-based automatic database installation and deployment method Pending CN112732279A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110028355.1A CN112732279A (en) 2021-01-11 2021-01-11 PostgressSQL-based automatic database installation and deployment method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110028355.1A CN112732279A (en) 2021-01-11 2021-01-11 PostgressSQL-based automatic database installation and deployment method

Publications (1)

Publication Number Publication Date
CN112732279A true CN112732279A (en) 2021-04-30

Family

ID=75591439

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110028355.1A Pending CN112732279A (en) 2021-01-11 2021-01-11 PostgressSQL-based automatic database installation and deployment method

Country Status (1)

Country Link
CN (1) CN112732279A (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109101242A (en) * 2018-07-19 2018-12-28 汉能移动能源控股集团有限公司 Automatic database deployment method and device
CN109241035A (en) * 2018-08-28 2019-01-18 福建南威软件有限公司 A kind of custom script realizes the automatic deployment method of database
CN111857752A (en) * 2020-07-22 2020-10-30 浪潮商用机器有限公司 PostgreSQL database installation method, device and equipment

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109101242A (en) * 2018-07-19 2018-12-28 汉能移动能源控股集团有限公司 Automatic database deployment method and device
CN109241035A (en) * 2018-08-28 2019-01-18 福建南威软件有限公司 A kind of custom script realizes the automatic deployment method of database
CN111857752A (en) * 2020-07-22 2020-10-30 浪潮商用机器有限公司 PostgreSQL database installation method, device and equipment

Similar Documents

Publication Publication Date Title
CN110096424B (en) Test processing method and device, electronic equipment and storage medium
CN106325970A (en) Compiling method and compiling system
US7827548B1 (en) Environment-neutral application build
CN106681775A (en) Method for achieving online batch upgrading of hard disk firmware through RAID card under Linux system
CN112068852B (en) Method, system, equipment and medium for installing open-source software based on domestic server
CN113760306B (en) Method and device for installing software, electronic equipment and storage medium
CN103677887A (en) Information processing method and electronic device
CN112416803A (en) Automatic testing method and device
EP4293498A1 (en) Application modification method, and system, cluster, medium and program product
CN113961570A (en) Real-time acquisition method applied to MYSQL BINLog change data
WO2017020460A1 (en) Method and apparatus for integrating plugin
CN112732279A (en) PostgressSQL-based automatic database installation and deployment method
CN112216340A (en) Hard disk test method and device, storage medium and electronic equipment
CN110795304A (en) Method and device for testing performance of distributed storage system
CN111459507B (en) Linux OS filling method and device based on hard disk drive name
CN114281367A (en) Big data platform deployment method and system for trust and creation environment
CN110096292B (en) Method and system for refreshing BIOS firmware of server in self-adaptive manner
CN110716798B (en) PHP (hypertext preprocessor) timing task management method and system
CN113761402A (en) Link debugging method, device, equipment and storage medium
CN113010189A (en) Database installation method, device, equipment and storage medium
CN112069062A (en) Method and device for editing and generating software test bug module
CN114443582B (en) File system mounting method, device, equipment and medium on operating system
RU2820753C1 (en) Method and system for controlling objects and processes in computing environment
CN113590225B (en) Mapping detection method and device, electronic equipment and storage medium
CN112181809B (en) Graphic user interface automatic test method based on multiple positioning methods

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination