Projekt

Allgemein

Profil

Setup postgresql92 » Historie » Version 1

Jeremias Keihsler, 12.04.2019 15:14

1 1 Jeremias Keihsler
h1. Install Procedure for PostgreSQL 9.2
2
3
h2. Requirements
4
5
To install postgresql you will need the following:
6
* a installed and supported operating system (e.g. CentOS 7.x)
7
* root-access
8
* a fast internet connection
9
10
h2. Preliminary Note
11
12
This procedure is based on a documentation supplied by 
13
* https://www.if-not-true-then-false.com/2012/install-postgresql-on-fedora-centos-red-hat-rhel/
14
15
h2. Install 
16
17
h3. Install postgresql and postgresql-server packages on CentOS 6.x:
18
19
<pre><code class="bash">
20
yum install postgresql postgresql-server postgresql-libs postgresql-contrib postgresql-devel
21
</code></pre>
22
23
h2. Configure PostgreSQL 9.2 Database Server
24
25
Initialize the cluster first with initdb command:
26
<pre><code class="bash">
27
/etc/init.d/postgresql-9.2 initdb
28
</code></pre>
29
30
Edit /var/lib/pgsql/9.2/data/postgresql.conf file:
31
<pre><code class="bash">
32
vim /var/lib/pgsql/9.2/data/postgresql.conf
33
</code></pre>
34
Set PostgreSQL server to listen all addresses and Change PostgreSQL port (default is 5432). Add/Uncomment/Edit following lines:
35
<pre><code class="bash">
36
...
37
listen_addresses = '*'
38
...
39
port = 5432
40
...
41
</code></pre>
42
Edit /var/lib/pgsql/9.2/data/pg_hba.conf file:
43
<pre><code class="bash">
44
vim /var/lib/pgsql/9.2/data/pg_hba.conf
45
</code></pre>
46
Add (example) your local network with md5 passwords:
47
48
<pre><code class="bash">
49
...
50
# Local networks
51
local	all	all			trust
52
host	all	all	xx.xx.xx.xx/xx	md5
53
# Example
54
host	all	all	10.20.4.0/24	md5
55
host    all     mes     0.0.0.0/0       md5
56
</code></pre>
57
58
manually start PostgreSQL Server:
59
<pre><code class="bash">
60
/etc/init.d/postgresql-9.2 start
61
</code></pre>
62
63
automatically start the service at boot time:
64
<pre><code class="bash">
65
/sbin/chkconfig postgresql-9.2 on
66
</code></pre>
67
68
you can check the runlevels by
69
<pre><code class="bash">
70
/sbin/chkconfig --list postgresql-9.2
71
</code></pre>
72
you should get an output like:
73
<pre><code class="bash">
74
postgresql     0:off   1:off   2:on   3:on   4:on   5:on   6:off
75
</code></pre>
76
77
Change to postgres user:
78
<pre><code class="bash">
79
su - postgres
80
</code></pre>
81
82
Create test database (as postgres user):
83
<pre><code class="bash">
84
createdb test
85
</code></pre>
86
Login test database (as postgres user):
87
<pre><code class="bash">
88
psql test
89
</code></pre>
90
Create New “testuser” Role with Superuser and Password:
91
<pre><code class="bash">
92
CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD 'test';
93
</code></pre>
94
logout from @psql@ by @\q@
95
96
h2. configure firewall
97
98
Open PostgreSQL Port (5432) on Iptables Firewall (as root user again)
99
<pre><code class="bash">
100
system-config-firewall-tui
101
</code></pre>
102
add port @5432:tcp@
103
104
check if settings are ok
105
<pre><code class="bash">
106
cat /etc/sysconfig/iptables
107
</code></pre>
108
You should have following line before COMMIT:
109
<pre><code class="bash">
110
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
111
</code></pre>
112
Restart Iptables Firewall:
113
<pre><code class="bash">
114
/etc/init.d/iptables restart
115
</code></pre>
116
117
h2. Usage 
118
119
Test remote connection:
120
<pre><code class="bash">
121
psql -h dbserver -U testuser test
122
</code></pre>
123
124
h2. Post Installation Steps 
125
126
*DON'T FORGET TO REMOVE* @testuser@ *BEFORE GOING TO PRODUCTION*
127
<pre><code class="bash">
128
dropuser testuser
129
</code></pre>
130
131
*DON'T FORGET TO SETUP* @vacuum@ *BEFORE GOING TO PRODUCTION*
132
<pre><code class="bash">
133
vacuumdb -a -U postgres -z -v
134
</code></pre>
135
136
maybe with a cron-job
137
138
OR
139
140
as @autovacuum@ is working by default, let's get some log-entries to see it actually working by changing @postgres.conf@
141
<pre><code class="bash">
142
log_autovacuum_min_duration = 10
143
</code></pre>
144
145
you can check the settings of the database by
146
<pre><code class="bash">
147
su - postgres
148
psql test
149
</code></pre>
150
<pre><code class="bash">
151
psql# show all;
152
</code></pre>