lando / postgres

The Official Postgres Lando Plugin
https://docs.lando.dev/postgres
GNU General Public License v3.0
0 stars 1 forks source link

Appserver Postgres Client mismatch #2

Open dpacassi opened 2 years ago

dpacassi commented 2 years ago

When creating a Drupal project with Lando and the following yml file:

name: testproject
recipe: drupal9
config:
  webroot: web
  php: '7.4'
  composer_version: '1.10.22'
  xdebug: false
  database: postgres:13

The DB version is 13 while the client bin versions (psql and pg_dump on appserver) are still on version 10. If I define another Postgres version in the config, I'd expect that the recipe automatically uses the right version also for the client commands (psql, pg_dump).

I guess this is related to lando/lando#1680. I found a workaround also there. I added following lines to get the client bins with the right version:

    build_as_root:
      - "apt -y update && apt-get install -y gnupg2 && echo 'deb https://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' >> /etc/apt/sources.list.d/pgdg.list && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && apt -y update && apt-get install -y postgresql-client-13"
Daisuke-sama commented 2 years ago

hey! Same for me, while I am looking for the twelve version. Also I cannot override the credentials

labboy0276 commented 2 years ago

@dpacassi @Daisuke-sama can you please provide steps to replicate. Using the following lando file:

name: d9-postgres
recipe: drupal9
config:
  webroot: .
  php: '7.4'
  xdebug: false
  database: postgres:13

The commands show the right version:

john@tandem:~/lando/1-test-sites/d9-postgres$ lando psql --version
psql (PostgreSQL) 13.5
john@tandem:~/lando/1-test-sites/d9-postgres$ lando psql
psql (13.5)
Daisuke-sama commented 2 years ago

sure, my steps:

name: web
recipe: lemp
config:
  php: 7.4
  database: postgres:12
//or
services:
  database:
    type: postgres:12
    portforward: 54321

and I get pg_restore --version or sql --version is 10 unless I force the installation of 12 using the run section of the configuration. Because my dump file doesn't load to the database and writes incompatible version.

Daisuke-sama commented 2 years ago

image

labboy0276 commented 2 years ago

strange @Daisuke-sama on this lando file:

name: d9-postgres
recipe: drupal9
config:
  webroot: .
  php: '7.4'
  xdebug: false
  database: postgres:13

I get the following:

john@tandem:~/lando/1-test-sites/d9-postgres$ lando ssh -s database
www-data@5a3068247653:/app$ psql --version
psql (PostgreSQL) 13.5
www-data@5a3068247653:/app$ pg_restore --version
pg_restore (PostgreSQL) 13.5

And on yours:

name: lando-rando
recipe: lemp
config:
  php: 7.4
  database: postgres:12
john@tandem:~/lando/1-test-sites/rando-tests$ lando ssh -s database
www-data@bed14b152d0c:/app$ pg_restore --version
pg_restore (PostgreSQL) 12.9
www-data@bed14b152d0c:/app$ psql --version
psql (PostgreSQL) 12.9

What version of Lando are you on? Have you tried purging your system and starting over? https://docs.lando.dev/help/purging-containers.html

long-blade commented 1 year ago

Same problem

After purging my system and starting over.

image

xurizaemon commented 1 year ago

I think the issue description captures this, but our team ran into this and the cause wasn't obvious so I'll add a comment. Here's a minimal repro, showing that with a simple configuration it's possible to see mismatched client versions:

.lando.yml:

name: lando-test
recipe: drupal7
config:
  database: postgres:12

steps to reproduce:

$ lando ssh -s database -c 'pg_restore --version'
pg_restore (PostgreSQL) 12.9

$ lando ssh -s appserver -c 'pg_restore --version'
pg_restore (PostgreSQL) 10.23 (Debian 10.23-1.pgdg110+1)
$ lando ssh -c 'pg_restore --version'
pg_restore (PostgreSQL) 10.23 (Debian 10.23-1.pgdg110+1)

(the last two commands are the same, specifying then omitting the host)

In a Drupal recipe, drush sql:* will be wrapping the appserver versions of the commands, while Lando's sql-import command will use the database host's client tools and versions (unless the user specifies -h).

If the appserver needs matching versions (eg to use drush sql:* commands with PostgreSQL), then a workaround is to add a build step for your appserver to install a matching set of PostgreSQL client commands, as noted by @dpacassi in the issue description.


Working on both postgres and non-postgres projects, I'd probably rather Lando didn't add such a build step by default, unless it applied only to Lando configurations where postgres was used, as I wouldn't want to have to wait for extra steps on a rebuild if the project at hand won't use those tools at all.

NB: @Daisuke-sama https://github.com/lando/postgres/issues/2#issuecomment-1086101718 did not behave as expected because the test was done with lando ssh database (which drops the user into an appserver shell), not lando ssh -s database (database shell).