Setup postgresql106 » Historie » Version 3
Jeremias Keihsler, 03.02.2020 21:37
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 | 2 | Jeremias Keihsler | h2. Install |
17 | 1 | Jeremias Keihsler | |
18 | h3. Install postgresql and postgresql-server packages on CentOS 8.x: |
||
19 | |||
20 | 2 | Jeremias Keihsler | <pre><code class="bash"> |
21 | yum install postgresql postgresql-server |
||
22 | </code></pre> |
||
23 | 1 | Jeremias Keihsler | <pre><code class="bash"> |
24 | yum install postgresql postgresql-server postgresql-libs postgresql-contrib postgresql-devel |
||
25 | </code></pre> |
||
26 | |||
27 | h2. Configure PostgreSQL 10.6 Database Server |
||
28 | |||
29 | Initialize the cluster first with initdb command: |
||
30 | <pre><code class="bash"> |
||
31 | 3 | Jeremias Keihsler | /usr/bin/postgresql-setup --initdb --unit postgresql |
32 | 1 | Jeremias Keihsler | </code></pre> |
33 | |||
34 | Edit /var/lib/pgsql/data/postgresql.conf file: |
||
35 | <pre><code class="bash"> |
||
36 | vim /var/lib/pgsql/data/postgresql.conf |
||
37 | </code></pre> |
||
38 | Set PostgreSQL server to listen all addresses and Change PostgreSQL port (default is 5432). Add/Uncomment/Edit following lines: |
||
39 | <pre><code class="bash"> |
||
40 | ... |
||
41 | listen_addresses = '*' |
||
42 | ... |
||
43 | port = 5432 |
||
44 | ... |
||
45 | </code></pre> |
||
46 | Edit /var/lib/pgsql/data/pg_hba.conf file: |
||
47 | <pre><code class="bash"> |
||
48 | vim /var/lib/pgsql/data/pg_hba.conf |
||
49 | </code></pre> |
||
50 | Add (example) your local network with md5 passwords: |
||
51 | |||
52 | <pre><code class="bash"> |
||
53 | ... |
||
54 | # Local networks |
||
55 | local all all trust |
||
56 | host all all xx.xx.xx.xx/xx md5 |
||
57 | # Example |
||
58 | host all all 10.20.4.0/24 md5 |
||
59 | host all mes 0.0.0.0/0 md5 |
||
60 | </code></pre> |
||
61 | |||
62 | manually start PostgreSQL Server: |
||
63 | <pre><code class="bash"> |
||
64 | systemctl start postgresql.service |
||
65 | </code></pre> |
||
66 | |||
67 | automatically start the service at boot time: |
||
68 | <pre><code class="bash"> |
||
69 | systemctl enable postgresql.service |
||
70 | </code></pre> |
||
71 | |||
72 | you can check the runlevels by |
||
73 | <pre><code class="bash"> |
||
74 | systemctl is-enabled postgresql.service |
||
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 | firewall-cmd --permanent --add-port=5432/tcp --zone=public |
||
101 | firewall-cmd --reload |
||
102 | </code></pre> |
||
103 | |||
104 | h2. Usage |
||
105 | |||
106 | Test remote connection: |
||
107 | <pre><code class="bash"> |
||
108 | psql -h dbserver -U testuser test |
||
109 | </code></pre> |
||
110 | |||
111 | h2. Post Installation Steps |
||
112 | |||
113 | *DON'T FORGET TO REMOVE* @testuser@ *BEFORE GOING TO PRODUCTION* |
||
114 | <pre><code class="bash"> |
||
115 | dropuser testuser |
||
116 | </code></pre> |
||
117 | |||
118 | *DON'T FORGET TO SETUP* @vacuum@ *BEFORE GOING TO PRODUCTION* |
||
119 | <pre><code class="bash"> |
||
120 | vacuumdb -a -U postgres -z -v |
||
121 | </code></pre> |
||
122 | |||
123 | maybe with a cron-job |
||
124 | |||
125 | OR |
||
126 | |||
127 | as @autovacuum@ is working by default, let's get some log-entries to see it actually working by changing @postgres.conf@ |
||
128 | <pre><code class="bash"> |
||
129 | log_autovacuum_min_duration = 10 |
||
130 | </code></pre> |
||
131 | |||
132 | you can check the settings of the database by |
||
133 | <pre><code class="bash"> |
||
134 | su - postgres |
||
135 | psql test |
||
136 | </code></pre> |
||
137 | <pre><code class="bash"> |
||
138 | psql# show all; |
||
139 | </code></pre> |