skip to Main Content

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:

  1. Accessed PostgreSQL 12 source code directory.
  2. I switched from the origin/REL_12_STABLE branch to the origin/REL_13_STABLE branch.
  3. 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:

  1. Manually changing the version in the postgresql.conf file of the database and the /usr/local/pgsql-13/bin/data directory.
  2. Installing postgresql-server-dev-13.
  3. Updating the FORCE_PGCONFIG variable with export FORCE_PGCONFIG=/usr/local/pgsql-13/bin/pg_config.
  4. 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


  1. 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

    # make directory for holding the data
    mkdir pg13data
    # go to pg13 (postgres 13 source code directory)
    cd pg13
    # configure the source code build
    ./configure --prefix=/home/rrr/bitnine/pg13 --enable-debug --with-pgport=5431
    make
    sudo make install
    # ensure installation
    cd ..
    cd pg13
    # expected dirs should have: bin  include  lib  share
    ls
    # add new user or just skip it and use your preferred 
    adduser postgres
    # change ownership to the user
    chown postgres pg13data
    # switch to the user
    su - postgres
    # Update LD_LIBRARY_PATH (very important step)
    LD_LIBRARY_PATH=/home/rrr/bitnine/pg13/lib
    export LD_LIBRARY_PATH
    # init db cluster
    ./pg13/bin/initdb -D ./pg13data
    # start the server
    ./pg13/bin/postgres -D ./pg13data/ -p 5431 >logfile 2>&1 &
    # create database 'test' 
    ./pg13/bin/createdb test -p 5431
    # start postgresql session
    # output psql (13.0)
    ./pg13/bin/psql test
    # NOTE : rrr is my username
    

    Installation of AGE

    cd apache-age-1.3.0
    LD_LIBRARY_PATH=/home/rrr/bitnine/pg13/lib
    export LD_LIBRARY_PATH
    # install
    sudo make PG_CONFIG=/home/rrr/bitnine/pg13/bin/pg_config install
    # installcheck
    sudo make clean
    make PG_CONFIG=/home/rrr/bitnine/pg13/bin/pg_config installcheck
    ./pg13/bin/psql test
    CREATE EXTENSION age;
    LOAD 'age';
    SELECT * FROM ag_catalog.create_graph('test_graph');
    

    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

    Login or Signup to reply.
  2. make distclean is not necessarily sufficient. It leaves behind bits of the old stuff which can then pollute the new build. You should do make maintainer-clean when switching versions, or just blow away the old source directory entirely and then git checkout -f from scratch.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search