Install postgresql 9.4 In CentOS
I. Preface
PostgreSQL, also known as Postgres, is a relational database management system applicable to various Linux operating systems, Windows, Solaris, BSD, and Mac OS X. PostgreSQL follows the PostgreSQL license and is an open source software. PostgreSQL is developed by the PostgreSQL Global Development Group and consists of a small number of companies that volunteer to supervise and manage these companies, including RedHat and EnterpriseDB.
PostgreSQL is becoming more and more popular, so it is taken for granted that it is so reliable and efficient. Compared with traditional enterprise-level relational databases, PostgreSQL is fully community-driven and has rich tools and documents to form a complete ecosystem.
Currently, the installation of most of the searched CentOS commands for Centos 6.x has changed a lot. This article mainly records the process of installing PostgreSQL in CentOS 7.1.
Ii. Install the PostgreSQL Source
CentOS 6.x 32bit
sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-i386/pgdg-centos94-9.4-1.noarch.rpm
CentOS 6.x 64bit
sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm
CentOS 7 64bit
sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm
There are not many differences in the process of adding a source, mainly because the source address has some changes.
3. Execute the installation command
sudo yum update
sudo yum install postgresql94-server postgresql94-contrib
4. verify whether the installation is successful
sudo rpm -aq| grep postgres
The execution result is as follows:
postgresql94-libs-9.4.1-1PGDG.rhel7.x86_64postgresql94-server-9.4.1-1PGDG.rhel7.x86_64postgresql94-9.4.1-1PGDG.rhel7.x86_64postgresql94-contrib-9.4.1-1PGDG.rhel7.x86_64
V. initialize the database
CentOS 6.x System
sudo service postgresql-9.4 initdb
CentOS 7 System
sudo /usr/pgsql-9.4/bin/postgresql94-setup initdb
When initializing a database, you can specify the parameter -- PGDATA = "/data", which is used to specify the path for storing data files in the database, the default path is/var/lib/pgsql/9.4/data.
If I execute service postgresql-9.4 initdb under CentOS 7, the following problem will be reported:
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
6. Start the service and set it to start upon startup
CentOS 6.x System
sudo service postgresql-9.4 start
sudo chkconfig postgresql-9.4 on
CentOS 7 System
sudo systemctl enable postgresql-9.4
sudo systemctl start postgresql-9.4
7. Open firewall ports
CentOS 6.x System
vi /etc/sysconfig/iptables
Press I to enter the input mode and add the following statement to the file.
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
Press ESC to exit the editing mode. Enter wq to exit the VI editing page.
Restart the Firewall Service
sudo service iptables restart
CentOS 7 System
sudo firewall-cmd --permanent --add-port=5432/tcp
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload
8. Access PostgreSQL
su - postgres
The output result is as follows:
Last Logon: October 11, May 18 15:17:29 CST 2015pts/0-bash-4.2 $
Enter the command psql to view the PostgrSQL version.
Psql (9.4.1) Input "help" to obtain help information.
9. Set the postgres User Password
postgres=# \password postgres
The above operations basically complete the installation of the entire PostgreSQL.