PostgreSQL-Three Ways to install

Source: Internet
Author: User
Tags bz2 postgresql postgresql commands psql xslt install perl postgres database postgresql client



Recently contacted the installation of PostgreSQL, and share with you.



First, Introduction



PostgreSQL is a very complex object-relational database management system (ORDBMS), and is currently the most powerful, feature richest and most complex free software database system. Some features don't even have a commercial database. The Berkeley-based database research program has now become an international development project and has a very wide range of users.



Advantages: http://www.cnblogs.com/zhangpengme/archive/2011/12/01/2271092.html



Official website: http://www.postgresql.org/(official website has various packages and instructions, very detailed)



Two or three types of installation process



A. RPM Package Installation



1. Check if PostgreSQL is installed



Rpm-qa|grep Postgres



If it is already installed, uninstall it using the RPM-E command.



2. Download RPM Package



#wget http://yum.postgresql.org/9.2/redhat/rhel-6-i386/postgresql92-contrib-9.2.4-1PGDG.rhel6.i686.rpm



#wget http://yum.postgresql.org/9.2/redhat/rhel-6-i386/postgresql92-libs-9.2.4-1PGDG.rhel6.i686.rpm



#wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm



3. Install PostgreSQL, pay attention to the installation sequence



# RPM-IVH postgresql92-libs-9.2.4-1pgdg.rhel6.i686.rpm
# RPM-IVH postgresql92-9.2.4-1pgdg.rhel6.i686.rpm
# RPM-IVH postgresql92-server-9.2.4-1pgdg.rhel6.i686.rpm
# RPM-IVH postgresql92-contrib-9.2.4-1pgdg.rhel6.i686.rpm



4. Initializing the PostgreSQL library



The PostgreSQL service will prompt for initialization when it first starts.





# service postgresql-9.2 Initdb





5. Start the service



# service postgresql-9.2 Start





6. Add the PostgreSQL service to the startup list



# chkconfig Postgresql-9.2on



# chkconfig--list|grep Postgres
7. Modify the password of the PostgreSQL database user Postgres (note that it is not a Linux system account)



The PostgreSQL database is created by default to create a Postgres database user as the administrator of the database, the default password is empty, we need to change to the specified password, which is set to ' Postgres '.
# Su-postgres
$ psql
# Alteruser Postgres with PASSWORD ' postgres ';
# Select*from Pg_shadow;








B. Yum Installation



1. Uninstall the PostgreSQL that you just installed



#/etc/init.d/postgresql-9.2 Stop//Stop PostgreSQL Service






To view installed packages



# Rpm-qa|grep Postgres



Unloading



# RPM-E postgresql92-server-9.2.4-1pgdg.rhel6.i686



# RPM-E postgresql92-contrib-9.2.4-1pgdg.rhel6.i686



# RPM-E postgresql92-9.2.4-1pgdg.rhel6.i686



# RPM-E postgresql92-libs-9.2.4-1pgdg.rhel6.i686



2. Yum Installation



If the default Yum installation is installed, the lower version of PostgreSQL 8.4 will be installed, which does not meet our requirements.





We use the PostgreSQL Yum Repository to install the latest version of PostgreSQL.



2.1 Installing PostgreSQL Yum Repository



# rpm-i http://yum.postgresql.org/9.2/RedHat/rhel-6-x86_64/pgdg-redhat92-9.2-7.noarch.rpm






2.2 Installing a new version of PostgreSQL



# yum Install Postgresql92-server Postgresql92-contrib



2.3 Viewing the installation





3. Initialize and start the database





Configuration file:/var/lib/pgsql/data/pg_hba.conf



4. Testing





Other steps such as a way.






C. Source Package Installation



1. Download PostgreSQL Source code



wget http://ftp.postgresql.org/pub/source/v9.0.3/postgresql-9.0.3.tar.bz2



wget https://ftp.postgresql.org/pub/source/v9.6.2/postgresql-9.6.2.tar.bz2



2. Unzip the file



Tar xjvf postgresql-9.0.3.tar.bz2



3. Enter the directory after decompression



CD postgresql-9.0.3/



4. Check the Install



The short version section of the install file explains how to install PostgreSQL commands, requirements section describes the Lib that is dependent on the installation of PostgreSQL, long, first configure try, if error occurs, Then you need to check whether the requirements requirements are met.



Short Version



./configure
Gmake
Su
Gmake Install
AddUser Postgres
Mkdir/usr/local/pgsql/data
Chown Postgres/usr/local/pgsql/data
Su-postgres
/usr/local/pgsql/bin/initdb-d/usr/local/pgsql/data
/usr/local/pgsql/bin/postgres-d/usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb Test
/usr/local/pgsql/bin/psql Test






5. Execute the command of short version in the install file and start compiling and installing the Postgrepsql database.



./configure--prefix=/usr/local/pgsql--with-perl--with-python--with-libxml--with-libxslt



Configure:error:readline Library not found



If you had readline already installed, see Config.log for details on the



Failure. It is possible the compiler isnt looking in the proper directory.



Yum Install-y readline-devel



(sudo apt-get install libreadline5-dev && sudo apt-get install zlib1g-dev)



Configure:error:library ' XSLT ' is required for XSLT support



Yum Install libxslt Libxslt-devel



Configure:error:header file <Python.h> is required for Python



Yum Install Python Python-devel



Configure:error:could not determine the flags for linking embedded Perl.



Yum Install perl-extutils-embed



After installing the ReadLine package, re-configure, successful.



6. Make



7. Make Install



8. Add User Postgres



Useradd Postgres



9. Create a database File storage folder



Mkdir/usr/local/pgsql/data



#mkdir/data/pgsql



10. Permissions to change the folder of the previously created data directory



Chown Postgres/usr/local/pgsql/data



#chown Postgres/data/pgsql



11. Switch Users



Su-postgres



12. Bind database File storage directory



/usr/local/pgsql/bin/initdb-d/usr/local/pgsql/data



#export path= $PATH:/usr/local/pgsql/bin/



#/usr/local/pgsql/bin/initdb-d/data/pgsql



13. Start the database



/usr/local/pgsql/bin/postgres-d/usr/local/pgsql/data >logfile 2>&1



[1] 18635



#/usr/local/pgsql/bin/postgres-d/data/pgsql >logfile 2>&1



[1] 18635



14. Create DATABASE Test



/usr/local/pgsql/bin/createdb Test



15. Connect to test Database



/usr/local/pgsql/bin/psql Test



Psql (9.0.3)



Type ' help ' for help.



test=#



16. CREATE TABLE table1



test=# CREATE TABLE table1 (



Test (# ID Integer



Test (#);



CREATE TABLE



test=#



17. Insert a record into the Table1 table



test=# INSERT INTO table1 values (1);



INSERT 0 1



18. Query the record you just inserted



test=# select * FROM table1;



Id



----



1








Third, client Installation



Because for us postgre application is very small, simply to learn his command line, for our time management is not too appropriate.



So we can go to download a client, do some simple operation, recommend Navicat website to download PostgreSQL client;



Https://www.navicat.com.cn/download









----------------------------------------------------------------------------------------






This article is from the "North Ice--q" blog, please be sure to keep this source http://beibing.blog.51cto.com/10693373/1912790



PostgreSQL-Three ways to install


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.