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