Wednesday, January 22, 2014

Install PostgreSQL 9.3 & psycopg2 on CentOS 6.4

Install yum in the PostgreSQL 9.3 on CentOS 6.4, is a Python binding psycopg2 note of procedures for installing the pip.

Installation of PostgreSQL

I use the RPM that the developer of PostgreSQL provides

Configure your YUM repository

Modification of the YUM repository
I will be out of the jurisdiction from PostgreSQL YUM repository of default
/etc/yum.repos.d/CentOS-Base.repo Add the following to the section of the [updates] and [base]
exclude=postgresql*

Install PostgreSQL Global Development Group of (PGDG)

By installing the PGDG, RPM packages of the following are available for installation
  • postgresql-libs:. The postgresql-libs package provides the essential shared libraries for any PostgreSQL client program or interface You will need to install this package to use any other PostgreSQL package or any clients that need to connect to a PostgreSQL server.
  • postgresql:. ​​If you want to manipulate a PostgreSQL database on a local or remote PostgreSQL server, you need this package You also need to install this package if you're installing the postgresql-server package.
  • postgresql-contrib: The postgresql-contrib package contains contributed packages that are included in the PostgreSQL distribution.
  • postgresql-devel:. The postgresql-devel package contains the header files and libraries needed to compile C or C + + applications which will directly interact with a PostgreSQL database management server and the ecpg Embedded C Postgres preprocessor You need to install this package if you want to develop applications which will interact with a PostgreSQL server.
  • postgresql-docs:. The postgresql-docs package includes the SGML source for the documentation as well as the documentation in PDF format and some extra documentation Install this package if you want to help with the PostgreSQL documentation project, or if you want to generate printed documentation.
  • postgresql-server:. The postgresql-server package includes the programs needed to create and run a PostgreSQL server, which will in turn allow you to create and maintain PostgreSQL databases You should install postgresql-server if you want to create and maintain your own PostgreSQL databases and / or your own PostgreSQL server. You also need to install the postgresql package and its requirements.
  • postgresql-tcl: The postgresql-tcl package contains the Pgtcl client library and its documentation.
  • postgresql-jdbc:. The postgresql-jdbc package includes the jar files needed for Java programs to access a PostgreSQL database.
  • postgresql-pl:. The postgresql-pl package contains the the PL / Perl, and PL / Python procedural languages ​​for the backend PL / Pgsql is part of the core server package.
  • postgresql-python: The postgresql-python package includes a module for developers to use when writing Python code for accessing a PostgreSQL database.
  • postgresql-test: The postgresql-test package includes the sources and pre-built binaries of various tests for the PostgreSQL database management system, including regression tests and benchmarks.
PGDG are present in the version / distribution / architecture each of PostgreSQL, this is to download and install what they want from the following pages.
The following assumed that you are installing on x86_64 of the 6 CentOS PostgreSQL9.3.
$ curl -O http://yum.postgresql.org/9.3/redhat/rhel-6.4-x86_64/pgdg-centos93-9.3-1.noarch.rpm
$ sudo rpm -ivh pgdg-centos93-9.3-1.noarch.rpm
warning: pgdg-centos93-9.3-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing...                ########################################### [100%]
   1:pgdg-centos93          ########################################### [100%]

$ yum list postgres*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
base                                                                                                                       | 3.7 kB     00:00
extras                                                                                                                     | 3.4 kB     00:00
pgdg93                                                                                                                     | 2.8 kB     00:00
pgdg93/primary_db                                                                                                          |  61 kB     00:00
updates                                                                                                                    | 3.4 kB     00:00
Available Packages
postgresql93.x86_64                                                         9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-contrib.x86_64                                                 9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-debuginfo.x86_64                                               9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-devel.x86_64                                                   9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-docs.x86_64                                                    9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-libs.x86_64                                                    9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-plperl.x86_64                                                  9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-plpython.x86_64                                                9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-pltcl.x86_64                                                   9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-server.x86_64                                                  9.3.0-1PGDG.rhel6                                               pgdg93
postgresql93-test.x86_64                                                    9.3.0-1PGDG.rhel6                                               pgdg93
postgresql_autodoc.noarch                                                   1.41-1.rhel6                                                    pgdg93

$ sudo yum install postgresql93 postgresql93-contrib postgresql93-devel postgresql93-libs postgresql93-server
Program /usr/pgsql-9.3/bin/ is installed below. The PGDATA is /var/lib/pgsql/9.3/data is set to.

Launch configuration

To auto-start chkconfig Set
$ sudo /sbin/chkconfig --list postgresql-9.3
postgresql-9.3  0:off   1:off   2:off   3:off   4:off   5:off   6:off
$ sudo /sbin/chkconfig postgresql-9.3 on
$ sudo /sbin/chkconfig --list postgresql-9.3
postgresql-9.3  0:off   1:off   2:on    3:on    4:on    5:on    6:off

$ sudo service postgresql-9.3 initdb
Initializing database:                                     [  OK  ]
$ sudo service postgresql-9.3 start
Starting postgresql-9.3 service:                           [  OK  ]
(You can create a user After $ createuser --interactive -W ), pg_hba.conf You can play around with the file.

Installation of psycopg2

Is a Python bindings for PostgreSQL psycopg2 the pip install.
First installation of pip
$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | sudo python
$ sudo easy_install pip
psycopg2 is extensible module and C, I put the development package of Python
$ sudo yum install python-devel
The build of psycopg2 pg_config it is necessary to execute the command.
/usr/pgsql-9.3/bin because it is installed in the path of irregular, environment variable PATH to adjust.
sudo When used in a environment variable for security PATH for is not taken over , run to become root.
$ sudo su
# export PATH=/usr/pgsql-9.3/bin:$PATH
#  pip install psycopg2
...
Successfully installed psycopg2
Cleaning up...

About pg_config package

pg_config package postgresql93-devel is installed in. pg_config If you can not be found, an error message similar to the following is displayed.
Error: pg_config executable not found.

Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:

    python setup.py build_ext --pg-config /path/to/pg_config build ...

or with the pg_config option in 'setup.cfg'.

References

No comments:

Post a Comment