I am contributing to Apache AGE, an extension of PostgreSQL, and would like to maintain PostgreSQL 11, 12, and 13 installed to easily switch between them to test/debug the extension’s functionality.
I have PostgreSQL 12 installed from the source code, and as it is not in my interest to keep multiple databases running at the same time, I followed the steps below to install PostgreSQL 13:
- Accessed PostgreSQL 12 source code directory.
- I switched from the
origin/REL_12_STABLE
branch to theorigin/REL_13_STABLE
branch. - Then, I ran the following commands:
make distclean
./configure --prefix=/usr/local/pgsql-13
make -j4
However, I am not able to change the version. This is the output of the pg_config
command. Only the version is still 12.14, even though I am pointing to the correct directory:
BINDIR = /usr/local/pgsql-13/bin
DOCDIR = /usr/local/pgsql-13/share/doc
HTMLDIR = /usr/local/pgsql-13/share/doc
INCLUDEDIR = /usr/local/pgsql-13/include
PKGINCLUDEDIR = /usr/local/pgsql-13/include
INCLUDEDIR-SERVER = /usr/local/pgsql-13/include/server
LIBDIR = /usr/local/pgsql-13/lib
PKGLIBDIR = /usr/local/pgsql-13/lib
LOCALEDIR = /usr/local/pgsql-13/share/locale
MANDIR = /usr/local/pgsql-13/share/man
SHAREDIR = /usr/local/pgsql-13/share
SYSCONFDIR = /usr/local/pgsql-13/etc
PGXS = /usr/local/pgsql-13/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/usr/local/pgsql-13'
CC = gcc
CPPFLAGS = -D_GNU_SOURCE
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql-13/lib',--enable-new-dtags
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lz -lreadline -lcrypt -lm
VERSION = PostgreSQL 12.14
I tried:
- Manually changing the version in the
postgresql.conf
file of the database and the/usr/local/pgsql-13/bin/data
directory. - Installing
postgresql-server-dev-13
. - Updating the
FORCE_PGCONFIG
variable withexport FORCE_PGCONFIG=/usr/local/pgsql-13/bin/pg_config
. - Updating the
FORCE_PGCONFIG
variable with the file from the package manager installation:export FORCE_PGCONFIG=/usr/local/pgsql-13/bin/pg_config
.
But none of these options worked. The option 4 causes errors when initializing the database with pg_ctl
, even no other database is running. It also not suitable for debugging the code:
2023-04-09 13:16:54.163 -03 [7819] LOG: could not bind IPv4 address "127.0.0.1": Address already in use
2023-04-09 13:16:54.163 -03 [7819] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2023-04-09 13:16:54.163 -03 [7819] WARNING: could not create listen socket for "localhost"
2023-04-09 13:16:54.163 -03 [7819] FATAL: could not create any TCP/IP sockets
2023-04-09 13:16:54.164 -03 [7819] LOG: database system is shut down
Also, I saw that it is possible to change the port number and use two servers simultaneously, but since I will only be using one version at a time, I don’t see the point in doing that.
I’m using Ubuntu 22.04 LTS. Is there any way to keep all versions from the source code installation?
3
Answers
Simply you can build each postgresql version in a local/relative path i.e. in the same directory of the source code and use different port for each version
and same for age you will need to be specific with the PG_CONFIG path and LD_LIBRARY_PATH as well before its installation
That’s an example of installation of PG 13 after that getting age installed
Installation of AGE
Do the same operation with another versions and leave the port to be the default as we changed that version or use what you like.
References:
I have wrote a blog entry about that you can check that
make distclean
is not necessarily sufficient. It leaves behind bits of the old stuff which can then pollute the new build. You should domake maintainer-clean
when switching versions, or just blow away the old source directory entirely and thengit checkout -f
from scratch.You should keep each version of postgresql in separate relative paths. So when you have installed each version in a separate directory, they won’t overlap or confuse other versions.
Finally you can install age in all those directories and start it from inside a particular version’s directory. This will eliminate this issue and only that server and age instance will run which belongs to the postgres parent directory.
Also, make sure to set the paths in ./configure properly, make sure postgres versions are in separate directories. You can use
pwd
feature for that which uses the absolute path of the directories.