In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to install the PostgreSQL database on the Linux system". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to install the PostgreSQL database on the Linux system.
I. preparatory work
The Linux operating system used here is Centos7. Choose to install the Centos7 system on the virtual machine, and then install PostgreSQL on the virtual machine.
Second, install PostgreSQL2.1 and select a version
Go to the download interface of the PostgreSQL official website and find the download information related to Centos. Download address on the official website: https://www.postgresql.org/download/linux/redhat/
2.2. install the yum source
Install according to the version of yum selected above:
Yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
As shown in the following figure:
2.3.Install PostgreSQL
Install PostgreSQL using the following command:
Yum install postgresql12-server
As shown in the following figure:
Enter "y" where you will be prompted during the installation process, and the installation interface is shown in the following figure:
3. Set PostgreSQL
In the above steps, we just installed PostgreSQL, and then we need to make some settings for PostgreSQL.
3.1. Initialize the database
Initialize the database using the following command:
/ usr/pgsql-12/bin/postgresql-12-setup initdb
As shown in the following figure:
After initializing the database, a folder named 12 is created under the / var/lib/pgsql directory, 12 is the database version, and if you are installing another version of PostgreSQL, it corresponds to its version number (11,9.5). If there is already a corresponding version of the folder here, an error will be reported in the initialization step. You need to delete the corresponding folder and initialize it.
3.2. Set the database to start automatically
Use the following command to set up the database self-startup
Systemctl enable postgresql-12systemctl start postgresql-12
As shown in the following figure:
3.3. Change the password
After installing the PostgreSQL database, a Linux login user name named postgres will be created by default. The password needs to be changed here.
Note: the password of the account logged in by the Linux system is changed here, not the password of the PostgreSQL database. The password of the PostgreSQL database will be changed later.
Use the following command to change the login password of the postgres user:
Passwd postgres
The postgres here indicates the user name of the password to be changed. As shown in the following figure:
3.4. Set to allow remote connections
The currently installed database can only be logged in locally. We need to set up some remote connection information to allow all computers to access the database.
Use the vim command to edit the file. If you do not have the vim command, you first need to install the vim command:
Yum install vim
As shown in the following figure:
The installation completion interface is shown in the figure:
First go to the data directory
Cd / var/lib/pgsql/12/data
As shown in the following figure:
Edit the postgresql.conf file:
Vim postgresql.conf
As shown in the following figure:
Find the listen_addresses node to modify, and modify the content before:
Remove the # in front of listen_addresses, and then change localhost to *. The modified content is as follows:
It's best to save the exit.
Also in the same directory, edit the pg_hba.conf file:
Vim pg_hba.conf
As shown in the following figure:
Here, modify the content of the IPv4, before modifying the contents of the file:
Modify to the contents of the file:
Finally, save and exit.
3.5. Restart the service
The above steps modify the file, and you need to restart the database service for the modified file to take effect:
Systemctl restart postgresql-12
As shown in the following figure:
3.6. Modify the database password
Log in to Centos with your postgres account and change the database user password (or switch directly to su postgres)
Ssh postgres@192.168.241.128-p 22
As shown in the following figure:
Then change the database user password
Psql-U postgres\ password
As shown in the following figure:
View PostgreSQL version information
3.7. Use the client to test login
After the above steps have been completed, we next use the client tool to test whether we can connect to the PostgreSQL database.
Note: PostgreSQL uses port 5432 by default. Before testing, add port 5432 to the firewall, or turn off the firewall, otherwise the client cannot connect. Here you choose to add port 5432 to the firewall.
Firewall-cmd-zone=public-add-port=5432/tcp-permanent
As shown in the following figure:
After modifying the configuration, you need to restart the firewall:
Firewall-cmd-reload
As shown in the following figure:
Then use Navicat as the client to test the connection PostgreSQL:
This means that the connection is successful.
Thank you for reading, the above is the content of "how to install PostgreSQL database on Linux system". After the study of this article, I believe you have a deeper understanding of how to install PostgreSQL database on Linux system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.