Projekt

Allgemein

Profil

Setup postgresql92 » Historie » Version 5

Jeremias Keihsler, 12.04.2019 16:59

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 4 Jeremias Keihsler
systemctl start postgresql.service
62 1 Jeremias Keihsler
</code></pre>
63
64
automatically start the service at boot time:
65
<pre><code class="bash">
66 4 Jeremias Keihsler
systemctl enable postgresql.service
67 1 Jeremias Keihsler
</code></pre>
68
69
you can check the runlevels by
70
<pre><code class="bash">
71 4 Jeremias Keihsler
systemctl is-enabled postgresql.service
72 1 Jeremias Keihsler
</code></pre>
73
74
Change to postgres user:
75
<pre><code class="bash">
76
su - postgres
77
</code></pre>
78
79
Create test database (as postgres user):
80
<pre><code class="bash">
81
createdb test
82
</code></pre>
83
Login test database (as postgres user):
84
<pre><code class="bash">
85
psql test
86
</code></pre>
87
Create New “testuser” Role with Superuser and Password:
88
<pre><code class="bash">
89
CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD 'test';
90
</code></pre>
91
logout from @psql@ by @\q@
92
93
h2. configure firewall
94
95
Open PostgreSQL Port (5432) on Iptables Firewall (as root user again)
96
<pre><code class="bash">
97 5 Jeremias Keihsler
firewall-cmd --permanent --add-port=10050/tcp --zone=public
98
firewall-cmd --reload
99 1 Jeremias Keihsler
</code></pre>
100
101
102
h2. Usage 
103
104
Test remote connection:
105
<pre><code class="bash">
106
psql -h dbserver -U testuser test
107
</code></pre>
108
109
h2. Post Installation Steps 
110
111
*DON'T FORGET TO REMOVE* @testuser@ *BEFORE GOING TO PRODUCTION*
112
<pre><code class="bash">
113
dropuser testuser
114
</code></pre>
115
116
*DON'T FORGET TO SETUP* @vacuum@ *BEFORE GOING TO PRODUCTION*
117
<pre><code class="bash">
118
vacuumdb -a -U postgres -z -v
119
</code></pre>
120
121
maybe with a cron-job
122
123
OR
124
125
as @autovacuum@ is working by default, let's get some log-entries to see it actually working by changing @postgres.conf@
126
<pre><code class="bash">
127
log_autovacuum_min_duration = 10
128
</code></pre>
129
130
you can check the settings of the database by
131
<pre><code class="bash">
132
su - postgres
133
psql test
134
</code></pre>
135
<pre><code class="bash">
136
psql# show all;
137
</code></pre>