-1

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?

Carla
  • 326
  • 1
  • 7
  • 1
    Don't build from source use the PGDG [Ubuntu](https://www.postgresql.org/download/linux/ubuntu/) repo and the included [postgresql-common](https://github.com/credativ/postgresql-common) to manage the versions. – Adrian Klaver Apr 09 '23 at 20:51

6 Answers6

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.

jjanes
  • 37,812
  • 5
  • 27
  • 34
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

1

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.

0

You might also need to kill the process running on port 5432 and then re-initialize the db based on the specific version of postgres you want to use.

To get the PID of the process currently running on port 5432(default port for postgres), simply run

sudo fuser -k 5432/tcp

or run:

sudo lsof -i :5432

The kill the process using the kill command. Reset your PGDATA environment variable to the bin/data directory of the postgres version you plan on using and then re-run the initdb command.

Make sure the bin commands you are using is the one specific to the postgres version.

Peter
  • 43
  • 4
0

install source code of pg from git

https://github.com/postgres/postgres.git

you can select the version by changing the git branch

 git branch -a
git checkout (branch name)

now install Pg

    ./configure
make -j12
make install -j12

set the path

export PATH=/usr/local/pgsql/bin/:$PATH
export PGDATA=/usr/local/pgsql/bin/data
sudo chown (username) /usr/local/psql/ -R 
Initdb

if you want to change the version just checkout the branch of that desired version and rerun all the setups

0

Try the following steps:

Clean Your Environment before attempting any further changes ensure that there are no PostgreSQL processes from previous installations. You can stop any running PostgreSQL instances using pg_ctl or other appropriate commands.

Check Installation Paths, make sure that the installation path you provided during the configuration of PostgreSQL 13 is correctly set to /usr/local/pgsql-13.

Configure the path, verify that the /usr/local/pgsql-13/bin directory is included in your system's PATH variable. This will ensure that when you run PostgreSQL-related commands, they are picked up from the correct version's directory.

Data Directory, PostgreSQL maintains data directories where the actual databases reside. Make sure that the data directory for PostgreSQL 13 (/usr/local/pgsql-13/data) is distinct from the one for PostgreSQL 12.

Configure the port properly if you're encountering port related problems, you can modify the postgresql.conf file in PostgreSQL 13's data directory and change the port number to something other than the default 5432. This will allow you to run both PostgreSQL versions simultaneously with different ports.

Hope these steps will resolve your issue!