-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgscratch.html
128 lines (109 loc) · 3.33 KB
/
pgscratch.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<html>
<head>
<meta
name="keywords"
content="PostgreSQL Build Compile Source Code"
/>
<meta
name="description"
content="Build PostgreSQL from Scratch"
/>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<link
rel="stylesheet"
href="pgscratch.css"
/>
</head>
<body>
<h1>PostgreSQL from Scratch on Linux/MacOS</h1>
<p>
The purpose of this document is to aid the reader in building
a postgres server from the source code available on postgresal.org.
The build environments can be either modern Linux or MacOSX.
</p>
<h2>Before You Start</h2>
<p>
Is building PostgreSQL from scratch better than installing with a distro
manager, like apt or dnf? The short answer is NO, particularly in
production environments. So why build from scratch?
Because building from scratch teaches how to secure and extend postgresql.
</p>
<p>
To build postgres you must be familiar with a shell command
line inside a program often call Terminal. The cut-n-paster
example in this document assume a bash shell. Consequently, if
you are not at least familiar with the a shell command line,
then PostgreSQL from Scratch might be difficult.
</p>
<h2>Open Terminal</h2>
<p>
If you do not know how to open Terminal
- in either Linux or MacOsX - then this document is not for you.
However, if you DO know how to open a Terminal then we will proceeed to
build PostgreSQL in the directory $HOME/opt/postgres/pgsql-16.3.
</p>
<h2>Setup Directories</h2>
<h2>Pull PG Source code from postgresql.org</h2>
<p>
We will build PostgreSQL under your personal linux/macosx account.
</p>
<h2>Setup Postgres User</h2>
<ol>
<li>Create <code>postgres</code> user account</li>
<li>
Create Directory <code>/usr/local/postgres</code>,
owned by user <code>postgres</code>
</li>
<li>
Become <code>postgres</code> user <code>su -l postgres</code>.
</li>
<li>
Make directory <code>~postgres/etc</code> and shell profile.
<pre class="terminal"g>
<code class="prompt">$</code>
<code>cat >>~/etc/profile-16.3</code><<EOF
<code style="font-style: italic">
export PGHOME=/usr/local/postgres/pgsql-16.4
export PGHOST=/tmp
export PGPORT=5432
export PGUSER=postgres
export PGPASSWORD=
export PGDATA=$PGHOME/data
PATH=$PGHOME/bin:$PATH
</code>
</pre>
</li>
</ol>
<h2>Pull Source code from <code>postgresql.org</code> and Unpack</h2>
<ol>
<li>
Make directory <code>~postgres/{dist,src,etc></code>
</li>
<li>
Pull source code for postgres-16.3 from postgresql.org.
<pre class="terminal"g>
<code class="prompt">$</code> <code>cd dist/</code>
<code class="prompt">$</code> <code>wget https://ftp.postgresql.org/pub/source/v16.3/postgresql-16.3.tar.bz2</code>
</pre>
</li>
<li>
Unpack source code.
<pre class="terminal"g>
<code class="prompt">$</code> <code>cd ~/src</code>
<code class="prompt">$</code> <code>tar xvf ~/dist/postgresql-16.3.tar.bz2</code>
</pre>
</li>
</ol>
<h2>Build/Install PostgreSQL from Source</h2>
<ol>
<li>Make simple build shell script
<pre class="terminal"g>
<code class="prompt">$</code> <code>cd ~/src/postgresql-16.3</code>
</pre>
</li>
</ol>
</body>
</html>