File: 10-postgresql

package info (click to toggle)
openstack-trove 1%3A24.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,968 kB
  • sloc: python: 50,665; sh: 2,866; makefile: 71
file content (61 lines) | stat: -rwxr-xr-x 2,255 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh

set -e
set -o xtrace

cat > "/etc/sysctl.d/10-postgresql-performance.conf" << _EOF_
# See 'http://www.postgresql.org/docs/9.6/static/kernel-resources.html'
# for best practices.
# It is recommended to disable memory overcommit,
# but the Python interpreter may require it on smaller flavors.
# We therefore stick with the heuristic overcommit setting.
vm.overcommit_memory=0

_EOF_

cat > "/etc/rc.local" << _EOF_
#!/bin/bash

# See 'http://www.postgresql.org/docs/9.6/static/kernel-resources.html'
# Disable Linux kernel transparent huge pages. This feature is not supported by
# by Postgres 9.6 and may negatively impact performance of the database.
if test -f /sys/kernel/mm/redhat_transparent_hugepage/defrag; then
  echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag
fi
if test -f /sys/kernel/mm/redhat_transparent_hugepage/enabled; then
  echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
fi

exit \$?

_EOF_

dnf install -y https://yum.postgresql.org/9.6/fedora/fedora-27-x86_64/pgdg-fedora96-9.6-4.noarch.rpm

dnf install -y postgresql96-server postgresql96-contrib postgresql96-devel gcc

# Though /var/lib/pgsql is the preferred directory, need to move it as
# this is where the volume will be mounted
su - postgres -c "/usr/pgsql-9.6/bin/initdb /var/lib/pgsql/9.6/data"
mv /var/lib/pgsql /var/lib/postgresql

# The `postgresql96-setup` use postgresql-${MAJORVERSION} as the service name,  so rename 
# postgresql-9.6.service to postgresql.service is not a good idea. 
#mv /lib/systemd/system/postgresql-9.6.service /lib/systemd/system/postgresql.service

sed -i 's/PGDATA=\/var\/lib\/pgsql\/9.6\/data/PGDATA=\/var\/lib\/postgresql\/9.6\/data/' /lib/systemd/system/postgresql-9.6.service

# Set the right log location for PGUPLOG and PGLOG.
sed -i 's/\/var\/lib\/pgsql/\/var\/lib\/postgresql/' /usr/pgsql-9.6/bin/postgresql96-setup

# Add all postgresql related command(include pg_rewind) to the OS path.
export PATH=$PATH:/usr/pgsql-9.6/bin

# Install the native Python client.
dnf install -y postgresql-devel python-devel
pip install psycopg2

# Run initdb before `systemctl start`
/usr/pgsql-9.6/bin/postgresql96-setup initdb
systemctl enable postgresql-9.6.service
systemctl start postgresql-9.6.service