title: How to solve pg_dump: aborting because of server version mismatch using docker
body: <p>It worked after I followed the instructions at computingforgeeks.com/install-postgresql-on-debian-linux but I tried to run <code>python manage.py dbbackup</code> again today and it does not work.</p>
  <p>I don't understand why it says <code>No such file or directory: '/root/usr/bin/pg_dump'</code> when the path matches the path from <code>find . -name pg_dump</code></p>
  <p>shell to postgres container</p>
  <pre><code>root@6d515751e154:/# pg_dump --version
  pg_dump (PostgreSQL) 13.3 (Debian 13.3-1.pgdg100+1)
  root@6d515751e154:/# find . -name pg_dump
  ./usr/lib/postgresql/13/bin/pg_dump
  ./usr/bin/pg_dump
  </code></pre>
  <p>base.py</p>
  <pre><code>DATABASES = {
      &quot;default&quot;: {
          &quot;ENGINE&quot;: os.environ.get(&quot;SQL_ENGINE&quot;),
          &quot;NAME&quot;: os.environ.get(&quot;SQL_DATABASE&quot;),
          &quot;USER&quot;: os.environ.get(&quot;SQL_USER&quot;),
          &quot;PASSWORD&quot;: os.environ.get(&quot;SQL_PASSWORD&quot;),
          &quot;HOST&quot;: os.environ.get(&quot;SQL_HOST&quot;),
          &quot;PORT&quot;: os.environ.get(&quot;SQL_PORT&quot;),
      }
  }
  
  DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
  DBBACKUP_STORAGE_OPTIONS = {'location': os.path.join(BASE_DIR, '../backups')}
  DBBACKUP_CONNECTORS = {
      &quot;default&quot;: {
          &quot;ENGINE&quot;: 'django.db.backends.postgresql_psycopg2',
          &quot;NAME&quot;: os.environ.get(&quot;SQL_DATABASE&quot;),
          &quot;USER&quot;: os.environ.get(&quot;SQL_USER&quot;),
          &quot;PASSWORD&quot;: os.environ.get(&quot;SQL_PASSWORD&quot;),
          &quot;HOST&quot;: os.environ.get(&quot;SQL_HOST&quot;),
          &quot;PORT&quot;: os.environ.get(&quot;SQL_PORT&quot;),
          # &quot;DUMP_CMD&quot;: os.path.join( # Tried both of these
          #     os.environ['HOME'],
          #     &quot;usr&quot;,
          #     &quot;bin&quot;,
          #     &quot;pg_dump&quot;
          #     )
          &quot;DUMP_CMD&quot;: os.path.join( # Tried both of these
              os.environ['HOME'],
              &quot;usr&quot;,
              &quot;lib&quot;,
              &quot;postgresql&quot;,
              &quot;13&quot;,
              &quot;bin&quot;,
              &quot;pg_dump&quot;
              )
      }
  }
  </code></pre>
  <p>docker-compose.yml</p>
  <pre><code>version: '3.8'
  
  services:
      wagtail:
          build: .
          container_name: wagtail
          command: python /code/mysite/manage.py runserver 0.0.0.0:8000 --settings=mysite.settings.dev
          restart: unless-stopped
          volumes:
              - .:/code
          ports:
              - 8000:8000
          env_file:
              - .env/.dev
          depends_on:
              - pgdb
          networks:
              - wagtailnet
      
      pgdb:
          image: postgres:13
          container_name: pgdb
          restart: unless-stopped
          ports:
              - 5432:5432
          env_file:
              - .env/.dev_db
          volumes:
              - pgdata:/var/lib/postgresql/data/
          networks:
              - wagtailnet
  
  volumes:
      pgdata:
  
  networks:
      wagtailnet:
  </code></pre>
  <p>Traceback 1:</p>
  <pre><code>Backing Up Database: postgres
  CommandConnectorError: Error running:  /root/usr/bin/pg_dump  --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
  [Errno 2] No such file or directory: '/root/usr/bin/pg_dump'
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/utils.py&quot;, line 118, in wrapper
      func(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 61, in handle  
      self._save_new_backup(database)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 74, in _save_new_backup
      outputfile = self.connector.create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 78, in create_dump
      dump = self._create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 38, in _create_dump
      stdout, stderr = self.run_command(cmd, env=self.dump_env)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 21, in run_command
      return super(PgDumpConnector, self).run_command(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 156, in run_command
      raise exceptions.CommandConnectorError(
  
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 146, in run_command
      process = Popen(cmd, stdin=stdin, stdout=stdout, stderr=stderr, env=full_env)
    File &quot;/usr/local/lib/python3.8/subprocess.py&quot;, line 854, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,
    File &quot;/usr/local/lib/python3.8/subprocess.py&quot;, line 1702, in _execute_child
      raise child_exception_type(errno_num, err_msg, err_filename)
  FileNotFoundError: [Errno 2] No such file or directory: '/root/usr/bin/pg_dump'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;manage.py&quot;, line 10, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py&quot;, line 419, in execute_from_command_line
      utility.execute()
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py&quot;, line 413, in execute      
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/base.py&quot;, line 354, in run_from_argv    
      self.execute(*args, **cmd_options)
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/base.py&quot;, line 398, in execute
      output = self.handle(*args, **options)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/utils.py&quot;, line 118, in wrapper
      func(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 61, in handle  
      self._save_new_backup(database)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 74, in _save_new_backup
      outputfile = self.connector.create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 78, in create_dump
      dump = self._create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 38, in _create_dump
      stdout, stderr = self.run_command(cmd, env=self.dump_env)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 21, in run_command
      return super(PgDumpConnector, self).run_command(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 156, in run_command
      raise exceptions.CommandConnectorError(
  dbbackup.db.exceptions.CommandConnectorError: Error running:  /root/usr/bin/pg_dump  --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
  [Errno 2] No such file or directory: '/root/usr/bin/pg_dump'
  </code></pre>
  <p>Traceback 2:</p>
  <pre><code>Backing Up Database: postgres
  CommandConnectorError: Error running:  /root/usr/lib/postgresql/13/bin/pg_dump  --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
  [Errno 2] No such file or directory: '/root/usr/lib/postgresql/13/bin/pg_dump'
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/utils.py&quot;, line 118, in wrapper
      func(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 61, in handle  
      self._save_new_backup(database)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 74, in _save_new_backup
      outputfile = self.connector.create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 78, in create_dump
      dump = self._create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 38, in _create_dump
      stdout, stderr = self.run_command(cmd, env=self.dump_env)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 21, in run_command
      return super(PgDumpConnector, self).run_command(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 156, in run_command
      raise exceptions.CommandConnectorError(
  
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 146, in run_command
      process = Popen(cmd, stdin=stdin, stdout=stdout, stderr=stderr, env=full_env)
    File &quot;/usr/local/lib/python3.8/subprocess.py&quot;, line 854, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,
    File &quot;/usr/local/lib/python3.8/subprocess.py&quot;, line 1702, in _execute_child
      raise child_exception_type(errno_num, err_msg, err_filename)
  FileNotFoundError: [Errno 2] No such file or directory: '/root/usr/lib/postgresql/13/bin/pg_dump'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;manage.py&quot;, line 10, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py&quot;, line 419, in execute_from_command_line
      utility.execute()
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py&quot;, line 413, in execute      
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/base.py&quot;, line 354, in run_from_argv    
      self.execute(*args, **cmd_options)
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/base.py&quot;, line 398, in execute
      output = self.handle(*args, **options)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/utils.py&quot;, line 118, in wrapper
      func(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 61, in handle  
      self._save_new_backup(database)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 74, in _save_new_backup
      outputfile = self.connector.create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 78, in create_dump
      dump = self._create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 38, in _create_dump
      stdout, stderr = self.run_command(cmd, env=self.dump_env)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 21, in run_command
      return super(PgDumpConnector, self).run_command(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 156, in run_command
      raise exceptions.CommandConnectorError(
  dbbackup.db.exceptions.CommandConnectorError: Error running:  /root/usr/lib/postgresql/13/bin/pg_dump  --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
  [Errno 2] No such file or directory: '/root/usr/lib/postgresql/13/bin/pg_dump'
  </code></pre>
  <hr />
  <h2>Update above</h2>
  <p>I am running a django server(image python:3.8.2-slim-buster) and a postgresql(image postgres:13) database on separate docker containers. I am trying to use django-dbbackup to back up data and ran into this error.</p>
  <pre><code># python manage.py dbbackup
  System check identified some issues:
  
  WARNINGS:
  account.EmailAddress: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
          HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
  account.EmailConfirmation: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
          HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
  socialaccount.SocialAccount: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
          HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
  socialaccount.SocialApp: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
          HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
  socialaccount.SocialToken: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
          HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
  Backing Up Database: postgres
  CommandConnectorError: Error running:  pg_dump  --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
  pg_dump: server version: 13.3 (Debian 13.3-1.pgdg100+1); pg_dump version: 11.12 (Debian 11.12-0+deb10u1)
  pg_dump: aborting because of server version mismatch
  
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/utils.py&quot;, line 118, in wrapper
      func(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 61, in handle
      self._save_new_backup(database)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 74, in _save_new_backup
      outputfile = self.connector.create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 78, in create_dump
      dump = self._create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 38, in _create_dump
      stdout, stderr = self.run_command(cmd, env=self.dump_env)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 21, in run_command
      return super(PgDumpConnector, self).run_command(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 150, in run_command
      raise exceptions.CommandConnectorError(
  
  Traceback (most recent call last):
    File &quot;manage.py&quot;, line 10, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py&quot;, line 419, in execute_from_command_line
      utility.execute()
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py&quot;, line 413, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/base.py&quot;, line 354, in run_from_argv
      self.execute(*args, **cmd_options)
    File &quot;/usr/local/lib/python3.8/site-packages/django/core/management/base.py&quot;, line 398, in execute
      output = self.handle(*args, **options)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/utils.py&quot;, line 118, in wrapper
      func(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 61, in handle
      self._save_new_backup(database)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py&quot;, line 74, in _save_new_backup
      outputfile = self.connector.create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 78, in create_dump
      dump = self._create_dump()
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 38, in _create_dump
      stdout, stderr = self.run_command(cmd, env=self.dump_env)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py&quot;, line 21, in run_command
      return super(PgDumpConnector, self).run_command(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py&quot;, line 150, in run_command
      raise exceptions.CommandConnectorError(
  dbbackup.db.exceptions.CommandConnectorError: Error running:  pg_dump  --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
  pg_dump: server version: 13.3 (Debian 13.3-1.pgdg100+1); pg_dump version: 11.12 (Debian 11.12-0+deb10u1)
  pg_dump: aborting because of server version mismatch
  </code></pre>
  <p>After searching for answers, I tried to update postgresql-client but it says I already have the newest version.</p>
  <pre><code>root@528fdf5ac614:/code/mysite# apt-get install postgresql-client
  Reading package lists... Done
  Building dependency tree
  Reading state information... Done
  postgresql-client is already the newest version (11+200+deb10u4).
  0 upgraded, 0 newly installed, 0 to remove and 18 not upgraded.
  </code></pre>
  <p>So I don't know how to proceed. Should I downgrade the database container using postgres:11.12 docker image? That means data will be lost?</p>
  <p>Also, why does the error say dbbackup.db.exceptions.CommandConnectorError: Error running:  pg_dump  --host=pgdb --port=5432 --username=postgres --no-password --clean postgres ?
  I have set the password in base.py like so:</p>
  <p>base.py settings</p>
  <pre><code>DATABASES = {
      &quot;default&quot;: {
          &quot;ENGINE&quot;: os.environ.get(&quot;SQL_ENGINE&quot;),
          &quot;NAME&quot;: os.environ.get(&quot;SQL_DATABASE&quot;),
          &quot;USER&quot;: os.environ.get(&quot;SQL_USER&quot;),
          &quot;PASSWORD&quot;: os.environ.get(&quot;SQL_PASSWORD&quot;),
          &quot;HOST&quot;: os.environ.get(&quot;SQL_HOST&quot;),
          &quot;PORT&quot;: os.environ.get(&quot;SQL_PORT&quot;),
      }
  }
  
  DBBACKUP_CONNECTORS = {
      &quot;default&quot;: {
          &quot;USER&quot;: os.environ.get(&quot;SQL_USER&quot;),
          &quot;PASSWORD&quot;: os.environ.get(&quot;SQL_PASSWORD&quot;),
          &quot;HOST&quot;: os.environ.get(&quot;SQL_HOST&quot;),
      }
  }
  </code></pre>