CentOS 7 Source Code compilation installation PostgreSQL 9.5

Source: Internet
Author: User
Tags postgresql psql readline centos server



Download


The official PostgreSQL can find the source file directory, the address is as follows:https://www.postgresql.org/ftp/source/, in the download list according to the needs of the selected version, after entering the subdirectory, you can see the file list:


As you can see, there are two compression formats available, where we select postgresql-9.5.5.tar.gzand upload to the specified directory on the CentOS server after the download is complete.



Configuring the compilation Installation


First into the PG compression Package directory tar -zxvf ./postgresql-9.5.5.tar.gz by decompression, and then you can start to compile the installation, into the decompression ./configure --help directory, through the can see the compilation related help information, such as:



For example --prefix=dir , you can specify the installation directory, --with-python and you can use the Python syntax of the Pl/python process language custom function, according to requirements we do not use, so at compile time only specify an installation directory:

./configure--prefix=/usr/local/postgresql



Running compile-time discovery prompts you not to have a C compiler because of the new system, so installing a GCC compiler is possible:


Yum Install GCC


After the installation is complete, compile the postgres again and find that the ReadLine library is missing , such as:

For example, but through the rpm -qa | grep readlinecommand view you can find that the system is self-readline package By default, such as:


Then there must still be a lack of readline-related packages, through theyum search readlinesearch can find a readline-devel package, such as:

In fact, what we lack is this readline development package (Readline-devel), not the ReadLine package, so install Readline-devel next:


Yum Install Readline-devel


After installation is completed again PostgreSQL, or error, this time the hint is missing zlib library:

Similarly, the missing is still the zlib development package (Zlib-devel) instead of the zlib package, so continue with the installation Zlib-devel:


Yum Install Zlib-devel

After the installation is complete and the PostgreSQL is compiled again, and no more error is reported, you can see the prompt to create the Config.status configuration file :

The configuration is complete, and then it is ready to be compiled and installed, followed by:


Make
Make install


See the following tips to illustrate the success of the build installation:



User rights and environment variables


After the successful compilation and installation, the next thing to do is to create a normal user, because the default superuser (root) does not start PostgreSQL, so you need to create a normal user to start the database, execute the following command to create the user:


Useradd Postgres

Next, you need to set permissions to assign all Postgres data directories to the Postgres user (here I'll specify the Postgres data directory in the/usr/local/postgresql/data directory):


Chown-r postgres:postgres/usr/local/postgresql/


Finally, for the sake of convenience set up the related environment variables, here just set Postgres user's environment variables , so first by su - postgres switching to Postgres user , open. Bash _profile file and append the following:

After the modification is complete source ./.bash_profile , you can make it take effect immediately, then verify that the environment variable is set correctly which psql , psql -V switch Any directory input, and view the path of the Psql client separately. and The database version of PostgreSQL , such as:

Initializing the database


Because the environment variable is configured, we can do it directly hereinitdb, but before we do initdb --help that we could look at the initialization-related help information:


As you can see,initdbwe can specify parameters to do some initialization at the same time as the initialization is used,

For example

Specify Pgdata (PostgreSQL data Catalog),


Specify encoding (encoding),


Specify the user name and password for the database superuser, and so on ,


In the last part of the paragraph I marked out that if the data directory is not specified, the pgdata in the environment variable will be used by default, since we have just set up the PGDATA environment variable, so here we do not need to specify the additional, the final execution of the initialization command:


# INITDB



The following information indicates that the initialization was successful:



At the same time, in the PostgreSQL directory, you can see the data directory and the data and configuration files for that directory:


For example, thebase directory is a table space directory , and the globaldirectory is the directory of the related variables


Pg_hba.conf and Postgresql.conf also mentioned in their previous blogs,


One is the access control configuration (127.0.0.1 to the trusted client IP network segment so that it can be accessed remotely),


One is the PostgreSQL Master profile (Listen_address=localhost changed to an asterisk to listen to the entire network), for convenience I have changed the pg_hba.conf IP address here0.0.0.0/0, and the encryption method tomd5means that password access is required to provide the lowest level of security protection:


And postgresql.conf, like the above, modifies the listen_address so that it can listen to the entire network:

Finally, do not forget to open the PG 5432 Port , or even if the above two modifications the client still cannot connect PostgreSQL, so add 5432 port to zone , run the following command (note that this needs to be cut back to the root user, Otherwise, no permissions):


firewall-cmd Span class= "hljs-literal" >--zone=public --add -port=5432/tcp --permanent


Firewall-cmd --reload


< Span class= "hljs-literal" >< Span class= "hljs-comment" >< Span class= "hljs-literal" >< Span class= "hljs-comment" > Now that the configuration is complete, you can also check the list of open ports byfirewall-cmd--zone=public--list-ports:

Firewall-cmd--zone=public--list-ports


Start and connect

Since we have set the environment variable, we have specified the data directory Pgdata, which means that the-llog file directory is usually specified, so we/usr/local/ In the PostgreSQL root directory, create a log directory to hold the journal files (note that you don't forget to give writable permissions),


The last pg_ctl start -l /usr/local/postgresql/log/pg_server.log run can start the database, see the following prompt to indicate that the boot succeeded:


Or, ps -ef|grep postgres Check to see if there are processes related to Postgres, as well as the success of the startup:


After the successful launch, we can connect via PostgreSQL's client tool Psql , and the direct input topsqlsee the version information indicates the connection was successful:


The next thing to do is to set the Postgres user's password (default is empty), with the psql connection is successful , \password the direct input will prompt for two password, such as:



CentOS 7 Source Code compilation installation PostgreSQL 9.5

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.