DEV Community

Cover image for Building PostgreSQL 11 From Source Code
nabbisen
nabbisen

Posted on • Updated on

Building PostgreSQL 11 From Source Code

October 18, 2018

I found by chance 2018-10-18 is the date for PostgreSQL 11.0 to be released and also for OpenBSD 6.4 to be.
Both of them have helped me a lot for a long time and they are now the latest.
Thus I decided to let them be together just for fun and pleasure : )

✿ ✿ ✿

Building PostgreSQL 11.0 From Source Code In OpenBSD 6.4

Preparation

Install required packages:

$ doas pkg_add gmake
$ # case: `wget` instead of `ftp` to donwload:
$ doas pkg_add wget
$ # case: using tar.bz2 instead of tar.gz:
$ doas pkg_add bzip2
Enter fullscreen mode Exit fullscreen mode

* Note: doas means "Do it as (root, this time)."

Get Source Code

The source code of each version is stored in the official site.
The choice to take this time is v11.0.

Download from there:

$ ftp https://ftp.postgresql.org/pub/source/v11.0/postgresql-11.0.tar.gz
$ # or: wget https://ftp.postgresql.org/pub/source/v11.0/postgresql-11.0.tar.gz
Enter fullscreen mode Exit fullscreen mode

Decompress it:

$ tar zxvf postgresql-11.0.tar.gz
$ # or: tar jxvf postgresql-11.0.tar.bz2
Enter fullscreen mode Exit fullscreen mode

The files are created like this:

$ cd postgresql-11.0
$ ls
COPYRIGHT      HISTORY        Makefile       aclocal.m4     configure      contrib        src
GNUmakefile.in INSTALL        README         config         configure.in   doc
Enter fullscreen mode Exit fullscreen mode

Make To Build

Configure at first:

$ ./configure
Enter fullscreen mode Exit fullscreen mode

The output excerpt is like this:

checking build system type... x86_64-unknown-openbsd6.4
...
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for gcc... gcc
...
checking for g++... g++
...
checking how to run the C preprocessor... gcc -E
checking allow thread-safe client libraries... yes
checking whether to build with ICU support... no
checking whether to build with Tcl... no
checking whether to build Perl modules... no
checking whether to build Python modules... no
checking whether to build with GSSAPI support... no
checking whether to build with PAM support... no
checking whether to build with BSD Authentication support... no
checking whether to build with LDAP support... no
checking whether to build with Bonjour support... no
checking whether to build with OpenSSL support... no
checking whether to build with SELinux support... no
checking whether to build with systemd support... no
...
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking for a thread-safe mkdir -p... config/install-sh -c -d
checking for bison... no
configure: WARNING:
*** Without Bison you will not be able to build PostgreSQL from Git nor
*** change any of the parser definition files.  You can obtain Bison from
*** a GNU mirror site.  (If you are using the official distribution of
*** PostgreSQL then you do not need to worry about this, because the Bison
*** output is pre-generated.)
...
config.status: linking src/makefiles/Makefile.openbsd to src/Makefile.port
Enter fullscreen mode Exit fullscreen mode

And make -- actually gmake, "G"NU make:

$ gmake
Enter fullscreen mode Exit fullscreen mode

The output ends with:

gmake -C config all
gmake[1]: Entering directory '/home/openbsd-postgres/postgresql-11.0/config'
gmake[1]: Nothing to be done for 'all'.
gmake[1]: Leaving directory '/home/openbsd-postgres/postgresql-11.0/config'
All of PostgreSQL successfully made. Ready to install.
Enter fullscreen mode Exit fullscreen mode

And then install:

$ doas make install
$ # or: doas gmake install
Enter fullscreen mode Exit fullscreen mode

The output ends with:

gmake[1]: Entering directory '/home/openbsd-postgres/postgresql-11.0/config'
/bin/sh ../config/install-sh -c -d '/usr/local/pgsql/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/usr/local/pgsql/lib/pgxs/config/missing'
gmake[1]: Leaving directory '/home/openbsd-postgres/postgresql-11.0/config'
PostgreSQL installation complete.
Enter fullscreen mode Exit fullscreen mode

After all, the latest PostgreSQL is installed into the directory: /usr/local/pgsql : )

Initiation

Prepare a user and a directory:

$ doas mkdir /var/postgresql11

$ doas useradd postgres11 -m /var/postgresql11
$ doas passwd postgres11

$ doas chown postgres11:postgres11 /var/postgresql11

$ su - postgres11
Enter fullscreen mode Exit fullscreen mode

Add bin to $PATH:

$ PATH=/usr/local/pgsql/bin:$PATH
$ export PATH
Enter fullscreen mode Exit fullscreen mode

And run initdb like this:

$ # note: --locale value is up to your environment
$ initdb -D /var/postgresql11/data/ -U postgres11 --auth=md5 --pwprompt --encoding=UTF-8 --locale=ja_JP.UTF-8
The files belonging to this database system will be owned by user "postgres11".
This user must also own the server process.

The database cluster will be initialized with locale "ja_JP.UTF-8".
initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

Enter new superuser password: 
Enter it again: 

creating directory /var/postgresql11/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 30
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctl -D /var/postgresql11/data/ -l logfile start

Enter fullscreen mode Exit fullscreen mode

Usage

$ cd /var/postgresql11 

$ # start database server
$ pg_ctl -D /var/postgresql11/data/ -l logfile start
waiting for server to start.... done
server started

$ createdb postgres11
Password:
$ # access database
$ psql
Password for user postgres11: 
psql (11.0)
Type "help" for help.

postgres11=# select 'Hello, OpenBSD 6.4' as greetings;
     greetings      
--------------------
 Hello, OpenBSD 6.4
(1 row)

postgres11=# \q
Enter fullscreen mode Exit fullscreen mode
✿ ✿ ✿

November 2, 2018

PostgreSQL 11.0 met OpenBSD 6.4 today : )
(It's not their first time, perhaps :p )

Top comments (0)