Projekt

Allgemein

Profil

Setup postgresql106 » Historie » Version 1

Jeremias Keihsler, 03.02.2020 21:34

1 1 Jeremias Keihsler
h1. Install Procedure for PostgreSQL 10.6
2
3
h2. Requirements
4
5
To install postgresql you will need the following:
6
* a installed and supported operating system (e.g. CentOS 8.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
* https://www.linode.com/docs/databases/postgresql/how-to-install-postgresql-relational-databases-on-centos-7/
15
16
h2. Install 
17
18
h3. Install postgresql and postgresql-server packages on CentOS 8.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 10.6 Database Server
25
26
Initialize the cluster first with initdb command:
27
<pre><code class="bash">
28
/usr/bin/postgresql-setup initdb
29
</code></pre>
30
31
Edit /var/lib/pgsql/data/postgresql.conf file:
32
<pre><code class="bash">
33
vim /var/lib/pgsql/data/postgresql.conf
34
</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
Edit /var/lib/pgsql/data/pg_hba.conf file:
44
<pre><code class="bash">
45
vim /var/lib/pgsql/data/pg_hba.conf
46
</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
systemctl start postgresql.service
62
</code></pre>
63
64
automatically start the service at boot time:
65
<pre><code class="bash">
66
systemctl enable postgresql.service
67
</code></pre>
68
69
you can check the runlevels by
70
<pre><code class="bash">
71
systemctl is-enabled postgresql.service
72
</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
firewall-cmd --permanent --add-port=5432/tcp --zone=public
98
firewall-cmd --reload
99
</code></pre>
100
101
h2. Usage 
102
103
Test remote connection:
104
<pre><code class="bash">
105
psql -h dbserver -U testuser test
106
</code></pre>
107
108
h2. Post Installation Steps 
109
110
*DON'T FORGET TO REMOVE* @testuser@ *BEFORE GOING TO PRODUCTION*
111
<pre><code class="bash">
112
dropuser testuser
113
</code></pre>
114
115
*DON'T FORGET TO SETUP* @vacuum@ *BEFORE GOING TO PRODUCTION*
116
<pre><code class="bash">
117
vacuumdb -a -U postgres -z -v
118
</code></pre>
119
120
maybe with a cron-job
121
122
OR
123
124
as @autovacuum@ is working by default, let's get some log-entries to see it actually working by changing @postgres.conf@
125
<pre><code class="bash">
126
log_autovacuum_min_duration = 10
127
</code></pre>
128
129
you can check the settings of the database by
130
<pre><code class="bash">
131
su - postgres
132
psql test
133
</code></pre>
134
<pre><code class="bash">
135
psql# show all;
136
</code></pre>