Installing PostgreSQL 9.4 on Centos 6.5
A note on how to install PostgreSQL 9.4 on Centos 6.5.
First, edit /etc/yum.repos.d/CentOS-Base.repo and add the following line to the [base] and [updates] sections:
exclude=postgresql*
Enable the extra repo:
yum localinstall http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm -y
Install PostgreSQL:
yum install postgresql94-server postgresql94-contrib postgresql-devel -y
Once installed, add it to startup and start it:
chkconfig postgresql-9.4 on
service postgresql-9.4 initdb
service postgresql-9.4 start
Now you need to create a user and a database in PostgreSQL.
Switch to the postgres user and connect to the console:
su - postgres
psql
Create the database and let the user work with it:
CREATE DATABASE **dbname**;
CREATE USER **dbuser** WITH PASSWORD '**myPassword**';
GRANT ALL PRIVILEGES ON DATABASE **dbname** to **dbuser**;
Press Ctrl+D to get back to the root user session.
To check that the user got created correctly, run:
psql -U**dbuser** -d**dbname** -hlocalhost -W
Odds are you’ll get this error:
psql: FATAL: Ident authentication failed for user `djangodbuser`
To fix it, open /var/lib/pgsql/9.4/data/pg_hba.conf for editing, find the following lines and replace ident with password:
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
After saving the file, restart PostgreSQL:
service postgresql-9.4 restart
Now you can try again:
psql -U**dbuser** -d**dbname** -hlocalhost -W
Should work now. If it doesn’t - leave a comment.
PostgreSQL driver for PHP
pecl install pdo_pgsql
The following error during install isn’t fatal:
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
configure: error: Cannot find libpq.so. Please specify correct PostgreSQL installation path
Fixes:
ln -s /usr/pgsql-9.4/include/libpq-fe.h /usr/local/include/libpq-fe.h
ln -s /usr/pgsql-9.4/lib/libpq.so /usr/local/lib/libpq.so
You may also hit this error:
/var/tmp/PDO_PGSQL/php_pdo_pgsql_int.h:27:28: error: libpq/libpq-fs.h: No such file or directory
/usr/local/include/libpq-fe.h:29:26: error: postgres_ext.h: No such file or directory
It’ll keep complaining it can’t find one header or another. Fix it with:
for f in $(ls /usr/pgsql-9.4/include/); do
ln -s /usr/pgsql-9.4/include/$f /usr/local/include/$f;
done
PostgreSQL driver for python:
pip install psycopg2
The following error during install isn’t fatal:
Error: pg_config executable not found.
Fix:
ln -s /usr/pgsql-9.4/bin/pg_config /usr/local/sbin/pg_config