Installing PostgreSQL using RPM packages in Linux
Postgresql and MySQL are currently popular and active open source relational database systems. Compared with high-end Oracle commercial products, Postgresql and MyQL have much room for improvement in software maturity and development features. However, in the system selection process, the basic software level is determined by the overall load, O & M requirements, and important budget of the system in the future. A good thing is good, but it also depends on whether we need him or whether we can use him.
Compared with the extensive development of MySQL, Postgresql was first researched by Berkley and used as a scientific research institution for teaching and application, no matter in compliance with relational database standards or kernel development, all adopt rigorous attitudes and methods. Therefore, Postgresql is a good relational database product solution when MySQL does not support transactions.
Currently, Postgresql supports mainstream operating systems such as Windows, Linux, and Unix. On Linux, we can use three common installation methods:
- RPM package: directly download the Linux installation package from the official Postgresql website and install it through yum or rpm;
- Yum installation: connect to the Postgresql Yum library and download all the installation files and dependency packages from the website;
- Source code installation: This method is the most flexible and can be displayed to determine the installation directory and data file location;
This article describes how to install the RPM installation package and how to configure the connection later.
For more MongoDB tutorials, see the following:
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
1. Installation File preparation
I use RedHat Linux 6.4 for testing.
[Root @ TEST-DB uploads] # cat/etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
Download the RPM installation package from the official website of PG at http://www.postgresql.org/download /. Select the latest version 9.5 for the experiment.
[Root @ TEST-DB uploads] # ls-l
Total 6580
-Rw-r -- 1 root 1373788 Jan 21 postgresql95-9.5.0-2PGDG.rhel6.x86_64.rpm
-Rw-r -- 1 root 465492 Jan 21 postgresql95-contrib-9.5.0-2PGDG.rhel6.x86_64.rpm
-Rw-r -- 1 root 204948 Jan 21 postgresql95-libs-9.5.0-2PGDG.rhel6.x86_64.rpm
-Rw-r -- 1 root 4682132 Jan 21 postgresql95-server-9.5.0-2PGDG.rhel6.x86_64.rpm
2. Install the package
Pay attention to the installation sequence. In principle, the installation process can be completed in the basic Linux version. However, some packages may need to be supported by the yum program.
[Root @ TEST-DB uploads] # yum install postgresql95-libs-9.5.0-2PGDG.rhel6.x86_64.rpm
Loaded plugins: product-id, refresh-packagekit, security, subrole-manager
This system is not registered to Red Hat sub‑management. You can use sub‑manager to register.
Localyum
Dependencies Resolved
========================================================== ========================================================== ========================
Package Arch Version Repository Size
========================================================== ========================================================== ========================
Installing:
Postgresql95-libs x86_64 9.5.0-2PGDG. rhel6/postgresql95-libs-9.5.0-2PGDG.rhel6.x86_64 639 k
Updating for dependencies:
Openssl x86_64 1.0.1e-15. el6 localyum 1.5 M
Transaction Summary
========================================================== ========================================================== ========================
Install 1 Package (s)
Upgrade 1 Package (s)
Total size: 2.1 M
(Space reasons, omitted ......)
Complete!
[Root @ TEST-DB uploads] # yum install postgresql95-9.5.0-2PGDG.rhel6.x86_64.rpm
Loaded plugins: product-id, refresh-packagekit, security, subrole-manager
This system is not registered to Red Hat submodules Management. You can use
(Space reasons, omitted ......)
Installed:
Postgresql95.x86 _ 64. 5.0-2PGDG. rhel6
Complete!
[Root @ TEST-DB uploads] # rpm-ivh postgresql95-server-9.5.0-2PGDG.rhel6.x86_64.rpm
Warning: postgresql95-server-9.5.0-2PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ######################################## ### [100%]
1: postgresql95-server ####################################### #### [100%]
[Root @ TEST-DB uploads] # rpm-ivh postgresql95-contrib-9.5.0-2PGDG.rhel6.x86_64.rpm
Warning: postgresql95-contrib-9.5.0-2PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ######################################## ### [100%]
1: postgresql95-contrib ####################################### #### [100%]
Note: After you select to use the rpm package for installation, the OS user ipvs will be automatically created. You can use the passwd command to set the password.
[Root @ TEST-DB uploads] # id postgres
Uid = 26 (postgres) gid = 26 (postgres) groups = 26 (postgres)
[Root @ TEST-DB uploads] # passwd ipvs
Changing password for user login S.
New password:
Bad password: it is based on a dictionary word
Retype new password:
Passwd: all authentication tokens updated successfully.
3. Local service configuration and local connection test
After the RPM package is installed, a postgresql-<vxxx> service is automatically added to the system. We can start the database through this service.
-- Disabled by default
[Root @ TEST-DB uploads] # service -- status-all | grep postgres
Postgresql-9.5 is stopped
-- Force Start Failure
[Root @ TEST-DB uploads] # service postgresql-9.5 start
/Var/lib/pgsql/9.5/data is missing. Use "service postgresql-9.5 initdb" to initialize the cluster first.
[FAILED]
The first startup failed, mainly because no master database exists in the initial database. You can use initdb for initialization.
[Root @ TEST-DB uploads] # service postgresql-9.5 initdb
Initializing database: [OK]
[Root @ TEST-DB uploads] # service -- status-all | grep postgres
Postgresql-9.5 is stopped
[Root @ TEST-DB uploads] # service postgresql-9.5 start
Starting postgresql-9.5 service: [OK]
View the running status of the background ipvs process.
[Root @ TEST-DB uploads] # ps-ef | grep postgres
Postgres 28417 1 0? 00:00:00/usr/pgsql-9.5/bin/postmaster-D/var/lib/pgsql/9.5/data
Postgres 28419 28417 0? 00:00:00 ipvs: logger process
Postgres 28421 28417 0? 00:00:00 ipvs: checkpointer process
Postgres 28422 28417 0? 00:00:00 ipvs: writer process
Postgres 28423 28417 0? 00:00:00 ipvs: wal writer process
Postgres 28424 28417 0? 00:00:00 postgres: autovacuum launcher process
Postgres 28425 28417 0? 00:00:00 postgres: stats collector process
Root 28431 27089 0 00:00:00 pts/0 grep postgres
Two details, marked in red, are the master working process of the database, which clearly indicates the executable program and data file location. In addition, most process execution users are running ipvs, which means that although the program is started through root, root also uses the ipvs user process to start the program.
Local connection. You can use psql as the client to connect to the local database.
[Root @ TEST-DB ~] # Su-postgres
-Bash-4.1 $ psql
Psql (9.5.0)
Type "help" for help.
Postgres = # help
You are using psql, the command-line interface to PostgreSQL.
Type: \ copyright for distribution terms
\ H for help with SQL commands
\? For help with psql commands
\ G or terminate with semicolon to execute query
\ Q to quit
Postgres = #
S = # alter user Login s with password 'login s ';
ALTER ROLE
Postgres = # select * from pg_shadow;
Usename | usesysid | usecreatedb | usesuper | userepl | usebypassrls | passwd
| Valuntil | useconfig
---------- + ------------- + ---------- + --------- + -------------- + -------------------------
------------ + ---------- + -----------
Postgres | 10 | t | md53175bce1d3201d16594ce
Bf9d7eb3f9d |
(1 row)
Postgres-# \ q
-Bash-4.1 $ exit
Logout
According to the standard psql command, the name of the connected database should be written later. If no data is written, the database named postgres is connected by default. This database is created during initdb execution.
4. remote connection Configuration
Note: All operations are performed on the database server. By default, Postgresql rejects remote access. We need to configure additional items.
Similar to MySQL, many configuration parameters of postgresql are distributed in text format files. In configuring the network connection, we need to modify two files.
The first is pg_mirror.conf under the PG data file.
[Root @ TEST-DB ~] # Su-postgres
-Bash-4.1 $ cd/var/lib/pgsql/9.5/data/
-Bash-4.1 $ ls-l | grep conf
-Rw ------- 1 postgres 4224 Jan 21 pg_hba.conf
-Rw ------- 1 postgres 1636 Jan 21 09:53 pg_ident.conf
-Rw ------- 1 postgres 88 Jan 21 postgresql. auto. conf
-Rw ------- 1 postgres 21738 Jan 21 postgresql. conf
There are a lot of content in pg_hba.conf. We need to modify the settings about the site to be connected.
# "Local" is for Unix domain socket connections only
Local all peer
# IPv4 local connections:
Host all 127.0.0.1/32 ident
# IPv6 local connections:
Host all: 1/128 ident
# Allow replication connections from localhost, by a user with
# Replication privilege.
# Local replication ipvs peer
# Host replication ipvs 127.0.0.1/32 ident
# Host replication slave S: 1/128 ident
Configure IPv4 Local connection.
# IPv4 local connections:
Host all 127.0.0.1/32 ident
Host all 172.17.107.0/24 password
Host all 172.17.197.0/24 password
The/24 after the IP Address indicates that all IP addresses in the CIDR block can be accessed. Password indicates the connection through user name and Password authentication.
Another configuration file is postgresql. conf, which defines the listening range of the listener. The default value is as follows:
#-Connection Settings-
# Listen_addresses = 'localhost' # what IP address (es) to listen on;
# Comma-separated list of addresses;
# Defaults to 'localhost'; use '*' for all
# (Change requires restart)
# Port = 5432 # (change requires restart)
Max_connections = 100 # (change requires restart)
Modify the listen_addresses project, remove the annotation information, and change localhost *. In this way, the listener monitors connection requests from all IP addresses.
#-Connection Settings-
Listen_addresses = '*' # what IP address (es) to listen on;
# Comma-separated list of addresses;
# Defaults to 'localhost'; use '*' for all
# (Change requires restart)
# Port = 5432 # (change requires restart)
Max_connections = 100 # (change requires restart)
Restart the PG program.
[Root @ TEST-DB ~] # Service postgresql-9.5 (restart)
Stop Ping postgresql-9.5 service: [OK]
Starting postgresql-9.5 service: [OK]
On a remote Windows server, we have configured the connection interface through the pgAdmin client.
Click Connect to confirm the success.
5. Conclusion
PG is a popular open-source relational database product. For most industries and enterprises, relational databases still occupy the mainstream demand.
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: