Linux CentOS 7 source code compilation and installation of PostgreSQL9.5, centos7 source code compilation rpm
The previous blog recorded the installation of PostgreSQL 9.3 in the form of an rpm package (PostgreSQL 9.3 is installed in Linux CentOS 7 (released). This blog will record the installation of PostgreSQL 9.5 in the form of source code compilation.
Download
You can find the source code file directory on the official postgresql website at https://www.postgresql.org/ftp/source/. you need to select a directory in the download folder, for example:
After entering the subdirectory, you can see the file list:
For example, we can see that two compression formats are provided. Here we choosePostgresql-9.5.5.tar.gzAfter the download is complete, upload it to the specified directory on the CentOS server.
Configure compilation and Installation
First, go to the pg compressed package directory through tar-zxvf. /postgresql-9.5.5.tar.gz to extract, and then you can start to compile and install, enter the extract directory, through. /configure -- help can view compilation-related help information, such:
For example, -- prefix = dir can be used to specify the installation directory. For example, -- with-python can use PL/python custom functions in the Python syntax. We cannot use them as needed, therefore, only one installation directory can be specified during compilation:
./Configure -- prefix =/usr/local/postgresql
After running the compilation, you will be prompted that the c compiler is not available because of the new system. Therefore, you can install a gcc compiler:
Yum install gcc
After the installation is complete, compile S again and find that the readline library is missing, for example:
For example, if you run the rpm-qa | grep readline command, you can find that the system has its own readline package by default, for example:
Therefore, there must be a lack of readline-related packages. You can use yum search readline to search forReadline-develPackages, such:
In fact, what we lack is this readline Development Kit (readline-devel), rather than the readline package. So next we will install it.Readline-devel:
Yum install readline-devel
After the installation is complete, compile postgresql again and report an error. This prompt indicates that the zlib library is missing:
Similarly, the missing zlib Development Kit (zlib-devel) is not the zlib package, so continue to install zlib-devel:
Yum install zlib-devel
After the installation is complete, compile postgresql again, and no error is reported. You can see that the config. status configuration file is created:
After the configuration is complete, you can compile and install it and execute the following commands in sequence:
Make
Make install
The following prompt indicates that the compilation and installation are successful:
User Permissions and Environment Variables
After compilation and installation are successful, the next step is to create a common user. Because the default Super User (root) cannot start postgresql, you need to create a common user to start the database, run the following command to create a user:
Useradd S
Next, you need to set permissions to assign all the data directories of postgres to the postgres user (here I specify the data directory of postgres under the/usr/local/postgresql/data Directory ):
Chown-R postgres: postgres/usr/local/postgresql/
Finally, for convenience, set the relevant environment variables. Here, only the postgres user's environment variables are set. Therefore, first switch to postgres user through su-postgres and open. Bash_profileFile and append the following content:
After modification, you can use source. /. make bash_profile take effect immediately. Next, check whether the environment variables are correctly set. Switch to any directory and enter which psql and psql-V to view the path of the psql client and the postgresql database version, for example:
After everything is ready, you can initialize the database.
Initialize Database
Because environment variables are configured, we can directly execute initdb to initialize the database. Before that, we can use initdb -- help to check the initialization help information:
For example, we can see that when initdb is used for initialization, we can specify parameters to perform initialization at the same time, such as specifying pgdata (postgresql data directory), specifying encoding (encoding) specify the username and password of the database superuser.If the data directory is not specified, the PGDATA in the environment variable is used by default.Because we have just set the PGDATA environment variable, we do not need to specify it here, and finally execute the initialization command:
Initdb
If the following information is displayed, the initialization is successful:
At the same time, you can view the generated data directory data and related data and configuration files in the postgresql directory:
For example, the base directory is the tablespace directory, the global directory is the directory of related global variables, pg_cmd.conf and postgresql. conf has been mentioned in earlier blogs. One is access control configuration (Change 127.0.0.1 to a trusted Client ip address segment for remote access ), one is the postgresql main configuration file (Change listen_address = localhost to an asterisk to enable it to listen to the entire network). For convenience, I will change the IP address of pg_assist.conf to 0.0.0.0/0, and change the encryption method to md5, password access is required, which provides a minimum level of security protection:
Postgresql. conf, as mentioned above, modifies listen_address to listen to the entire network:
Finally, do not forget to open port 5432 of pg. Otherwise, even if the above two clients are modified, they still cannot connect to postgresql. Therefore, add Port 5432 to the zone, run the following commands in sequence (note that you need to switch back to the root user, otherwise you do not have the permission ):
Firewall-cmd -- zone = public -- add-port = 5432/tcp -- permanent
Firewall-cmd -- reload
Now the configuration is complete. You can also use firewall-cmd -- zone = public -- list-ports to view the opened port list and confirm again, if the following prompt is displayed, the port is successfully enabled:
At this point, the configuration is complete, and the database is started and connected.
Start and connect
At the end of database initialization, we can see the startup command, for example:
Because we have set environment variables, we have already specified the data directory pgdata.-1 indicates the log file directory, which usually needs to be specified, therefore, we create another log directory under the/usr/local/postgresql root directory to store log files (note that you must not forget to grant writable permissions ),
Run pg_ctl start-l/usr/local/postgresql/log/pg_server.log to start the database. The following prompt indicates that the database is successfully started:
You can also use ps-ef | grep postgres to check whether there are any processes related to ipvs. If yes, the startup is successful:
After successful startup, we can use the client tool provided by postgresqlPsqlDirectly enter psql to view the version information, indicating that the connection is successful:
In the log file directory, you can see the database log file and the startup log:
The first thing to do next is to set the postgres User password (blank by default). After psql connection is successful, enter \ password directly, and you will be prompted to enter the password twice, for example:
Now, we can change the password to 111111 and run the \ l command to view the Database List. The use of psql is not described in detail here. The last and most important thing is to verify the connection of the non-local client tool. After all, we are going to be a database server. Here I chose Navicat Premium, on the host (Windows7) enable Navicat to test the connection with the postgresql server in the VM:
For example, you can find that the connection is successful. Similarly, you can use the command to stop the database.pg_ctl stop
To close the postgresql service, it is very simple, so far the compilation and installation of source code postgresql is all over.
Summary
Briefly record The entire process of compiling and installing postgreSQL9.5 in CentOS 7, and hope to help those who encounter The same problem, The End.