Showing posts with label PostgreSQL. Show all posts
Showing posts with label PostgreSQL. Show all posts

19 February 2018

PostgreSQL - Step by step guide installation from source

[Tested On]
CentOS Linux release 7.4.1708 (Core)

# wget https://ftp.postgresql.org/pub/source/v9.6.6/postgresql-9.6.6.tar.gz
# tar xvzf postgresql-9.6.6.tar.gz
# cd postgresql-9.6.6
# mkdir /opt/postgresql-9.6.6
# ./configure --prefix=/opt/postgresql-9.6.6
--- possible error output ---
configure: error: readline library not found
--- possible error output ---
# yum install readline-devel (install the missing library as reported above)
# make
# make install
# adduser postgres
# passwd postgres (set password)
# mkdir /opt/postgresql-9.6.6/data
# chown postgres:postgres /opt/postgresql-9.6.6/data
# su - postgres
$ /opt/postgresql-9.6.6/bin/initdb -D /opt/postgresql-9.6.6/data/
$ /opt/postgresql-9.6.6/bin/postmaster -D /opt/postgresql-9.6.6/data >/opt/postgresql-9.6.6/data/log 2>&1 &
$ ps -eaf | grep postgres (verify postgres is running)
$ vi ~/.bashrc
export PATH=$PATH:/opt/postgresql-9.6.6/bin
-- Save the file
-- Exit to root

--- Start and Stop postgresql using systemctl (systemd) ---
# cd /usr/lib/systemd/system
# vi postgres.service

--- Insert the following script  (change the postgresql location paths accordingly) ---
# START SCRIPT
[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking

User=postgres
Group=postgres

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
# ... but allow it still to be effective for child processes
# (note that these settings are ignored by Postgres releases before 9.5)
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

# Maximum number of seconds pg_ctl will wait for postgres to start.  Note that
# PGSTARTTIMEOUT should be less than TimeoutSec value.
Environment=PGSTARTTIMEOUT=270

Environment=PGDATA=/opt/postgresql-9.6.6/data


ExecStart=/opt/postgresql-9.6.6//bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
ExecStop=/opt/postgresql-9.6.6/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/opt/postgresql-9.6.6/bin/pg_ctl reload -D ${PGDATA} -s

# Give a reasonable amount of time for the server to start up/shut down.
# Ideally, the timeout for starting PostgreSQL server should be handled more
# nicely by pg_ctl in ExecStart, so keep its timeout smaller than this value.
TimeoutSec=300

[Install]
WantedBy=multi-user.target
# END SCRIPT

--- Save the file

# systemctl daemon-reload
# systemctl enable postgres
# systemctl start postgres

--- Verify postgres is running
# systemctl status postgres

POSTGRESQL - Comparison between PostgreSQL vs EDB Postgres Advanced Server

Your new IT project requires you to setup postgresql database and most of the time we get to the postgresql website and download the version (either the source or rpm files)  and proceed with installation accordingly.

Before you do that, please understand the specific requirement for the database or consult with the project manager before you make a decision to choose either postgresql or EDB Postgresql Advanced Server for your project. 

Please go through the comparison by clicking the link below. 
https://www.enterprisedb.com/products/compare-postgres-databases

6 June 2011

22 January 2011

PostgreSQL - Migrating from Oracle to Postgres Using ora2pg

# tar xzf ora2pg-7.x.tar.gz
# cd ora2pg-7.x/
# perl Makefile.PL
# make && make install

# perl -MCPAN -e 'install DBI'

# export ORACLE_HOME
# export LD_LIBRARY_PATH=$ORACLE_HOME/lib
# perl -MCPAN -e 'install DBD::Oracle'

Edit /etc/ora2pg/ora2pg.conf to modify ORACLE_HOST ORACLE_USER ORACLE_PASSWORD

20 January 2011

PostgreSQL To Identify and Terminate Hang Query

ps -ef | grep postgres to list out all processes belong to postgres user.

Notice process id with "idle in transaction", this is the hanging query in PostgreSQL.
Issue following command to terminate the PostgreSQL process manually.

kill -9 {pid}

PostgreSQL Cannot Start DB Service

Postgres cannot be started up, a file in pg_xlog was deleted, filename 000000010000000100000077

Err shown in $PGDATA/pg_log

2010-12-30 15:59:04 MYT LOG: database system was interrupted; last known up at 2010-12-30 12:19:37 MYT
2010-12-30 15:59:04 MYT LOG: could not open file "pg_xlog/000000010000000100000077" (log file 1, segment 119): No such file or directory
2010-12-30 15:59:04 MYT LOG: invalid primary checkpoint record
2010-12-30 15:59:04 MYT LOG: could not open file "pg_xlog/000000010000000100000077" (log file 1, segment 119): No such file or directory
2010-12-30 15:59:04 MYT LOG: invalid secondary checkpoint record
2010-12-30 15:59:04 MYT PANIC: could not locate a valid checkpoint record
2010-12-30 15:59:04 MYT LOG: startup process (PID 15605) was terminated by signal 6: Aborted
2010-12-30 15:59:04 MYT LOG: aborting startup due to startup process failure


Solution:
/opt/Postgresql/8.4/bin/pg_resetxlog -f $PGDATA

PostgreSQL unixODBC Configuration

Create the following files:

----pgsql-driver.tpl----------------------------------
[PostgreSQL]
Description = PostgreSQL driver for Linux & Win32
Driver = /usr/lib64/libodbcpsql.so
Setup = /usr/lib64/libodbcpsqlS.so


----pgsql-dsn.tpl----------------------------------
[saga80d01]
Description = CP resources db
Driver = PostgreSQL
Trace = No
TraceFile = sql.log
Database = saga80d01
Servername = localhost
UserName = postgres
Password = postgres
Port = 5432
Protocol = 6.4
ReadOnly = No
RowVersioning = No
ShowSystemTables = No
ShowOidColumn = No
FakeOidIndex = No
ConnSettings =
ExtraSysTablePrefixes =



1. Make sure unixODBC is installed
2. Install a driver
- odbcinst -i -d -f pgsql-driver.tpl
3. Install a system DSN
- odbcinst -i -s -f pgsql-dsn.tpl -l
4. Test Connection
- isql -v

PostgreSQL Client Only Installation

./configure --prefix=/opt/Postgresql-8....
gmake -C src/bin install
gmake -C src/include install
gmake -C src/interfaces install
gmake -C doc install

Wordpress - Local installation in Vmware

If you're interested in exploring website design with WordPress, this guide will help you set up a WordPress instance on your local mach...