Projekt

Allgemein

Profil

Setup postgresql92 » Historie » Version 3

Jeremias Keihsler, 12.04.2019 15:26

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