How to install PostgreSQL 9.6 In CentOS 7: centospostgresql
Preface
PostgreSQL is a powerful open-source object relational database system that runs on almost all major operating systems, including Linux, Unix (AIX, BSD, HP-UX, sgi irix, Mac OS, Solaris, Tru64), and Windows OS. PostgreSQL is recommended for new projects. Here we will simply sort out the installation process under CentOS.
The CentOS source comes with PostgreSQL. You can useyum list | grep postgresql
Check the version that comes with the system. here we can see version 9.2. We recommend that you install the updated version.
Install
1. Install yum source (address obtained from http://yum.postgresql.org/repopackages.php)
yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
The Latest Version 9.6 is selected.yum update
Update the source information before usingyum list | grep postgresql
Whether the latest postgresql version is available.
[root@localhost ~]# yum list|grep postgresqlcalligra-kexi-driver-postgresql.x86_64 2.9.10-1.el7 epel collectd-postgresql.x86_64 5.6.0-1.el7 epel freeradius-postgresql.x86_64 3.0.4-6.el7 base libreoffice-postgresql.x86_64 1:4.3.7.2-5.el7_2.1 updates mingw32-postgresql.noarch 9.3.4-2.el7 epel mingw64-postgresql.noarch 9.3.4-2.el7 epel opendbx-postgresql.x86_64 1.4.6-6.el7 epel opensips-postgresql.x86_64 1.10.5-3.el7 epel owncloud-postgresql.noarch 9.0.4-1.el7 epel pcp-pmda-postgresql.x86_64 3.10.6-2.el7 base pdns-backend-postgresql.x86_64 3.4.10-1.el7 epel perdition-postgresql.x86_64 2.1-5.el7 epel postgresql.i686 9.2.15-1.el7_2 updates postgresql.x86_64 9.2.15-1.el7_2 updates postgresql-contrib.x86_64 9.2.15-1.el7_2 updates postgresql-devel.i686 9.2.15-1.el7_2 updates postgresql-devel.x86_64 9.2.15-1.el7_2 updates postgresql-docs.x86_64 9.2.15-1.el7_2 updates postgresql-jdbc.noarch 9.4.1212-1.rhel7 pgdg96 postgresql-jdbc-javadoc.noarch 9.4.1212-1.rhel7 pgdg96 postgresql-libs.i686 9.2.15-1.el7_2 updates postgresql-libs.x86_64 9.2.15-1.el7_2 updates postgresql-odbc.x86_64 09.03.0100-2.el7 base postgresql-pgpool-II.x86_64 3.4.6-1.el7 epel postgresql-pgpool-II-devel.x86_64 3.4.6-1.el7 epel postgresql-pgpool-II-extensions.x86_64 3.4.6-1.el7 epel postgresql-plperl.x86_64 9.2.15-1.el7_2 updates postgresql-plpython.x86_64 9.2.15-1.el7_2 updates postgresql-plruby.x86_64 0.5.3-13.el7 epel postgresql-plruby-doc.x86_64 0.5.3-13.el7 epel postgresql-pltcl.x86_64 9.2.15-1.el7_2 updates postgresql-server.x86_64 9.2.15-1.el7_2 updates postgresql-test.x86_64 9.2.15-1.el7_2 updates postgresql-unit96.x86_64 1.0-1.rhel7 pgdg96 postgresql-unit96-debuginfo.x86_64 1.0-1.rhel7 pgdg96 postgresql-upgrade.x86_64 9.2.15-1.el7_2 updates postgresql96.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-contrib.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-debuginfo.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-devel.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-docs.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-libs.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-odbc.x86_64 09.05.0400-1PGDG.rhel7 pgdg96 postgresql96-plperl.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-plpython.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-pltcl.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-python.x86_64 4.2-1PGDG.rhel7 pgdg96 postgresql96-python-debuginfo.x86_64 4.2-1PGDG.rhel7 pgdg96 postgresql96-server.x86_64 9.6.1-1PGDG.rhel7 pgdg96 postgresql96-tcl.x86_64 2.1.1-1.rhel7 pgdg96 postgresql96-tcl-debuginfo.x86_64 2.1.1-1.rhel7 pgdg96 postgresql96-test.x86_64 9.6.1-1PGDG.rhel7 pgdg96 proftpd-postgresql.x86_64 1.3.5b-2.el7 epel python-testing.postgresql.noarch 1.1.0-2.el7 epel qt-postgresql.i686 1:4.8.5-12.el7_2 updates qt-postgresql.x86_64 1:4.8.5-12.el7_2 updates qt5-qtbase-postgresql.x86_64 5.6.1-3.el7 epel soci-postgresql.x86_64 3.2.3-1.el7 epel soci-postgresql-devel.x86_64 3.2.3-1.el7 epel
2. Install PostgreSQL
Here the core is to install postgresql96-server and postgresql96-contrib, where the "contrib" package contains some common components and methods.
yum install postgresql96-server postgresql96-contrib
After installation, the executable file in/usr/pgsql-9.5/bin/, data and configuration file in/var/lib/pgsql/9.6/data/
3. initialize the database
/usr/pgsql-9.6/bin/postgresql96-setup initdb
4. By default, PostgreSQL does not support Password Logon. You need to modify the configuration file if necessary.
vi /var/lib/pgsql/9.6/data/pg_hba.conf
Replace the ident in the uncommented row with md5
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections onlylocal all all peer# IPv4 local connections:host all all 127.0.0.1/32 ident# IPv6 local connections:host all all ::1/128 ident# Allow replication connections from localhost, by a user with the# replication privilege.#local replication postgres peer#host replication postgres 127.0.0.1/32 ident#host replication postgres ::1/128 ident
To enable remote access, edit the/var/lib/pgsql/9.6/data/postgresql. conf file.
Set#listen_addresses = 'localhost'
Changelisten_addresses='*'
(Of course, here '*' can also be changed to any server IP address you want to open)
In addition, you can enable trusted remote connections for specific IP addresses, modify/var/lib/pgsql/9.6/data/pg_assist.conf, and add settings in the following format.
# IPv4 local connections: host all 127.0.0.1/32 trust host all 8.8.8.8/32 (the IP address of the server to be connected) trust
Do not forget to restart the service after modifying the configuration.
5. Management services, like other services, are managed using systemd.
Systemctl start postgresql-9.6 # start Service systemctl restart postgresql-9.6 # restart service systemctl stop postgresql-9.6 # stop Service systemctl enable postgresql-9.6 # auto start
6. log on to PostgreSQL
After the PostgreSQL installation is complete, the 'ipvs' user will be created to execute PostgreSQL, and a 'ipvs' user will be created in the database. If you want to use PostgreSQL, you must first log on to this account.
sudo -i -u postgres
After the command is executed, the prompt will change to '-bash-4.2 $' and then run
Homogeneous execution enters psql to enter the postgresql command line environment.
[root@localhost ~]# sudo -i -u postgres-bash-4.2$ psqlpsql (9.6.1)Type "help" for help. postgres=#
Then you can executeALTER USER postgres WITH PASSWORD '123456'
To set the postgres user password. you can exit the database through \ q.
7. Open the Firewall
The PostgreSQL service is built in the CentOS firewall. The configuration file is located in/usr/lib/firewalld/services/postgresql. xml. You only need to open the PostgreSQL service as a service.
Firewall-cmd -- add-service = postgresql -- permanent Open the postgresql service firewall-cmd -- reload heavy load firewall
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.