Skip to content

Instantly share code, notes, and snippets.

@sebastianwebber
Last active June 25, 2023 00:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastianwebber/a1cec0d82e4250b8f81ddd7344562850 to your computer and use it in GitHub Desktop.
Save sebastianwebber/a1cec0d82e4250b8f81ddd7344562850 to your computer and use it in GitHub Desktop.
9.3.5 build on centos 7

9.3 build on centos 7

Dependencies

yum install -y wget systemtap-sdt-devel gcc make bison flex perl-devel perl-ExtUtils-Embed readline-devel zlib-devel python-devel openssl-devel pam-devel libxml2-devel libxslt-devel openldap-devel tcl-devel

compiling

mkdir /opt/resources
cd /opt/resources
wget https://ftp.postgresql.org/pub/source/v9.3.5/postgresql-9.3.5.tar.bz2
tar xvjf postgresql-9.3.5.tar.bz2
cd postgresql-9.3.5

Configure, build, and install:

./configure CFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' \
LDFLAGS='-Wl,--as-needed' \
--enable-rpath \
--prefix=/usr/pgsql-9.3 \
--includedir=/usr/pgsql-9.3/include \
--mandir=/usr/pgsql-9.3/share/man \
--datadir=/usr/pgsql-9.3/share \
--with-perl \
--with-python \
--with-tcl \
--with-tclconfig=/usr/lib64 \
--with-openssl \
--with-pam \
--with-includes=/usr/include \
--with-libraries=/usr/lib64 \
--enable-nls \
--enable-dtrace \
--with-libxml \
--with-libxslt \
--with-ldap \
--with-selinux \
--with-system-tzdata=/usr/share/zoneinfo \
--sysconfdir=/etc/sysconfig/pgsql \
--docdir=/usr/pgsql-9.3/doc \
--htmldir=/usr/pgsql-9.3/doc/html
make -j 16 install
make -C contrib/ install

Fix the alternatives:

alternatives --install /usr/bin/psql pgsql-psql /usr/pgsql-9.3/bin/psql 930
alternatives --install /usr/bin/pg_dump pgsql-pg_dump /usr/pgsql-9.3/bin/pg_dump 930
alternatives --install /usr/bin/pg_restore pgsql-pg_restore /usr/pgsql-9.3/bin/pg_restore 930
alternatives --install /usr/bin/vacuumdb pgsql-vacuumdb /usr/pgsql-9.3/bin/vacuumdb 930
alternatives --install /usr/bin/pg_dumpall pgsql-pg_dumpall /usr/pgsql-9.3/bin/pg_dumpall 930
alternatives --install /usr/bin/pg_config pgsql-pg_config /usr/pgsql-9.3/bin/pg_config 930

SystemD config

save on /etc/systemd/system/postgresql-9.3.service:

# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  If you want to customize, the
# best way is to create a file "/etc/systemd/system/postgresql-9.3.service",
# containing
#       .include /lib/systemd/system/postgresql-9.3.service
#       ...make your changes here...
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.

# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL 9.3 database server
Documentation=https://www.postgresql.org/docs/9.3/static/
After=syslog.target
After=network.target

[Service]
Type=forking

User=postgres
Group=postgres

# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.

# Location of database directory
Environment=PGDATA=/var/lib/pgsql/9.3/data/

# 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

ExecStart=/usr/pgsql-9.3/bin/pg_ctl start -D ${PGDATA} -s -w -t 300
ExecStop=/usr/pgsql-9.3/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/pgsql-9.3/bin/pg_ctl reload -D ${PGDATA} -s

# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec=0

Initialize the cluster

Create a new user:

useradd postgres -c "PostgreSQL Server" --home-dir /var/lib/pgsql

Then initialize the cluster:

su - postgres
mkdir /var/lib/pgsql/9.3
/usr/pgsql-9.3/bin/initdb -D /var/lib/pgsql/9.3/data
# /etc/tuned/postgresql/tuned.conf
[main]
include= throughput-performance
[vm]
transparent_hugepages=never
[sysctl]
vm.overcommit_memory = 2
vm.swappiness = 1
kernel.sched_autogroup_enabled = 0
kernel.sched_migration_cost_ns = 50000000
vm.dirty_ratio = 90
vm.dirty_background_ratio = 10
vm.overcommit_ratio = 90
vm.zone_reclaim_mode = 0
@sebastianwebber
Copy link
Author

To fix the python devel conflict:

yum install yum-utils
package-cleanup --dupes
package-cleanup --cleandupes
 yum update
yum install python-devel

https://forums.cpanel.net/threads/update-error-python-devel-conflicts-with-python.655331/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment